diff --git a/lib/extensions.js b/lib/extensions.js index b4c406d7a..9948538cc 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -7,8 +7,8 @@ var eol = require('os').EOL, pkg = require('../package.json'), mkdir = require('mkdirp'), path = require('path'), - defaultBinaryPath = path.join(__dirname, '..', 'vendor'), - trueCasePathSync = require('true-case-path'); + glob = require('glob'), + defaultBinaryPath = path.join(__dirname, '..', 'vendor'); /** * Get the human readable name of the Platform that is running @@ -284,6 +284,39 @@ function getBinaryPath() { } } +/** + * Returns a normalized file path. + * Taken from `true-case-path` npm package, with additional change to normalize drive letter + * @param {string} File path + */ +function trueCasePathSync(fsPath) { + + // Normalize the path so as to resolve . and .. components. + // !! As of Node v4.1.1, a path starting with ../ is NOT resolved relative + // !! to the current dir, and glob.sync() below then fails. + // !! When in doubt, resolve with fs.realPathSync() *beforehand*. + var fsPathNormalized = path.normalize(fsPath); + + // 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 = path.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. + return glob.sync(noDrivePath, { nocase: true, cwd: pathRoot.toLowerCase() })[0]; +} + /** * An array of paths suitable for use as a local disk cache of the binding. * diff --git a/package.json b/package.json index e42973a07..551e95e18 100644 --- a/package.json +++ b/package.json @@ -70,8 +70,7 @@ "npmlog": "^4.0.0", "request": "~2.79.0", "sass-graph": "^2.2.4", - "stdout-stream": "^1.4.0", - "true-case-path": "^1.0.2" + "stdout-stream": "^1.4.0" }, "devDependencies": { "coveralls": "^2.11.8",