@@ -4,7 +4,7 @@ import HtmlWebpackPlugin, { createHtmlTagObject } from 'html-webpack-plugin';
44import path from 'path' ;
55import { Compiler } from 'webpack' ;
66
7- const PACKAGE_PATH = '../../packages' ;
7+ const PACKAGES_DIR = '../../packages' ;
88
99const tracingOnly = process . env . PW_TRACING_ONLY === 'true' ;
1010const bundleKey = process . env . PW_BUNDLE ;
@@ -19,47 +19,54 @@ const BUNDLE_PATHS: Record<string, Record<string, string>> = {
1919 browser : {
2020 cjs : 'dist/index.js' ,
2121 esm : 'esm/index.js' ,
22- bundle : 'build/bundle.js' ,
23- bundle_min : 'build/bundle.min.js' ,
22+ bundle_es5 : 'build/bundle.js' ,
23+ bundle_es5_min : 'build/bundle.min.js' ,
2424 bundle_es6 : 'build/bundle.es6.js' ,
2525 bundle_es6_min : 'build/bundle.es6.min.js' ,
2626 } ,
2727 tracing : {
2828 cjs : 'dist/index.js' ,
2929 esm : 'esm/index.js' ,
30- bundle : 'build/bundle.tracing.js' ,
31- bundle_min : 'build/bundle.tracing.min.js' ,
32- // `tracing` doesn't have an es6 build
30+ bundle_es5 : 'build/bundle.tracing.js' ,
31+ bundle_es5_min : 'build/bundle.tracing.min.js' ,
32+ // `tracing` doesn't have an es6 build yet
3333 bundle_es6 : 'build/bundle.tracing.js' ,
3434 bundle_es6_min : 'build/bundle.tracing.min.js' ,
3535 } ,
3636} ;
3737
38- /**
38+ /*
3939 * Generate webpack aliases based on packages in monorepo
40- * Example of an alias: '@sentry/serverless': 'path/to/sentry-javascript/packages/serverless',
40+ *
41+ * When using compiled versions of the tracing and browser packages, their aliases look for example like
42+ * '@sentry/browser': 'path/to/sentry-javascript/packages/browser/esm/index.js'
43+ * When using bundled versions of the tracing and browser packages, their aliases look for example like
44+ * '@sentry/browser': false
45+ * so that the compiled versions aren't included
46+ * All other packages are aliased for example like
47+ * '@sentry/serverless': 'path/to/sentry-javascript/packages/serverless'
4148 */
4249function generateSentryAlias ( ) : Record < string , string > {
43- const dirents = readdirSync ( PACKAGE_PATH , { withFileTypes : true } )
50+ const packageNames = readdirSync ( PACKAGES_DIR , { withFileTypes : true } )
4451 . filter ( dirent => dirent . isDirectory ( ) )
4552 . map ( dir => dir . name ) ;
4653
4754 return Object . fromEntries (
48- dirents . map ( d => {
55+ packageNames . map ( packageName => {
4956 const packageJSON : Package = JSON . parse (
50- readFileSync ( path . resolve ( PACKAGE_PATH , d , 'package.json' ) , { encoding : 'utf-8' } ) . toString ( ) ,
57+ readFileSync ( path . resolve ( PACKAGES_DIR , packageName , 'package.json' ) , { encoding : 'utf-8' } ) . toString ( ) ,
5158 ) ;
5259
53- const modulePath = path . resolve ( PACKAGE_PATH , d ) ;
60+ const modulePath = path . resolve ( PACKAGES_DIR , packageName ) ;
5461
55- if ( useCompiledModule && bundleKey && BUNDLE_PATHS [ d ] ?. [ bundleKey ] ) {
56- const bundlePath = path . resolve ( modulePath , BUNDLE_PATHS [ d ] [ bundleKey ] ) ;
62+ if ( useCompiledModule && bundleKey && BUNDLE_PATHS [ packageName ] ?. [ bundleKey ] ) {
63+ const bundlePath = path . resolve ( modulePath , BUNDLE_PATHS [ packageName ] [ bundleKey ] ) ;
5764
5865 return [ packageJSON [ 'name' ] , bundlePath ] ;
5966 }
6067
61- if ( useBundle && bundleKey && BUNDLE_PATHS [ d ] ?. [ bundleKey ] ) {
62- // If we're injecting a bundle, ignore the webpack import .
68+ if ( useBundle && bundleKey ) {
69+ // If we're injecting a bundle, ignore the webpack imports .
6370 return [ packageJSON [ 'name' ] , false ] ;
6471 }
6572
@@ -99,9 +106,10 @@ class SentryScenarioGenerationPlugin {
99106 compiler . hooks . compilation . tap ( this . _name , compilation => {
100107 HtmlWebpackPlugin . getHooks ( compilation ) . alterAssetTags . tapAsync ( this . _name , ( data , cb ) => {
101108 if ( useBundle && bundleKey ) {
102- const bundleName = tracingOnly || this . requiresTracing ? 'tracing' : 'browser' ;
109+ const useTracingBundle = tracingOnly || this . requiresTracing ;
110+ const bundleName = useTracingBundle ? 'tracing' : 'browser' ;
103111 const bundleObject = createHtmlTagObject ( 'script' , {
104- src : path . resolve ( PACKAGE_PATH , bundleName , BUNDLE_PATHS [ bundleName ] [ bundleKey ] ) ,
112+ src : path . resolve ( PACKAGES_DIR , bundleName , BUNDLE_PATHS [ bundleName ] [ bundleKey ] ) ,
105113 } ) ;
106114
107115 data . assetTags . scripts . unshift ( bundleObject ) ;
0 commit comments