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

Function findSourceMap

lib/internal/source_map/source_map_cache.js:372–407  ·  view source on GitHub ↗

* Find a source map for a given actual source URL or path. * * This function may be invoked from user code or test runner, this must not throw * any exceptions. * @param {string} sourceURL - actual source URL or path * @returns {import('internal/source_map/source_map').SourceMap | undefined} a

(sourceURL)

Source from the content-addressed store, hash-verified

370 * @returns {import('internal/source_map/source_map').SourceMap | undefined} a source map or undefined if not found
371 */
372function findSourceMap(sourceURL) {
373 if (typeof sourceURL !== 'string') {
374 return undefined;
375 }
376
377 // No source maps for builtin modules.
378 if (sourceURL.startsWith('node:')) {
379 return undefined;
380 }
381
382 if (!getSourceMapsSupport().nodeModules && isUnderNodeModules(sourceURL)) {
383 return undefined;
384 }
385
386 SourceMap ??= require('internal/source_map/source_map').SourceMap;
387 try {
388 if (RegExpPrototypeExec(kLeadingProtocol, sourceURL) === null) {
389 // If the sourceURL is an invalid path, this will throw an error.
390 sourceURL = pathToFileURL(sourceURL).href;
391 }
392 const entry = getModuleSourceMapCache().get(sourceURL) ?? generatedSourceMapCache.get(sourceURL);
393 if (entry?.data == null) {
394 return undefined;
395 }
396
397 let sourceMap = entry.sourceMap;
398 if (sourceMap === undefined) {
399 sourceMap = new SourceMap(entry.data, { lineLengths: entry.lineLengths });
400 entry.sourceMap = sourceMap;
401 }
402 return sourceMap;
403 } catch (err) {
404 debug(err);
405 return undefined;
406 }
407}
408
409/**
410 * Retrieve the original source code from the source map's `sources` list or disk.

Callers 7

lazyFindSourceMapFunction · 0.85
getSourceMapErrorSourceFunction · 0.85
getErrorSourceLocationFunction · 0.85
runFunction · 0.85

Calls 6

getSourceMapsSupportFunction · 0.85
isUnderNodeModulesFunction · 0.85
getMethod · 0.65
requireFunction · 0.50
pathToFileURLFunction · 0.50
debugFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…