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:
cjihrig 2019-06-05 15:35:13 -04:00
parent 0cd112a07e
commit 58fc168807
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
2 changed files with 9 additions and 1 deletions

View File

@ -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 {

View File

@ -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')
);