feat(esbuild): inject sourcemap IDs before asset hashing - #4644
Draft
hpouillot wants to merge 1 commit into
Draft
Conversation
Add a first-party esbuild plugin for Angular and other in-memory builds. The plugin registers content-hashed output filenames at runtime before esbuild computes them, then stamps the matching filename into source-map metadata for a later non-mutating CLI upload. Includes unit coverage for runtime registration, source-map positions, deterministic output hashes, downstream hashing order, configuration idempotency, and error handling. Generated-By: PostHog Desktop Task-Id: 3385093b-f0e6-46eb-9d6e-33ce42daa018
1 task
Contributor
Contributor
|
Size Change: 0 B Total Size: 20.1 MB ℹ️ View Unchanged
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Post-build source-map injection rewrites JavaScript after Angular has generated
ngsw.jsonand after bundlers/CDNs have chosen content-hashed filenames. This invalidates Angular service-worker versions, SRI values, and immutable cache keys.Editing Angular's generated manifest inside a generic CLI would fix one symptom but couple PostHog to a framework-private file format.
Fixes PostHog/posthog#86046 together with PostHog/posthog#85637.
Changes
@posthog/esbuild-pluginpackage.banneroption, before output hashes are computed.@angular-builders/custom-esbuildand the required non-mutatingposthog-cli sourcemap uploadstep.The companion CLI change accepts this tightly-scoped map-only ID only when the deployed JavaScript carries the matching runtime-registration marker and the map ID equals the output filename. Event release mode remains unsupported.
Why this shape
An esbuild
onEndmutation is still too late: esbuild has already chosen[hash]filenames. A random chunk ID injected there changes bytes without changing the filename. The static banner is part of esbuild's own input to output hashing, whileimport.meta.urlprovides each final filename at runtime.Verification
Automated:
pnpm --filter @posthog/esbuild-plugin lintpnpm --filter @posthog/esbuild-plugin test:unit(6 tests)pnpm --filter @posthog/esbuild-plugin buildAngular integration (Angular 22.1.3 +
@angular-builders/custom-esbuild22.0.1 + PWA):ngsw.jsonmatched the emitted file.chunk_idmatched the content-hashed output filename.main-*.jscontent hash, confirming the banner was included before output naming.Release
Includes a changeset for the initial
@posthog/esbuild-pluginrelease.