* Verifies all the paths in the sources field are as expected. * * @param {!Object} sourcemapJson * @param {string} map The map filepath to check
(sourcemapJson, map)
| 67 | * @param {string} map The map filepath to check |
| 68 | */ |
| 69 | function checkSourcemapSources(sourcemapJson, map) { |
| 70 | log('Inspecting', cyan('sources'), 'in', cyan(map) + '...'); |
| 71 | if (!sourcemapJson.sources) { |
| 72 | log(red('ERROR:'), 'Could not find', cyan('sources')); |
| 73 | throw new Error('Could not find sources array'); |
| 74 | } |
| 75 | /** @type {string[]} */ |
| 76 | const invalidSources = sourcemapJson.sources |
| 77 | .filter((source) => !source.match(/\[.*\]/)) // Ignore non-path sources '[...]' |
| 78 | .filter((source) => !fs.existsSync(source)); // All source paths should exist |
| 79 | if (invalidSources.length > 0) { |
| 80 | log( |
| 81 | red('ERROR:'), |
| 82 | 'Found invalid paths in', |
| 83 | cyan('sources') + ':', |
| 84 | cyan(invalidSources.join(', ')) |
| 85 | ); |
| 86 | throw new Error('Invalid paths in sources array'); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Performs a sanity check on the mappings field in the sourcemap file. |
no test coverage detected