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 juanarbol committed Jan 31, 2023
1 parent 24a1016 commit baf30ee
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
Expand Up @@ -29,6 +29,7 @@ const {
ArrayPrototypeJoin,
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypePushApply,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
Expand Down Expand Up @@ -655,12 +656,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
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 baf30ee

Please sign in to comment.