* 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)
| 370 | * @returns {import('internal/source_map/source_map').SourceMap | undefined} a source map or undefined if not found |
| 371 | */ |
| 372 | function 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. |
no test coverage detected
searching dependent graphs…