Skip to content

Commit 7ce2ee6

Browse files
committed
fix: get tsconfig when compiling typescript
1 parent 02ad74b commit 7ce2ee6

File tree

9 files changed

+91
-28
lines changed

9 files changed

+91
-28
lines changed

lib/compilers/babel-compiler.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ var defaultBabelOptions = {
77
plugins: ['transform-runtime']
88
}
99

10-
module.exports = function compileBabel (scriptContent) {
10+
module.exports = function compileBabel (scriptContent, inputSourceMap) {
1111
const { file, config } = findBabelConfig.sync(process.cwd(), 0)
1212

1313
if (!file) {
1414
logger.info('no .babelrc found, defaulting to default babel options')
1515
}
1616

17+
const sourceMapOptions = {
18+
sourceMaps: true,
19+
inputSourceMap: inputSourceMap || null
20+
}
21+
1722
const baseBabelOptions = file ? config : defaultBabelOptions
18-
const babelOptions = Object.assign({ sourceMaps: true }, baseBabelOptions)
23+
const babelOptions = Object.assign(sourceMapOptions, baseBabelOptions)
1924

2025
const res = babel.transform(scriptContent, babelOptions)
2126

lib/compilers/typescript-compiler.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
const ensureRequire = require('../ensure-require')
2+
const compileBabel = require('./babel-compiler')
3+
const tsconfig = require('tsconfig')
24

35
module.exports = function compileTypescript (scriptContent) {
46
ensureRequire('typescript', ['typescript'])
57
const typescript = require('typescript')
8+
const file = tsconfig.loadSync(process.cwd())
69

7-
const res = typescript.transpileModule(scriptContent, { 'compilerOptions': {
8-
'sourceMap': true
9-
}})
10+
const res = typescript.transpileModule(scriptContent, file.config)
1011

11-
return {
12-
code: res.outputText,
13-
sourceMap: res.sourceMapText
14-
}
12+
return compileBabel(res.outputText, res.sourceMapText)
1513
}

package-lock.json

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"release": "build/release.sh",
2121
"release:note": "node build/gen-release-note.js",
2222
"test": "npm run lint && ./test.sh",
23-
"unit": "cross-env BABEL_ENV=test jest test --runInBand --coverage --coverageDirectory test/coverage"
23+
"unit": "jest test --no-cache --runInBand --coverage --coverageDirectory test/coverage"
2424
},
2525
"author": "Edd Yerburgh",
2626
"license": "MIT",
@@ -31,7 +31,6 @@
3131
"clear-module": "^2.1.0",
3232
"coffee-script": "^1.12.7",
3333
"conventional-changelog": "^1.1.5",
34-
"cross-env": "^5.0.2",
3534
"eslint": "^4.3.0",
3635
"eslint-plugin-html": "^3.1.1",
3736
"eslint-plugin-vue": "^2.1.0",
@@ -58,6 +57,7 @@
5857
"js-beautify": "^1.6.14",
5958
"object-assign": "^4.1.1",
6059
"source-map": "^0.5.6",
60+
"tsconfig": "^7.0.0",
6161
"vue-template-es2015-compiler": "^1.5.3"
6262
},
6363
"jest": {

test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ cp -R node_modules temp-dir/node_modules
66
cp jest-vue.js temp-dir/jest-vue.js
77
cp package.json temp-dir/package.json
88
cp .babelrc temp-dir/.babelrc
9+
cp tsconfig.json temp-dir/tsconfig.json
910
cd temp-dir
1011
yarn unit

test/TypeScript.spec.js

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/resources/TypeScript.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<template>
2-
<div></div>
2+
<div><basic /></div>
33
</template>
44

55
<script lang="ts">
6+
import Basic from './Basic'
7+
68
export default {
79
computed: {
810
exclamationMarks(): string {
911
return 'string'
1012
}
13+
},
14+
components: {
15+
Basic
1116
}
1217
};
1318
</script>

tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2015",
4+
"moduleResolution": "node",
5+
"allowSyntheticDefaultImports": true,
6+
"strict": true,
7+
"noEmit": true
8+
},
9+
"include": [
10+
"**/*.ts"
11+
]
12+
}

yarn.lock

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
# yarn lockfile v1
33

44

5+
"@types/strip-bom@^3.0.0":
6+
version "3.0.0"
7+
resolved "https://registry.yarnpkg.com/@types/strip-bom/-/strip-bom-3.0.0.tgz#14a8ec3956c2e81edb7520790aecf21c290aebd2"
8+
9+
"@types/strip-json-comments@0.0.30":
10+
version "0.0.30"
11+
resolved "https://registry.yarnpkg.com/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz#9aa30c04db212a9a0649d6ae6fd50accc40748a1"
12+
513
JSONStream@^1.0.4:
614
version "1.3.1"
715
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.1.tgz#707f761e01dae9e16f1bcf93703b78c70966579a"
@@ -1164,13 +1172,6 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
11641172
version "1.0.2"
11651173
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
11661174

1167-
cross-env@^5.0.2:
1168-
version "5.0.5"
1169-
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.0.5.tgz#4383d364d9660873dd185b398af3bfef5efffef3"
1170-
dependencies:
1171-
cross-spawn "^5.1.0"
1172-
is-windows "^1.0.0"
1173-
11741175
cross-spawn@^5.1.0:
11751176
version "5.1.0"
11761177
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
@@ -2141,10 +2142,6 @@ is-utf8@^0.2.0:
21412142
version "0.2.1"
21422143
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"
21432144

2144-
is-windows@^1.0.0:
2145-
version "1.0.1"
2146-
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.1.tgz#310db70f742d259a16a369202b51af84233310d9"
2147-
21482145
isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0:
21492146
version "1.0.0"
21502147
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
@@ -3537,7 +3534,7 @@ strip-ansi@^4.0.0:
35373534
dependencies:
35383535
ansi-regex "^3.0.0"
35393536

3540-
strip-bom@3.0.0:
3537+
strip-bom@3.0.0, strip-bom@^3.0.0:
35413538
version "3.0.0"
35423539
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
35433540

@@ -3553,7 +3550,7 @@ strip-indent@^1.0.1:
35533550
dependencies:
35543551
get-stdin "^4.0.1"
35553552

3556-
strip-json-comments@~2.0.1:
3553+
strip-json-comments@^2.0.0, strip-json-comments@~2.0.1:
35573554
version "2.0.1"
35583555
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
35593556

@@ -3673,6 +3670,15 @@ tryit@^1.0.1:
36733670
version "1.0.3"
36743671
resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb"
36753672

3673+
tsconfig@^7.0.0:
3674+
version "7.0.0"
3675+
resolved "https://registry.yarnpkg.com/tsconfig/-/tsconfig-7.0.0.tgz#84538875a4dc216e5c4a5432b3a4dec3d54e91b7"
3676+
dependencies:
3677+
"@types/strip-bom" "^3.0.0"
3678+
"@types/strip-json-comments" "0.0.30"
3679+
strip-bom "^3.0.0"
3680+
strip-json-comments "^2.0.0"
3681+
36763682
tunnel-agent@^0.6.0:
36773683
version "0.6.0"
36783684
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"

0 commit comments

Comments
 (0)