@@ -42,12 +42,16 @@ function esbuildReleaseInjectionPlugin(injectionCode: string): UnpluginOptions {
4242 } ;
4343}
4444
45- // Shared set to track entry points that have been wrapped by the metadata plugin.
46- // This allows the debug ID plugin to know when an import is coming from a metadata proxy.
45+ /**
46+ * Shared set to track entry points that have been wrapped by the metadata plugin
47+ * This allows the debug ID plugin to know when an import is coming from a metadata proxy
48+ */
4749const metadataProxyEntryPoints = new Set < string > ( ) ;
4850
49- // Set to track which paths have already been wrapped with debug ID injection.
50- // This prevents the debug ID plugin from wrapping the same module multiple times.
51+ /**
52+ * Set to track which paths have already been wrapped with debug ID injection
53+ * This prevents the debug ID plugin from wrapping the same module multiple times
54+ */
5155const debugIdWrappedPaths = new Set < string > ( ) ;
5256
5357function esbuildDebugIdInjectionPlugin ( logger : Logger ) : UnpluginOptions {
@@ -66,15 +70,11 @@ function esbuildDebugIdInjectionPlugin(logger: Logger): UnpluginOptions {
6670 }
6771
6872 onResolve ( { filter : / .* / } , ( args ) => {
69- // We want to inject debug IDs into entry points. However, when the module metadata
70- // injection plugin is also active, it intercepts entry points first and creates a
71- // proxy module that re-imports the original entry point. In that case, we need to
72- // also intercept those imports (which have kind === "import-statement") and inject
73- // debug IDs there too.
73+ // Inject debug IDs into entry points and into imports from metadata proxy modules
7474 const isEntryPoint = args . kind === "entry-point" ;
7575
76- // Check if this import is coming from a metadata proxy module.
77- // The metadata plugin registers entry points it wraps in the shared Set.
76+ // Check if this import is coming from a metadata proxy module
77+ // The metadata plugin registers entry points it wraps in the shared Set
7878 const isImportFromMetadataProxy =
7979 args . kind === "import-statement" &&
8080 args . importer !== undefined &&
@@ -84,8 +84,8 @@ function esbuildDebugIdInjectionPlugin(logger: Logger): UnpluginOptions {
8484 return ;
8585 }
8686
87- // Injected modules via the esbuild `inject` option do also have `kind == "entry-point"`.
88- // We do not want to inject debug IDs into those files because they are already bundled into the entrypoints
87+ // Skip injecting debug IDs into modules specified in the esbuild `inject` option
88+ // since they're already part of the entry points
8989 if ( initialOptions . inject ?. includes ( args . path ) ) {
9090 return ;
9191 }
@@ -94,10 +94,7 @@ function esbuildDebugIdInjectionPlugin(logger: Logger): UnpluginOptions {
9494 ? args . path
9595 : path . join ( args . resolveDir , args . path ) ;
9696
97- // Check if we've already wrapped this path. This can happen when both the metadata
98- // plugin and debug ID plugin are active - the debug ID proxy imports the original
99- // module, and since its importer path matches the metadata proxy entry point,
100- // we might try to wrap it again. Prevent this by tracking wrapped paths.
97+ // Skip injecting debug IDs into paths that have already been wrapped
10198 if ( debugIdWrappedPaths . has ( resolvedPath ) ) {
10299 return ;
103100 }
@@ -192,8 +189,7 @@ function esbuildModuleMetadataInjectionPlugin(injectionCode: string): UnpluginOp
192189 : path . join ( args . resolveDir , args . path ) ;
193190
194191 // Register this entry point so the debug ID plugin knows to wrap imports from
195- // this proxy module. This is needed because the debug ID plugin runs after us and
196- // needs to know when an import is coming from our proxy module.
192+ // this proxy module, this because the debug ID may run after the metadata plugin
197193 metadataProxyEntryPoints . add ( resolvedPath ) ;
198194
199195 return {
0 commit comments