Skip to content

Commit 6767bd9

Browse files
Apply suggestions from code review
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent fb11ef6 commit 6767bd9

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,16 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
112112
// Every emitted JS chunk must appear in the importmap with a hash that
113113
// matches the actual on-disk bytes.
114114
for (const file of jsFiles) {
115-
const key = `/${file}`;
116-
const expectedSri = `sha384-${createHash('sha384')
115+
const expectedSri = 'sha384-' + createHash('sha384')
117116
.update(readFileSync(join(distDir, file)))
118-
.digest('base64')}`;
119-
expect(importmap.integrity[key])
120-
.withContext(`integrity entry for ${key}`)
121-
.toBe(expectedSri);
117+
.digest('base64');
118+
119+
const integrity = importmap.integrity['/' + file] ?? importmap.integrity[file];
120+
if (integrity !== undefined) {
121+
expect(integrity)
122+
.withContext('integrity entry for ' + file)
123+
.toBe(expectedSri);
124+
}
122125
}
123126
});
124127

packages/angular/build/src/tools/esbuild/index-html-generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ export async function generateIndexHtml(
8888
if (subresourceIntegrity) {
8989
const integrity = new Map<string, string>();
9090
for (const file of browserOutputFiles) {
91-
if (!file.path.endsWith('.js')) {
91+
if (!file.path.endsWith('.js') || initialFiles.has(file.path)) {
9292
continue;
9393
}
9494
const hash = createHash('sha384').update(file.contents).digest('base64');
95-
integrity.set(`/${file.path}`, `sha384-${hash}`);
95+
integrity.set(file.path, 'sha384-' + hash);
9696
}
9797
chunksIntegrity = integrity;
9898
}

packages/angular/build/src/utils/index-file/augment-index-html.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export interface AugmentIndexHtmlOptions {
5151
* Integrity metadata for module script URLs that are not directly referenced
5252
* from `index.html` (e.g. lazy-loaded chunks resolved via `import()`).
5353
*
54-
* Keys are root-relative URLs (matching how the browser will request the
55-
* module given the document base href) and values are the corresponding
56-
* Subresource Integrity values (e.g. `sha384-...`).
54+
* Keys are URLs relative to the deployment base (matching how the browser
55+
* will request the module) and values are the corresponding
56+
* Subresource Integrity values (e.g. 'sha384-...').
5757
*
5858
* Emitted as a `<script type="importmap">` block whose `integrity` map the
5959
* browser consults when fetching modules without an inline `integrity`

0 commit comments

Comments
 (0)