MCPcopy Create free account
hub / github.com/ampproject/amphtml / checkSourcemapSources

Function checkSourcemapSources

build-system/tasks/check-sourcemaps.js:69–88  ·  view source on GitHub ↗

* Verifies all the paths in the sources field are as expected. * * @param {!Object} sourcemapJson * @param {string} map The map filepath to check

(sourcemapJson, map)

Source from the content-addressed store, hash-verified

67 * @param {string} map The map filepath to check
68 */
69function 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.

Callers 1

checkSourceMapFunction · 0.85

Calls 4

cyanFunction · 0.85
redFunction · 0.85
logFunction · 0.50
filterMethod · 0.45

Tested by

no test coverage detected