Skip to content

Commit baf30ee

Browse files
aduh95juanarbol
authored andcommitted
module: fix unintended mutation
Refs: #46061 (comment) PR-URL: #46108 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent 24a1016 commit baf30ee

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/internal/modules/cjs/loader.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
ArrayPrototypeJoin,
3030
ArrayPrototypeMap,
3131
ArrayPrototypePush,
32+
ArrayPrototypePushApply,
3233
ArrayPrototypeSlice,
3334
ArrayPrototypeSplice,
3435
ArrayPrototypeUnshift,
@@ -655,12 +656,11 @@ Module._findPath = function(request, paths, isMain) {
655656
return filename;
656657
}
657658

658-
if (exts === undefined) {
659-
exts = [''];
660-
} else {
661-
ArrayPrototypeUnshift(exts, '');
659+
const extensions = [''];
660+
if (exts !== undefined) {
661+
ArrayPrototypePushApply(extensions, exts);
662662
}
663-
reportModuleNotFoundToWatchMode(basePath, exts);
663+
reportModuleNotFoundToWatchMode(basePath, extensions);
664664
}
665665

666666
return false;

test/fixtures/require-resolve.js

+5
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,8 @@ assert.strictEqual(
9898
require.resolve('./printA.js', {}),
9999
require.resolve('./printA.js')
100100
);
101+
102+
assert.strictEqual(
103+
require.resolve('no_index/'),
104+
path.join(__dirname, 'node_modules', 'no_index', 'lib', 'index.js'),
105+
)

0 commit comments

Comments
 (0)