Skip to content

Commit f8e5483

Browse files
committed
fix(@angular/build): address review feedback in sourcemap ignore-list plugin
Address review comments for the fast sourcemap ignore-list implementation: - Only bypass the fast path when IGNORE_LIST_BYTES is present in the buffer instead of skipping the file completely, preventing false positives if the token appears in sourcesContent. - Check if the ignore-list extension property already exists on the parsed map object in the fallback slow path to avoid duplicate insertion. - Validate that every element in the extracted sources array is a string to prevent runtime errors.
1 parent 2efacdc commit f8e5483

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

packages/angular/build/src/tools/esbuild/sourcemap-ignorelist-plugin.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ function extractSources(contents: Buffer): string[] | undefined {
8585
const slice = contents.toString('utf-8', arrayStartIndex, i + 1);
8686
const parsed = JSON.parse(slice);
8787

88-
return Array.isArray(parsed) ? (parsed as string[]) : undefined;
88+
return Array.isArray(parsed) && parsed.every((s) => typeof s === 'string')
89+
? (parsed as string[])
90+
: undefined;
8991
} catch {
9092
return undefined;
9193
}
@@ -153,34 +155,40 @@ export function createSourcemapIgnorelistPlugin(): Plugin {
153155
continue;
154156
}
155157

156-
// If the ignore list is already present, avoid duplicate insertion
157-
if (contents.includes(IGNORE_LIST_BYTES)) {
158-
continue;
159-
}
158+
let fastPathSuccess = false;
159+
if (!contents.includes(IGNORE_LIST_BYTES)) {
160+
const sources = extractSources(contents);
161+
if (sources) {
162+
const ignoreList: number[] = [];
163+
for (let index = 0; index < sources.length; ++index) {
164+
const location = sources[index].indexOf('node_modules/');
165+
if (location === 0 || (location > 0 && sources[index][location - 1] === '/')) {
166+
ignoreList.push(index);
167+
}
168+
}
160169

161-
const sources = extractSources(contents);
162-
if (sources) {
163-
const ignoreList: number[] = [];
164-
for (let index = 0; index < sources.length; ++index) {
165-
const location = sources[index].indexOf('node_modules/');
166-
if (location === 0 || (location > 0 && sources[index][location - 1] === '/')) {
167-
ignoreList.push(index);
170+
if (ignoreList.length === 0) {
171+
continue;
168172
}
169-
}
170173

171-
if (ignoreList.length === 0) {
172-
continue;
174+
const updated = updateSourcemapFast(contents, ignoreList);
175+
if (updated) {
176+
file.contents = updated;
177+
fastPathSuccess = true;
178+
}
173179
}
180+
}
174181

175-
const updated = updateSourcemapFast(contents, ignoreList);
176-
if (updated) {
177-
file.contents = updated;
178-
continue;
179-
}
182+
if (fastPathSuccess) {
183+
continue;
180184
}
181185

182186
// Fallback to full JSON parse/stringify if fast scanning or splicing fails
183187
const map = JSON.parse(contents.toString('utf-8')) as SourceMap;
188+
if (map[IGNORE_LIST_ID]) {
189+
continue;
190+
}
191+
184192
const ignoreList = [];
185193

186194
// Check and store the index of each source originating from a node modules directory

0 commit comments

Comments
 (0)