* Retrieve the original source code from the source map's `sources` list or disk. * @param {import('internal/source_map/source_map').SourceMap.payload} payload * @param {string} originalSourcePath - path or url of the original source * @returns {string | undefined} - the source content or undefin
(payload, originalSourcePath)
| 413 | * @returns {string | undefined} - the source content or undefined if file not found |
| 414 | */ |
| 415 | function getOriginalSource(payload, originalSourcePath) { |
| 416 | let source; |
| 417 | // payload.sources has been normalized to be an array of absolute urls. |
| 418 | const sourceContentIndex = |
| 419 | ArrayPrototypeIndexOf(payload.sources, originalSourcePath); |
| 420 | if (payload.sourcesContent?.[sourceContentIndex]) { |
| 421 | // First we check if the original source content was provided in the |
| 422 | // source map itself: |
| 423 | source = payload.sourcesContent[sourceContentIndex]; |
| 424 | } else if (StringPrototypeStartsWith(originalSourcePath, 'file://')) { |
| 425 | // If no sourcesContent was found, attempt to load the original source |
| 426 | // from disk: |
| 427 | debug(`read source of ${originalSourcePath} from filesystem`); |
| 428 | const originalSourcePathNoScheme = fileURLToPath(originalSourcePath); |
| 429 | try { |
| 430 | source = readFileSync(originalSourcePathNoScheme, 'utf8'); |
| 431 | } catch (err) { |
| 432 | debug(err); |
| 433 | } |
| 434 | } |
| 435 | return source; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Get the line of source in the source map. |
no test coverage detected
searching dependent graphs…