Skip to content

Commit

Permalink
fix: findExisting should be case sensitive
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haoqunjiang committed Sep 15, 2018
1 parent 09305db commit 7e5382f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/@vue/cli-service-global/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,31 @@ const path = require('path')

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

// Based on https://stackoverflow.com/questions/27367261/check-if-file-exists-case-sensitive
// Case checking is required, to avoid errors raised by case-sensitive-paths-webpack-plugin
function fileExistsWithCaseSync (filepath) {
const dir = path.dirname(filepath)

if (dir === '/' || dir === '.') {
return true
}

try {
const filenames = fs.readdirSync(dir)
if (!filenames.includes(path.basename(filepath))) {
return false
}
} catch (e) {
// dir does not exist
return false
}

return fileExistsWithCaseSync(dir)
}

exports.findExisting = (context, files) => {
for (const file of files) {
if (fs.existsSync(path.join(context, file))) {
if (fileExistsWithCaseSync(path.join(context, file))) {
return file
}
}
Expand Down

0 comments on commit 7e5382f

Please sign in to comment.