Skip to content

Commit 5ee6df7

Browse files
fix: improve source map comment detection and test fix
1 parent 0720a2f commit 5ee6df7

3 files changed

Lines changed: 5 additions & 32 deletions

File tree

.idea/copilotDiffState.xml

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/angular/build/src/builders/application/tests/options/subresource-integrity_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
9898
);
9999
expect(jsFiles.length).toBeGreaterThan(0);
100100

101-
const debugIdRe = /^\s*\/\/\s*#\s*debugId=([0-9a-f-]+)\s*$/m;
101+
const debugIdRe = /\/\/# debugId=([^\r\n]*)/;
102102
const indexHtml = harness.readFile('dist/browser/index.html');
103103
const importmapMatch = indexHtml.match(/<script type="importmap">([^<]+)<\/script>/);
104104
const importmap = importmapMatch

packages/angular/build/src/utils/debug-id.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export function generateDebugId(name: string | Uint8Array): string {
4141
}
4242

4343
/** Pattern matching an existing `//# debugId=<uuid>` comment anywhere in the file. */
44-
const DEBUG_ID_COMMENT = /^[ \t]*\/\/[ \t]*#[ \t]*debugId=[^\n]*\n?/m;
44+
const DEBUG_ID_COMMENT = /\n\/\/# debugId=[^\r\n]*\n?/;
4545

4646
/** Pattern matching the `//# sourceMappingURL=` comment, used to position the debug-id line. */
47-
const SOURCE_MAPPING_URL_COMMENT = /^[ \t]*\/\/[ \t]*#[ \t]*sourceMappingURL=[^\n]*$/m;
47+
const SOURCE_MAPPING_URL_COMMENT = /\n\/\/# sourceMappingURL=[^\r\n]*\s*$/;
4848

4949
/**
5050
* Inserts (or replaces) a `//# debugId=<id>` comment in the given JavaScript text.
@@ -58,11 +58,11 @@ export function injectDebugIdIntoJs(text: string, id: string): string {
5858

5959
// Replace any existing debugId comment to keep the operation idempotent.
6060
if (DEBUG_ID_COMMENT.test(text)) {
61-
return text.replace(DEBUG_ID_COMMENT, `${comment}\n`);
61+
return text.replace(DEBUG_ID_COMMENT, `\n${comment}\n`);
6262
}
6363

6464
if (SOURCE_MAPPING_URL_COMMENT.test(text)) {
65-
return text.replace(SOURCE_MAPPING_URL_COMMENT, (match) => `${comment}\n${match}`);
65+
return text.replace(SOURCE_MAPPING_URL_COMMENT, (match) => `\n${comment}${match}`);
6666
}
6767

6868
// No source map reference; append at the very end on its own line.

0 commit comments

Comments
 (0)