module: handle empty require.resolve() options
If require.resolve() is passed an options object, but the paths option is not present, then use the default require.resolve() paths. PR-URL: https://github.com/nodejs/node/pull/28078 Fixes: https://github.com/nodejs/node/issues/28077 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
0cd112a07e
commit
58fc168807
@ -598,7 +598,9 @@ Module._resolveFilename = function(request, parent, isMain, options) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (options.paths !== undefined) {
|
||||
} else if (options.paths === undefined) {
|
||||
paths = Module._resolveLookupPaths(request, parent);
|
||||
} else {
|
||||
throw new ERR_INVALID_OPT_VALUE('options.paths', options.paths);
|
||||
}
|
||||
} else {
|
||||
|
6
test/fixtures/require-resolve.js
vendored
6
test/fixtures/require-resolve.js
vendored
@ -92,3 +92,9 @@ common.expectsError(() => {
|
||||
code: 'ERR_INVALID_OPT_VALUE',
|
||||
type: TypeError,
|
||||
});
|
||||
|
||||
// Verify that the default require.resolve() is used for empty options.
|
||||
assert.strictEqual(
|
||||
require.resolve('./printA.js', {}),
|
||||
require.resolve('./printA.js')
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user