Skip to content

Conversation

@logaretm
Copy link
Collaborator

When using the esbuild plugin with either moduleMetadata or applicationKey options configured, debug IDs were not being injected into bundles. This caused sourcemap uploads to fail with:

Could not determine debug ID from bundle.

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.

entry point -> metadata proxy -> debug ID proxy -> original module.

Minor note, I needed to enable es6 env since I wanted to use sets for this.

closes #726
closes #826

Copilot AI review requested due to automatic review settings December 26, 2025 14:18
@linear
Copy link

linear bot commented Dec 26, 2025

Comment on lines +49 to +55
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.

Comment on lines 78 to 81
const isImportFromMetadataProxy =
args.kind === "import-statement" &&
args.importer !== undefined &&
metadataProxyEntryPoints.has(args.importer);

This comment was marked as outdated.

Copy link

Copilot AI left a 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 moduleMetadata and applicationKey scenarios

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.

@logaretm logaretm requested review from Lms24 and timfish December 29, 2025 09:05
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@logaretm logaretm merged commit 777850f into main Dec 29, 2025
24 checks passed
@logaretm logaretm deleted the awad/bundler-91-esbuild-modulemetadata-breaks-debugid-injection branch December 29, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Esbuild moduleMetadata breaks debugID injection applicationKey in esbuild plugin prevents debug ID injection

3 participants