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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
  • 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.