Skip to content

Commit 7e5382f

Browse files
committed
fix: findExisting should be case sensitive
closes vuejs#2305 We have added `case-sensitive-paths-webpack-plugin` to the base config. So the filename of instant prototyping entry should also be case-sensitive.
1 parent 09305db commit 7e5382f

File tree

1 file changed

+23
-1
lines changed
  • packages/@vue/cli-service-global/lib

1 file changed

+23
-1
lines changed

packages/@vue/cli-service-global/lib/util.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,31 @@ const path = require('path')
33

44
exports.toPlugin = id => ({ id, apply: require(id) })
55

6+
// Based on https://stackoverflow.com/questions/27367261/check-if-file-exists-case-sensitive
7+
// Case checking is required, to avoid errors raised by case-sensitive-paths-webpack-plugin
8+
function fileExistsWithCaseSync (filepath) {
9+
const dir = path.dirname(filepath)
10+
11+
if (dir === '/' || dir === '.') {
12+
return true
13+
}
14+
15+
try {
16+
const filenames = fs.readdirSync(dir)
17+
if (!filenames.includes(path.basename(filepath))) {
18+
return false
19+
}
20+
} catch (e) {
21+
// dir does not exist
22+
return false
23+
}
24+
25+
return fileExistsWithCaseSync(dir)
26+
}
27+
628
exports.findExisting = (context, files) => {
729
for (const file of files) {
8-
if (fs.existsSync(path.join(context, file))) {
30+
if (fileExistsWithCaseSync(path.join(context, file))) {
931
return file
1032
}
1133
}

0 commit comments

Comments
 (0)