Skip to content

Commit

Permalink
module: fix unintended mutation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aduh95 authored and RafaelGSS committed Jan 20, 2023
1 parent 1146f02 commit 54896ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
ArrayPrototypeJoin,
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypePushApply,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
Expand Down Expand Up @@ -667,12 +668,11 @@ Module._findPath = function(request, paths, isMain) {
return filename;
}

if (exts === undefined) {
exts = [''];
} else {
ArrayPrototypeUnshift(exts, '');
const extensions = [''];
if (exts !== undefined) {
ArrayPrototypePushApply(extensions, exts);
}
reportModuleNotFoundToWatchMode(basePath, exts);
reportModuleNotFoundToWatchMode(basePath, extensions);
}

return false;
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/require-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ assert.strictEqual(
require.resolve('./printA.js', {}),
require.resolve('./printA.js')
);

assert.strictEqual(
require.resolve('no_index/'),
path.join(__dirname, 'node_modules', 'no_index', 'lib', 'index.js'),
)

0 comments on commit 54896ab

Please sign in to comment.