Skip to content

Commit

Permalink
module: apply code style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
papercuptech committed Dec 6, 2016
1 parent d0306de commit 51757d3
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,22 @@ if (process.platform === 'win32') {
// Use colon as an extra condition since we can get node_modules
// path for dirver root like 'C:\node_modules' and don't need to
// parse driver name.
if (code === 92/*\*/ || code === 47/*/*/ || code === 58/*:*/
|| (adjacentNodeModules && code === 46/*.*/)) {
if (code === 92/*\*/ || code === 47/*/*/ || code === 58/*:*/ ||
(adjacentNodeModules && code === 46/*.*/)) {
if (p !== nmLen) {
var parent = from.slice(0, last);
paths.push(parent + '\\node_modules');

if (adjacentNodeModules) {
paths.push(parent + '+node_modules');
if (code === 46/*.*/)
if (code === 46/*.*/) {
while (i > 1) {
const code = from.charCodeAt(--i);
if (code === 92/*\*/ || code === 47/*/*/ || code === 58/*:*/)
if (code === 92/*\*/ || code === 47/*/*/ || code === 58/*:*/) {
break;
}
}
}
}
}
last = i;
Expand Down Expand Up @@ -311,8 +313,13 @@ if (process.platform === 'win32') {

if (adjacentNodeModules) {
paths.push(parent + '+node_modules');
if (code === 46/*.*/)
while (i > 1 && from.charCodeAt(--i) !== 47/*/*/);
if (code === 46/*.*/) {
while (i > 1) {
if (from.charCodeAt(--i) === 47/*/*/) {
break;
}
}
}
}
}
last = i;
Expand Down Expand Up @@ -432,28 +439,36 @@ Module._resolveLookupPaths = function(request, parent) {
// its target is simply read and resolved, potentially relative to the
// symlink's dirname. in all other cases the original path is preserved.
Module._resolveMainRequest = function(request) {
if(!preserveSymlinks) return request
if(!preserveSymlinks) {
return request;
}

request = Module._resolveFilename(request, null)
if(!fs.lstatSync(request).isSymbolicLink()) return request
request = Module._resolveFilename(request, null);
if(!fs.lstatSync(request).isSymbolicLink()) {
return request;
}

let isExecutable = false
let isExecutable = false;
if(process.platform === 'win32') {
const execExts = (process.env.PATHEXT || '').split(path.delimiter)
const requestExt = path.extname(request).toLowerCase()
const execExts = (process.env.PATHEXT || '').split(path.delimiter);
const requestExt = path.extname(request).toLowerCase();
isExecutable =
execExts.some(execExt => requestExt === execExt.trim().toLowerCase())
} else try {
fs.accessSync(request, fs.constants.X_OK)
isExecutable = true
} catch(e) {}
execExts.some((execExt) => requestExt === execExt.trim().toLowerCase());
} else {
try {
fs.accessSync(request, fs.constants.X_OK);
isExecutable = true;
} catch(e) {}
}

if(!isExecutable) return request
if(!isExecutable) {
return request;
}

const targetPath = fs.readlinkSync(request)
const targetPath = fs.readlinkSync(request);
return path.isAbsolute(targetPath)
? targetPath
: path.resolve(path.dirname(request), targetPath)
: path.resolve(path.dirname(request), targetPath);
}

// Check the cache for the requested file.
Expand Down

0 comments on commit 51757d3

Please sign in to comment.