MCPcopy Index your code
hub / github.com/nodejs/node / finalizeResolution

Function finalizeResolution

lib/internal/modules/esm/resolve.js:226–292  ·  view source on GitHub ↗

* Finalizes the resolution of a module specifier by checking if the resolved pathname contains encoded "/" or "\\" * characters, checking if the resolved pathname is a directory or file, and resolving any symlinks if necessary. * @param {URL} resolved - The resolved URL object. * @param {string |

(resolved, base, preserveSymlinks)

Source from the content-addressed store, hash-verified

224 * @throws {ERR_MODULE_NOT_FOUND} - If the resolved pathname is not a file.
225 */
226function finalizeResolution(resolved, base, preserveSymlinks) {
227 if (RegExpPrototypeExec(encodedSepRegEx, resolved.pathname) !== null) {
228 let basePath;
229 try {
230 basePath = fileURLToPath(base);
231 } catch {
232 basePath = base;
233 }
234 throw new ERR_INVALID_MODULE_SPECIFIER(
235 resolved.pathname, 'must not include encoded "/" or "\\" characters',
236 basePath);
237 }
238
239 let path;
240 try {
241 path = fileURLToPath(resolved);
242 } catch (err) {
243 setOwnProperty(err, 'input', `${resolved}`);
244 setOwnProperty(err, 'module', `${base}`);
245 throw err;
246 }
247
248 const stats = internalFsBinding.internalModuleStat(
249 StringPrototypeEndsWith(path, '/') ? StringPrototypeSlice(path, -1) : path,
250 );
251
252 // Check for stats.isDirectory()
253 if (stats === 1) {
254 let basePath;
255 try {
256 basePath = fileURLToPath(base);
257 } catch {
258 basePath = base;
259 }
260 throw new ERR_UNSUPPORTED_DIR_IMPORT(path, basePath, String(resolved));
261 } else if (stats !== 0) {
262 // Check for !stats.isFile()
263 if (process.env.WATCH_REPORT_DEPENDENCIES && process.send) {
264 process.send({ 'watch:require': [path || resolved.pathname] });
265 }
266 let basePath;
267 try {
268 basePath = fileURLToPath(base);
269 } catch {
270 basePath = base;
271 }
272 throw new ERR_MODULE_NOT_FOUND(
273 path || resolved.pathname, basePath, resolved);
274 }
275
276 if (!preserveSymlinks) {
277 // If you are reading this code to figure out how to patch Node.js module loading
278 // behavior - DO NOT depend on the patchability in new code: Node.js
279 // internals may stop going through the JavaScript fs module entirely.
280 // Prefer module.registerHooks() or other more formal fs hooks released in the future.
281 const real = fs.realpathSync(path, {
282 [internalFS.realpathCacheKey]: realpathCache,
283 });

Callers 1

moduleResolveFunction · 0.85

Calls 6

fileURLToPathFunction · 0.85
setOwnPropertyFunction · 0.85
StringClass · 0.85
sendMethod · 0.65
pathToFileURLFunction · 0.50
realpathSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…