Skip to content

Commit 133a930

Browse files
committed
fix: use fork-ts-checker-webpack-plugin v5 for vue 3 type checking
Fixes vuejs#5712 Note this is a optional dependency so that we don't break compatibility with Node.js v8.
1 parent f1e77a5 commit 133a930

File tree

3 files changed

+90
-36
lines changed

3 files changed

+90
-36
lines changed

packages/@vue/cli-plugin-typescript/index.js

+35-22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ module.exports = (api, projectOptions) => {
44
const fs = require('fs')
55
const useThreads = process.env.NODE_ENV === 'production' && !!projectOptions.parallel
66

7+
const { semver, loadModule } = require('@vue/cli-shared-utils')
8+
const vue = loadModule('vue', api.service.context)
9+
const isVue3 = (vue && semver.major(vue.version) === 3)
10+
711
api.chainWebpack(config => {
812
config.resolveLoader.modules.prepend(path.join(__dirname, 'node_modules'))
913

@@ -76,30 +80,39 @@ module.exports = (api, projectOptions) => {
7680
return options
7781
})
7882

83+
// this plugin does not play well with jest + cypress setup (tsPluginE2e.spec.js) somehow
84+
// so temporarily disabled for vue-cli tests
7985
if (!process.env.VUE_CLI_TEST) {
80-
// try to load `@vue/compiler-sfc` if the project is using Vue 3.
81-
// if it is not available, it uses `vue-template-compiler`
82-
let compiler = '@vue/compiler-sfc'
83-
try {
84-
require.resolve(compiler)
85-
// use a shim as @vue/compiler-sfc does not offer the `parseComponent` function
86-
// but a `parse` function
87-
// the shim only delegates to the parse function
88-
compiler = '@vue/cli-plugin-typescript/vue-compiler-sfc-shim'
89-
} catch (e) {
90-
compiler = 'vue-template-compiler'
91-
}
92-
// this plugin does not play well with jest + cypress setup (tsPluginE2e.spec.js) somehow
93-
// so temporarily disabled for vue-cli tests
94-
config
95-
.plugin('fork-ts-checker')
96-
.use(require('fork-ts-checker-webpack-plugin'), [{
97-
vue: { enabled: true, compiler },
98-
tslint: projectOptions.lintOnSave !== false && fs.existsSync(api.resolve('tslint.json')),
99-
formatter: 'codeframe',
100-
// https://github.com/TypeStrong/ts-loader#happypackmode-boolean-defaultfalse
101-
checkSyntacticErrors: useThreads
86+
if (isVue3) {
87+
config
88+
.plugin('fork-ts-checker')
89+
.use(require('fork-ts-checker-webpack-plugin-v5'), [{
90+
typescript: {
91+
extensions: {
92+
vue: {
93+
enabled: true,
94+
// use a shim as @vue/compiler-sfc does not offer the `parseComponent` function
95+
compiler: '@vue/cli-plugin-typescript/vue-compiler-sfc-shim'
96+
}
97+
},
98+
diagnosticOptions: {
99+
semantic: true,
100+
// https://github.com/TypeStrong/ts-loader#happypackmode
101+
syntactic: useThreads
102+
}
103+
}
102104
}])
105+
} else {
106+
config
107+
.plugin('fork-ts-checker')
108+
.use(require('fork-ts-checker-webpack-plugin'), [{
109+
vue: { enabled: true, compiler: 'vue-template-compiler' },
110+
tslint: projectOptions.lintOnSave !== false && fs.existsSync(api.resolve('tslint.json')),
111+
formatter: 'codeframe',
112+
// https://github.com/TypeStrong/ts-loader#happypackmode-boolean-defaultfalse
113+
checkSyntacticErrors: useThreads
114+
}])
115+
}
103116
}
104117
})
105118

packages/@vue/cli-plugin-typescript/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"webpack": "^4.0.0",
3535
"yorkie": "^2.0.0"
3636
},
37+
"optionalDependencies": {
38+
"fork-ts-checker-webpack-plugin-v5": "npm:fork-ts-checker-webpack-plugin@^5.0.11"
39+
},
3740
"peerDependencies": {
3841
"@vue/cli-service": "^3.0.0 || ^4.0.0-0",
3942
"@vue/compiler-sfc": "^3.0.0-beta.14",

yarn.lock

+52-14
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
dependencies:
106106
xss "^1.0.6"
107107

108-
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4":
108+
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.8.3":
109109
version "7.10.4"
110110
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a"
111111
integrity sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==
@@ -2691,7 +2691,7 @@
26912691
ast-types "0.12.1"
26922692
recast "0.17.2"
26932693

2694-
"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.4":
2694+
"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5":
26952695
version "7.0.5"
26962696
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.5.tgz#dcce4430e64b443ba8945f0290fb564ad5bac6dd"
26972697
integrity sha512-7+2BITlgjgDhH0vvwZU/HZJVyk+2XUlvxXe8dFMedNX/aMkaOq++rMAFXc0tM7ij15QaWlbdQASBR9dihi+bDQ==
@@ -2781,6 +2781,11 @@
27812781
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
27822782
integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==
27832783

2784+
"@types/parse-json@^4.0.0":
2785+
version "4.0.0"
2786+
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
2787+
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==
2788+
27842789
"@types/puppeteer@^1.11.0":
27852790
version "1.20.4"
27862791
resolved "https://registry.yarnpkg.com/@types/puppeteer/-/puppeteer-1.20.4.tgz#30cb0a4ee5394c420119cbdf9f079d6595a07f67"
@@ -6421,6 +6426,17 @@ cosmiconfig@^5.0.0, cosmiconfig@^5.0.6, cosmiconfig@^5.1.0, cosmiconfig@^5.2.1:
64216426
js-yaml "^3.13.1"
64226427
parse-json "^4.0.0"
64236428

6429+
cosmiconfig@^6.0.0:
6430+
version "6.0.0"
6431+
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-6.0.0.tgz#da4fee853c52f6b1e6935f41c1a2fc50bd4a9982"
6432+
integrity sha512-xb3ZL6+L8b9JLLCx3ZdoZy4+2ECphCMo2PwqgP1tlfVq6M6YReyzBJtvWWtbDSpNr9hn96pkCiZqUcFEc+54Qg==
6433+
dependencies:
6434+
"@types/parse-json" "^4.0.0"
6435+
import-fresh "^3.1.0"
6436+
parse-json "^5.0.0"
6437+
path-type "^4.0.0"
6438+
yaml "^1.7.2"
6439+
64246440
create-ecdh@^4.0.0:
64256441
version "4.0.3"
64266442
resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.3.tgz#c9111b6f33045c4697f144787f9254cdc77c45ff"
@@ -8907,6 +8923,23 @@ forever-agent@~0.6.1:
89078923
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
89088924
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=
89098925

8926+
"fork-ts-checker-webpack-plugin-v5@npm:fork-ts-checker-webpack-plugin@^5.0.11":
8927+
version "5.0.11"
8928+
resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-5.0.11.tgz#40a49a45403910c118c6ae7f3415dbdb317e4574"
8929+
integrity sha512-7QFCTfjayFhoX7uxncnHHi3ICWwffUQMoYaHldElA6wYy/9aDTsRIi6QcS8MDAkZa7xdDyv0YKuqcGYjAzboyQ==
8930+
dependencies:
8931+
"@babel/code-frame" "^7.8.3"
8932+
"@types/json-schema" "^7.0.5"
8933+
chalk "^4.1.0"
8934+
cosmiconfig "^6.0.0"
8935+
deepmerge "^4.2.2"
8936+
fs-extra "^9.0.0"
8937+
memfs "^3.1.2"
8938+
minimatch "^3.0.4"
8939+
schema-utils "2.7.0"
8940+
semver "^7.3.2"
8941+
tapable "^1.0.0"
8942+
89108943
fork-ts-checker-webpack-plugin@^3.1.1:
89118944
version "3.1.1"
89128945
resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-3.1.1.tgz#a1642c0d3e65f50c2cc1742e9c0a80f441f86b19"
@@ -9020,7 +9053,7 @@ fs-extra@^8.1.0:
90209053
jsonfile "^4.0.0"
90219054
universalify "^0.1.0"
90229055

9023-
fs-extra@^9.0.1:
9056+
fs-extra@^9.0.0, fs-extra@^9.0.1:
90249057
version "9.0.1"
90259058
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc"
90269059
integrity sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==
@@ -10321,7 +10354,7 @@ import-fresh@^2.0.0:
1032110354
caller-path "^2.0.0"
1032210355
resolve-from "^3.0.0"
1032310356

10324-
import-fresh@^3.0.0:
10357+
import-fresh@^3.0.0, import-fresh@^3.1.0:
1032510358
version "3.2.1"
1032610359
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.2.1.tgz#633ff618506e793af5ac91bf48b72677e15cbe66"
1032710360
integrity sha512-6e1q1cnWP2RXD9/keSkxHScg508CdXqXWgWBaETNhyuBFz+kUZlKboh+ISK+bU++DmbHimVBrOz/zzPe0sZ3sQ==
@@ -12766,7 +12799,7 @@ mem@^4.0.0:
1276612799
mimic-fn "^2.0.0"
1276712800
p-is-promise "^2.0.0"
1276812801

12769-
memfs@^3.2.0:
12802+
memfs@^3.1.2, memfs@^3.2.0:
1277012803
version "3.2.0"
1277112804
resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.2.0.tgz#f9438e622b5acd1daa8a4ae160c496fdd1325b26"
1277212805
integrity sha512-f/xxz2TpdKv6uDn6GtHee8ivFyxwxmPuXatBb1FBwxYNuVpbM3k/Y1Z+vC0mH/dIXXrukYfe3qe5J32Dfjg93A==
@@ -16301,6 +16334,15 @@ saxes@^3.1.9:
1630116334
dependencies:
1630216335
xmlchars "^2.1.1"
1630316336

16337+
[email protected], schema-utils@^2.0.0, schema-utils@^2.5.0, schema-utils@^2.6.1, schema-utils@^2.6.5, schema-utils@^2.6.6, schema-utils@^2.7.0:
16338+
version "2.7.0"
16339+
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.0.tgz#17151f76d8eae67fbbf77960c33c676ad9f4efc7"
16340+
integrity sha512-0ilKFI6QQF5nxDZLFn2dMjvc4hjg/Wkg7rHd3jK6/A4a1Hl9VFdQWvgB1UMGoU94pad1P/8N7fMcEnLnSiju8A==
16341+
dependencies:
16342+
"@types/json-schema" "^7.0.4"
16343+
ajv "^6.12.2"
16344+
ajv-keywords "^3.4.1"
16345+
1630416346
schema-utils@^1.0.0:
1630516347
version "1.0.0"
1630616348
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-1.0.0.tgz#0b79a93204d7b600d4b2850d1f66c2a34951c770"
@@ -16310,15 +16352,6 @@ schema-utils@^1.0.0:
1631016352
ajv-errors "^1.0.0"
1631116353
ajv-keywords "^3.1.0"
1631216354

16313-
schema-utils@^2.0.0, schema-utils@^2.5.0, schema-utils@^2.6.1, schema-utils@^2.6.5, schema-utils@^2.6.6, schema-utils@^2.7.0:
16314-
version "2.7.0"
16315-
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.0.tgz#17151f76d8eae67fbbf77960c33c676ad9f4efc7"
16316-
integrity sha512-0ilKFI6QQF5nxDZLFn2dMjvc4hjg/Wkg7rHd3jK6/A4a1Hl9VFdQWvgB1UMGoU94pad1P/8N7fMcEnLnSiju8A==
16317-
dependencies:
16318-
"@types/json-schema" "^7.0.4"
16319-
ajv "^6.12.2"
16320-
ajv-keywords "^3.4.1"
16321-
1632216355
scrollparent@^2.0.1:
1632316356
version "2.0.1"
1632416357
resolved "https://registry.yarnpkg.com/scrollparent/-/scrollparent-2.0.1.tgz#715d5b9cc57760fb22bdccc3befb5bfe06b1a317"
@@ -19660,6 +19693,11 @@ [email protected]:
1966019693
resolved "https://registry.yarnpkg.com/yaml-js/-/yaml-js-0.0.8.tgz#87cfa5a9613f48e26005420d6a8ee0da6fe8daec"
1966119694
integrity sha1-h8+lqWE/SOJgBUINao7g2m/o2uw=
1966219695

19696+
yaml@^1.7.2:
19697+
version "1.10.0"
19698+
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"
19699+
integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==
19700+
1966319701
1966419702
version "10.1.0"
1966519703
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-10.1.0.tgz#7202265b89f7e9e9f2e5765e0fe735a905edbaa8"

0 commit comments

Comments
 (0)