@@ -32,6 +32,14 @@ const BUNDLE_PATHS: Record<string, Record<string, string>> = {
3232 bundle_es6 : 'build/bundles/bundle.tracing.js' ,
3333 bundle_es6_min : 'build/bundles/bundle.tracing.min.js' ,
3434 } ,
35+ integrations : {
36+ cjs : 'build/npm/cjs/index.js' ,
37+ esm : 'build/npm/esm/index.js' ,
38+ bundle_es5 : 'build/bundles/[INTEGRATION_NAME].es5.js' ,
39+ bundle_es5_min : 'build/bundles/[INTEGRATION_NAME].es5.min.js' ,
40+ bundle_es6 : 'build/bundles/[INTEGRATION_NAME].js' ,
41+ bundle_es6_min : 'build/bundles/[INTEGRATION_NAME].min.js' ,
42+ } ,
3543} ;
3644
3745/*
@@ -78,6 +86,7 @@ function generateSentryAlias(): Record<string, string> {
7886
7987class SentryScenarioGenerationPlugin {
8088 public requiresTracing : boolean = false ;
89+ public requiredIntegrations : string [ ] = [ ] ;
8190
8291 private _name : string = 'SentryScenarioGenerationPlugin' ;
8392
@@ -89,18 +98,24 @@ class SentryScenarioGenerationPlugin {
8998 // To help Webpack resolve Sentry modules in `import` statements in cases where they're provided in bundles rather than in `node_modules`
9099 '@sentry/browser' : 'Sentry' ,
91100 '@sentry/tracing' : 'Sentry' ,
101+ '@sentry/integrations' : 'Sentry.Integrations' ,
92102 }
93103 : { } ;
94104
95- // Checking if the current scenario has imported `@sentry/tracing`.
105+ // Checking if the current scenario has imported `@sentry/tracing` or `@sentry/integrations` .
96106 compiler . hooks . normalModuleFactory . tap ( this . _name , factory => {
97107 factory . hooks . parser . for ( 'javascript/auto' ) . tap ( this . _name , parser => {
98108 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
99- parser . hooks . import . tap ( this . _name , ( _statement : unknown , source : string ) => {
100- if ( source === '@sentry/tracing' ) {
101- this . requiresTracing = true ;
102- }
103- } ) ;
109+ parser . hooks . import . tap (
110+ this . _name ,
111+ ( statement : { specifiers : [ { imported : { name : string } } ] } , source : string ) => {
112+ if ( source === '@sentry/tracing' ) {
113+ this . requiresTracing = true ;
114+ } else if ( source === '@sentry/integrations' ) {
115+ this . requiredIntegrations . push ( statement . specifiers [ 0 ] . imported . name . toLowerCase ( ) ) ;
116+ }
117+ } ,
118+ ) ;
104119 } ) ;
105120 } ) ;
106121
@@ -113,6 +128,18 @@ class SentryScenarioGenerationPlugin {
113128 src : path . resolve ( PACKAGES_DIR , bundleName , BUNDLE_PATHS [ bundleName ] [ bundleKey ] ) ,
114129 } ) ;
115130
131+ this . requiredIntegrations . forEach ( integration => {
132+ const integrationObject = createHtmlTagObject ( 'script' , {
133+ src : path . resolve (
134+ PACKAGES_DIR ,
135+ 'integrations' ,
136+ BUNDLE_PATHS [ 'integrations' ] [ bundleKey ] . replace ( '[INTEGRATION_NAME]' , integration ) ,
137+ ) ,
138+ } ) ;
139+
140+ data . assetTags . scripts . unshift ( integrationObject ) ;
141+ } ) ;
142+
116143 data . assetTags . scripts . unshift ( bundleObject ) ;
117144 }
118145
0 commit comments