-
Notifications
You must be signed in to change notification settings - Fork 51
fix(esbuild): fix debug ID injection when moduleMetadata or applicationKey is set
#828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(esbuild): fix debug ID injection when moduleMetadata or applicationKey is set
#828
Conversation
| const metadataProxyEntryPoints = new Set<string>(); | ||
|
|
||
| /** | ||
| * Set to track which paths have already been wrapped with debug ID injection | ||
| * This prevents the debug ID plugin from wrapping the same module multiple times | ||
| */ | ||
| const debugIdWrappedPaths = new Set<string>(); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
packages/esbuild-plugin/src/index.ts
Outdated
| const isImportFromMetadataProxy = | ||
| args.kind === "import-statement" && | ||
| args.importer !== undefined && | ||
| metadataProxyEntryPoints.has(args.importer); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical bug where debug IDs were not being injected into bundles when using the esbuild plugin with moduleMetadata or applicationKey options. The issue occurred because both the metadata injection plugin and debug ID injection plugin use onResolve hooks, causing the metadata plugin to block debug ID injection.
Key changes:
- Introduced shared state between plugins using module-level Sets to coordinate plugin execution
- Modified debug ID injection plugin to recognize and wrap imports from metadata proxy modules
- Added comprehensive integration tests for both
moduleMetadataandapplicationKeyscenarios
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/esbuild-plugin/src/index.ts | Implements shared state coordination between metadata and debug ID plugins, enabling proper chaining of proxy modules |
| packages/esbuild-plugin/.eslintrc.js | Enables ES6 environment for Set support |
| packages/integration-tests/fixtures/metadata-with-debug-id/setup.ts | Test setup for metadata with debug ID injection scenario |
| packages/integration-tests/fixtures/metadata-with-debug-id/metadata-with-debug-id.test.ts | Integration tests verifying debug IDs and metadata work together across all bundlers |
| packages/integration-tests/fixtures/metadata-with-debug-id/input/bundle.js | Test input that outputs both debug IDs and metadata for verification |
| packages/integration-tests/fixtures/application-key-with-debug-id/setup.ts | Test setup for applicationKey with debug ID injection scenario |
| packages/integration-tests/fixtures/application-key-with-debug-id/input/bundle.js | Test input that outputs both debug IDs and metadata for applicationKey verification |
| packages/integration-tests/fixtures/application-key-with-debug-id/application-key-with-debug-id.test.ts | Integration tests verifying applicationKey metadata and debug IDs work together |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...tegration-tests/fixtures/application-key-with-debug-id/application-key-with-debug-id.test.ts
Outdated
Show resolved
Hide resolved
...tegration-tests/fixtures/application-key-with-debug-id/application-key-with-debug-id.test.ts
Show resolved
Hide resolved
packages/integration-tests/fixtures/metadata-with-debug-id/metadata-with-debug-id.test.ts
Show resolved
Hide resolved
Lms24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
When using the esbuild plugin with either
moduleMetadataorapplicationKeyoptions configured, debug IDs were not being injected into bundles. This caused sourcemap uploads to fail with:The metadata injection plugin and debug ID injection plugin both use
onResolve, the metadata plugin will block debug ID injection from running.I fixed this by adding shared state between the two plugins. The metadata plugin now registers which entry points it wraps, and the debug ID plugin recognizes imports from those proxy modules and wraps them too, so they are properly chained.
Minor note, I needed to enable es6 env since I wanted to use sets for this.
closes #726
closes #826