Previously, require.resolve() called Module._resolveFilename() directly, bypassing any resolve hooks registered via module.registerHooks(). This patch fixes that. PR-URL: https://github.com/nodejs/node/pull/62028 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
13 lines
545 B
JavaScript
13 lines
545 B
JavaScript
// Fixture CJS file that calls require.resolve with the paths option.
|
|
'use strict';
|
|
const path = require('path');
|
|
const fixturesDir = path.resolve(__dirname, '..', '..');
|
|
const nodeModules = path.join(fixturesDir, 'node_modules');
|
|
|
|
// Use the paths option to resolve 'bar' from the fixtures node_modules.
|
|
const resolved = require.resolve('bar', { paths: [fixturesDir] });
|
|
const expected = path.join(nodeModules, 'bar.js');
|
|
if (resolved !== expected) {
|
|
throw new Error(`Expected ${expected}, got ${resolved}`);
|
|
}
|
|
module.exports = { resolved };
|