Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Normalize drive letter #2179

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down