1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add case sensitive checks for imports and JSON page resolver (#697)

* Add case-sensitive-paths-webpack-plugin plugin.

* Add case-sensitive check for server/resolve.
This commit is contained in:
Arunoda Susiripala 2017-01-08 18:12:29 -08:00 committed by Guillermo Rauch
parent 042ffa1175
commit 88e4adfc2a
4 changed files with 38 additions and 2 deletions

View file

@ -53,6 +53,7 @@
"babel-preset-es2015": "6.18.0",
"babel-preset-react": "6.16.0",
"babel-runtime": "6.20.0",
"case-sensitive-paths-webpack-plugin": "1.1.4",
"cross-spawn": "5.0.1",
"del": "2.2.2",
"friendly-errors-webpack-plugin": "1.1.2",

View file

@ -5,6 +5,7 @@ import webpack from 'webpack'
import glob from 'glob-promise'
import WriteFilePlugin from 'write-file-webpack-plugin'
import FriendlyErrorsWebpackPlugin from 'friendly-errors-webpack-plugin'
import CaseSensitivePathPlugin from 'case-sensitive-paths-webpack-plugin'
import UnlinkFilePlugin from './plugins/unlink-file-plugin'
import WatchPagesPlugin from './plugins/watch-pages-plugin'
import WatchRemoveEventPlugin from './plugins/watch-remove-event-plugin'
@ -71,7 +72,8 @@ export default async function createCompiler (dir, { dev = false, quiet = false
filename: 'commons.js',
minChunks: Math.max(2, minChunks)
}),
new JsonPagesPlugin()
new JsonPagesPlugin(),
new CaseSensitivePathPlugin()
]
if (dev) {

View file

@ -1,5 +1,6 @@
import { join, sep } from 'path'
import { join, sep, parse } from 'path'
import fs from 'mz/fs'
import glob from 'glob-promise'
export default async function resolve (id) {
const paths = getPaths(id)
@ -51,5 +52,33 @@ async function isFile (p) {
if (err.code === 'ENOENT') return false
throw err
}
// We need the path to be case sensitive
const realpath = await getTrueFilePath(p)
if (p !== realpath) return false
return stat.isFile() || stat.isFIFO()
}
// This is based on the stackoverflow answer: http://stackoverflow.com/a/33139702/457224
// We assume we'll get properly normalized path names as p
async function getTrueFilePath (p) {
let fsPathNormalized = p
// OSX: HFS+ stores filenames in NFD (decomposed normal form) Unicode format,
// so we must ensure that the input path is in that format first.
if (process.platform === 'darwin') fsPathNormalized = fsPathNormalized.normalize('NFD')
// !! Windows: Curiously, the drive component mustn't be part of a glob,
// !! otherwise glob.sync() will invariably match nothing.
// !! Thus, we remove the drive component and instead pass it in as the 'cwd'
// !! (working dir.) property below.
var pathRoot = parse(fsPathNormalized).root
var noDrivePath = fsPathNormalized.slice(Math.max(pathRoot.length - 1, 0))
// Perform case-insensitive globbing (on Windows, relative to the drive /
// network share) and return the 1st match, if any.
// Fortunately, glob() with nocase case-corrects the input even if it is
// a *literal* path.
const result = await glob(noDrivePath, { nocase: true, cwd: pathRoot })
return result[0]
}

View file

@ -1087,6 +1087,10 @@ cardinal@^1.0.0:
ansicolors "~0.2.1"
redeyed "~1.0.0"
case-sensitive-paths-webpack-plugin:
version "1.1.4"
resolved "https://registry.yarnpkg.com/case-sensitive-paths-webpack-plugin/-/case-sensitive-paths-webpack-plugin-1.1.4.tgz#8aaedd5699a86cac2b34cf40d9b4145758978472"
caseless@~0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.11.0.tgz#715b96ea9841593cc33067923f5ec60ebda4f7d7"