// SM-A7 — detect Subresource Integrity BEFORE stamping, because stamping after emit breaks it. // // `sourcemaps inject` appends the debug-id comment and the `_bugseeDebugIds` registration to every // emitted `.js`. A build that computed SRI hashes during emit (`webpack-subresource-integrity`, // Angular's `subresourceIntegrity: true`) has already written a hash of the PRE-stamp bytes into the // HTML, so the browser refuses the script and the page runs nothing at all. // // Measured 2026-09-18 on webpack 5.111 + webpack-subresource-integrity, Chromium 151: before inject // the app ran clean; after it, `window.__ran` was false and the console carried "Failed to find a // valid digest in the 'integrity' attribute … The resource has been blocked." `index.html` was // byte-identical; only the JS grew (114 → 472 bytes). // // So we look for it and refuse rather than shipping a broken page. Rewriting the hashes is not a // safe alternative: `webpack-subresource-integrity` also embeds the lazy chunks' hashes in the // runtime chunk (`__webpack_require__.sriHashes`), so patching the HTML alone would still break // every dynamic import. import { createHash } from 'node:crypto'; import type { Dirent } from 'node:fs'; import { readdir, readFile } from 'node:fs/promises'; import { isAbsolute, join, normalize, resolve, sep } from 'node:path'; import { readRegularFile } from './safe-read'; /** A page larger than this is not scanned (a real page is a few KB): the scan must stay bounded on hostile input. */ export const MAX_HTML_BYTES = 8 * 1024 * 1024; /** One `