fix(cli): support pre-hash esbuild sourcemap IDs - #85637
Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
🤖 CI report✅ Trunk lane — non-backend laneThis PR is assigned to the non-backend lane. It does not run backend Python tests and may merge in parallel with PRs in other lanes. |
There was a problem hiding this comment.
Additive, contained change to the sourcemap CLI: it only adds warning logs and a README caveat when injection/cleanup rewrites built files, without altering the actual injection behavior; includes a targeted regression test. No risky territory (no data model, API, billing, auth, dependency, or CI/deploy config changes) and no unresolved review concerns.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 122L, 2F substantive, 148L/3F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1c-medium (148L, 3F, single-area, fix) |
| stamphog 2.0.0b4 | .stamphog/policy.yml @ fcfd143 · reviewed head fcfd143 |
New commits were pushed — dismissing the stamphog approval from an earlier head. This PR no longer qualifies for automatic review.
e2cf647 to
6dd3f43
Compare
|
cc @PostHog/team-error-tracking |
Injection appends a chunk id (and, in event mode, a release id) to each JS chunk, then writes the file back in place. Cleanup strips sourceMappingURL comments the same way. Any content hash pinned before these steps stops matching, which silently breaks service worker manifests, Subresource Integrity, and deploy manifests. The CLI now logs which built files it rewrote, so a pipeline can regenerate its manifest. A README caveat states the ordering rule with an Angular ngsw-config example. Generated-By: PostHog Desktop Task-Id: f594195d-afac-41b7-8d87-db49eb2ef661
Replace Angular manifest rewriting with a generic build-time contract. Accept a source-map-only output-filename ID when the deployed JavaScript contains the matching runtime registration marker and the map ID exactly matches the filename. Keep normal source-injected IDs authoritative, reject mismatches, and reject output-filename IDs in event release mode. Document the esbuild plugin workflow and retain the official ngsw regeneration fallback. Generated-By: PostHog Desktop Task-Id: 3385093b-f0e6-46eb-9d6e-33ce42daa018
52ba1b0 to
8ea5a40
Compare

Problem
posthog-cli sourcemap injectrewrites JavaScript after Angular has generatedngsw.jsonand after bundlers or CDNs have chosen content-hashed filenames. This invalidates service-worker versions, SRI values, and immutable cache keys.Editing Angular's generated manifest in the CLI would couple a generic source-map tool to a framework-private format. A source-map-only ID is also insufficient unless the deployed JavaScript registers the same ID at runtime.
Fixes #86046 together with PostHog/posthog-js#4644.
Changes
--delete-afterrewrites built JavaScript.chunk_idmust exactly match the JavaScript filename;@posthog/esbuild-plugin+ non-mutatingsourcemap uploadAngular flow.ngsw-configregeneration as the fallback for projects that cannot customize their builder.Companion plugin
PostHog/posthog-js#4644 adds
@posthog/esbuild-plugin. It inserts a deterministicimport.meta.urlruntime banner before esbuild computes output hashes, then stamps the final content-hashed filename into source-map metadata without rewriting JavaScript. Angular can safely generatengsw.jsonafterward.Verification
cargo test --lib(148 passed)cargo test --test sourcemap(28 passed)cargo clippy --lib --tests -- -D warningscargo fmt -- --checkngsw.jsonJavaScript SHA-1 matched, map IDs matched content-hashed filenames, and repeat builds were byte-identical.Automatic notifications
Docs update
CLI README updated. Public Angular source-map docs should move to the esbuild plugin workflow after both packages are released.