@@ -38,26 +38,57 @@ function esbuildReleaseInjectionPlugin(injectionCode: string): UnpluginOptions {
3838
3939function esbuildDebugIdInjectionPlugin ( ) : UnpluginOptions {
4040 const pluginName = "sentry-esbuild-debug-id-injection-plugin" ;
41- const virtualReleaseInjectionFilePath = path . resolve ( "_sentry-debug-id-injection-stub" ) ; // needs to be an absolute path for older eslint versions
41+ const proxyNamespace = "sentry-debug-id-proxy" ;
42+ const stubNamespace = "sentry-debug-id-stub" ;
4243
4344 return {
4445 name : pluginName ,
4546
4647 esbuild : {
47- setup ( { initialOptions, onLoad, onResolve } ) {
48- initialOptions . inject = initialOptions . inject || [ ] ;
49- initialOptions . inject . push ( virtualReleaseInjectionFilePath ) ;
48+ setup ( { onLoad, onResolve } ) {
49+ onResolve ( { filter : / .* / } , ( args ) => {
50+ if ( args . kind !== "entry-point" ) {
51+ return ;
52+ }
53+ return {
54+ pluginName,
55+ path : args . path ,
56+ namespace : proxyNamespace ,
57+ pluginData : {
58+ originalPath : args . path ,
59+ originalResolveDir : args . resolveDir ,
60+ } ,
61+ } ;
62+ } ) ;
63+
64+ onLoad ( { filter : / .* / , namespace : proxyNamespace } , ( args ) => {
65+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
66+ const originalPath = args . pluginData . originalPath as string ;
67+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
68+ const originalResolveDir = args . pluginData . originalResolveDir as string ;
69+ return {
70+ loader : "js" ,
71+ pluginName,
72+ contents : `
73+ import "_sentry-debug-id-injection-stub";
74+ import * as OriginalModule from "${ originalPath } ";
75+ export default OriginalModule.default;
76+ export * from "${ originalPath } ";` ,
77+ resolveDir : originalResolveDir ,
78+ } ;
79+ } ) ;
5080
5181 onResolve ( { filter : / _ s e n t r y - d e b u g - i d - i n j e c t i o n - s t u b / } , ( args ) => {
5282 return {
5383 path : args . path ,
5484 sideEffects : true ,
5585 pluginName,
86+ namespace : stubNamespace ,
5687 suffix : "?sentry-module-id=" + uuidv4 ( ) , // create different module, each time this is resolved
5788 } ;
5889 } ) ;
5990
60- onLoad ( { filter : / _ s e n t r y - d e b u g - i d - i n j e c t i o n - s t u b / } , ( ) => {
91+ onLoad ( { filter : / _ s e n t r y - d e b u g - i d - i n j e c t i o n - s t u b / , namespace : stubNamespace } , ( ) => {
6192 return {
6293 loader : "js" ,
6394 pluginName,
0 commit comments