Skip to content

Commit 3247719

Browse files
authored
fix: fix scoped modules exclusion on windows (#2379)
closes #2251
1 parent 33dad39 commit 3247719

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ beforeAll(async () => {
2626
`const test = () => "__TEST__";\nexport default test`
2727
)
2828

29+
await project.write(
30+
'node_modules/@scope/external-dep/package.json',
31+
`{ "name": "@scope/external-dep", "version": "1.0.0", "main": "index.js" }`
32+
)
33+
34+
await project.write(
35+
'node_modules/@scope/external-dep/index.js',
36+
`const test = () => "__SCOPE_TEST__";\nexport default test`
37+
)
38+
2939
let $packageJson = await project.read('package.json')
3040

3141
$packageJson = JSON.parse($packageJson)
@@ -39,7 +49,12 @@ beforeAll(async () => {
3949

4050
let $mainjs = await project.read('src/main.js')
4151

42-
$mainjs = `import test from 'external-dep'\n${$mainjs}\ntest()`
52+
$mainjs = `
53+
import test from 'external-dep'
54+
import scopeTest from '@scope/external-dep'
55+
${$mainjs}
56+
test()
57+
scopeTest()`
4358

4459
await project.write(
4560
'src/main.js',
@@ -59,4 +74,6 @@ test('dep from node_modules should been transpiled', async () => {
5974
)
6075
await project.run('vue-cli-service build')
6176
expect(await readVendorFile()).toMatch('return "__TEST__"')
77+
78+
expect(await readVendorFile()).toMatch('return "__SCOPE_TEST__"')
6279
})

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const path = require('path')
2+
13
module.exports = (api, options) => {
24
const useThreads = process.env.NODE_ENV === 'production' && options.parallel
35
const cliServicePath = require('path').dirname(require.resolve('@vue/cli-service'))
@@ -17,7 +19,13 @@ module.exports = (api, options) => {
1719
return true
1820
}
1921
// check if this is something the user explicitly wants to transpile
20-
if (options.transpileDependencies.some(dep => filepath.match(dep))) {
22+
if (options.transpileDependencies.some(dep => {
23+
if (typeof dep === 'string') {
24+
return filepath.includes(path.normalize(dep))
25+
} else {
26+
return filepath.match(dep)
27+
}
28+
})) {
2129
return false
2230
}
2331
// Don't transpile node_modules

0 commit comments

Comments
 (0)