Skip to content

Commit 3b7fca6

Browse files
committed
module: simplify _resolveMain
remove check of execute bit for file-symlink as it's always set. if file-symlink, just follow its target
1 parent 51757d3 commit 3b7fca6

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

lib/module.js

+5-23
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ if (process.platform === 'win32') {
255255
// path for dirver root like 'C:\node_modules' and don't need to
256256
// parse driver name.
257257
if (code === 92/*\*/ || code === 47/*/*/ || code === 58/*:*/ ||
258-
(adjacentNodeModules && code === 46/*.*/)) {
258+
(adjacentNodeModules && code === 43/*+*/)) {
259259
if (p !== nmLen) {
260260
var parent = from.slice(0, last);
261261
paths.push(parent + '\\node_modules');
262262

263263
if (adjacentNodeModules) {
264264
paths.push(parent + '+node_modules');
265-
if (code === 46/*.*/) {
265+
if (code === 43/*+*/) {
266266
while (i > 1) {
267267
const code = from.charCodeAt(--i);
268268
if (code === 92/*\*/ || code === 47/*/*/ || code === 58/*:*/) {
@@ -306,14 +306,14 @@ if (process.platform === 'win32') {
306306
var last = from.length;
307307
for (var i = from.length - 1; i >= 0; --i) {
308308
const code = from.charCodeAt(i);
309-
if (code === 47/*/*/ || (adjacentNodeModules && code === 46/*.*/)) {
309+
if (code === 47/*/*/ || (adjacentNodeModules && code === 43/*+*/)) {
310310
if (p !== nmLen) {
311311
var parent = from.slice(0, last);
312312
paths.push(parent + '/node_modules');
313313

314314
if (adjacentNodeModules) {
315315
paths.push(parent + '+node_modules');
316-
if (code === 46/*.*/) {
316+
if (code === 43/*+*/) {
317317
while (i > 1) {
318318
if (from.charCodeAt(--i) === 47/*/*/) {
319319
break;
@@ -434,8 +434,7 @@ Module._resolveLookupPaths = function(request, parent) {
434434
return [id, [path.dirname(parent.filename)]];
435435
};
436436

437-
// when preserving symlinks, if the main file is both a file symlink AND
438-
// has execute permission (on windows, its extension is in PATHEXT), then
437+
// when preserving symlinks, if the main file is a file symlink then
439438
// its target is simply read and resolved, potentially relative to the
440439
// symlink's dirname. in all other cases the original path is preserved.
441440
Module._resolveMainRequest = function(request) {
@@ -448,23 +447,6 @@ Module._resolveMainRequest = function(request) {
448447
return request;
449448
}
450449

451-
let isExecutable = false;
452-
if(process.platform === 'win32') {
453-
const execExts = (process.env.PATHEXT || '').split(path.delimiter);
454-
const requestExt = path.extname(request).toLowerCase();
455-
isExecutable =
456-
execExts.some((execExt) => requestExt === execExt.trim().toLowerCase());
457-
} else {
458-
try {
459-
fs.accessSync(request, fs.constants.X_OK);
460-
isExecutable = true;
461-
} catch(e) {}
462-
}
463-
464-
if(!isExecutable) {
465-
return request;
466-
}
467-
468450
const targetPath = fs.readlinkSync(request);
469451
return path.isAbsolute(targetPath)
470452
? targetPath

0 commit comments

Comments
 (0)