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

Function urlToFilename

lib/internal/modules/helpers.js:360–380  ·  view source on GitHub ↗

* Coerce a URL string to a filename. This is used by the ESM loader * to map ESM URLs to entries in the CJS module cache on a best-effort basis. * TODO(joyeecheung): this can be rather expensive, cache the result on the * ModuleWrap wherever we can. * @param {string|undefined} url URL to convert

(url)

Source from the content-addressed store, hash-verified

358 * @returns {string|undefined}
359 */
360function urlToFilename(url) {
361 if (url && StringPrototypeStartsWith(url, 'file://')) {
362 let urlObj;
363 try {
364 urlObj = new URL(url);
365 } catch {
366 // Not a proper URL, return as-is as the cache key.
367 return url;
368 }
369 try {
370 return fileURLToPath(urlObj);
371 } catch {
372 // This is generally only possible when the URL is provided by a custom loader.
373 // Just use the path and ignore whether it's absolute or not as there's no such
374 // requirement for CJS cache.
375 return urlObj.pathname;
376 }
377 }
378 // Not a file URL, return as-is.
379 return url;
380}
381
382// Whether we have started executing any user-provided CJS code.
383// This is set right before we call the wrapped CJS code (not after,

Callers 8

runSyncMethod · 0.85
runSyncMethod · 0.85
importSyncForRequireMethod · 0.85
createCJSModuleWrapFunction · 0.85

Calls 1

fileURLToPathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…