@@ -4,7 +4,7 @@ import HtmlWebpackPlugin, { createHtmlTagObject } from 'html-webpack-plugin';
4
4
import path from 'path' ;
5
5
import { Compiler } from 'webpack' ;
6
6
7
- const PACKAGE_PATH = '../../packages' ;
7
+ const PACKAGES_DIR = '../../packages' ;
8
8
9
9
const tracingOnly = process . env . PW_TRACING_ONLY === 'true' ;
10
10
const bundleKey = process . env . PW_BUNDLE ;
@@ -19,47 +19,54 @@ const BUNDLE_PATHS: Record<string, Record<string, string>> = {
19
19
browser : {
20
20
cjs : 'dist/index.js' ,
21
21
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' ,
24
24
bundle_es6 : 'build/bundle.es6.js' ,
25
25
bundle_es6_min : 'build/bundle.es6.min.js' ,
26
26
} ,
27
27
tracing : {
28
28
cjs : 'dist/index.js' ,
29
29
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
33
33
bundle_es6 : 'build/bundle.tracing.js' ,
34
34
bundle_es6_min : 'build/bundle.tracing.min.js' ,
35
35
} ,
36
36
} ;
37
37
38
- /**
38
+ /*
39
39
* 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'
41
48
*/
42
49
function generateSentryAlias ( ) : Record < string , string > {
43
- const dirents = readdirSync ( PACKAGE_PATH , { withFileTypes : true } )
50
+ const packageNames = readdirSync ( PACKAGES_DIR , { withFileTypes : true } )
44
51
. filter ( dirent => dirent . isDirectory ( ) )
45
52
. map ( dir => dir . name ) ;
46
53
47
54
return Object . fromEntries (
48
- dirents . map ( d => {
55
+ packageNames . map ( packageName => {
49
56
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 ( ) ,
51
58
) ;
52
59
53
- const modulePath = path . resolve ( PACKAGE_PATH , d ) ;
60
+ const modulePath = path . resolve ( PACKAGES_DIR , packageName ) ;
54
61
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 ] ) ;
57
64
58
65
return [ packageJSON [ 'name' ] , bundlePath ] ;
59
66
}
60
67
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 .
63
70
return [ packageJSON [ 'name' ] , false ] ;
64
71
}
65
72
@@ -99,9 +106,10 @@ class SentryScenarioGenerationPlugin {
99
106
compiler . hooks . compilation . tap ( this . _name , compilation => {
100
107
HtmlWebpackPlugin . getHooks ( compilation ) . alterAssetTags . tapAsync ( this . _name , ( data , cb ) => {
101
108
if ( useBundle && bundleKey ) {
102
- const bundleName = tracingOnly || this . requiresTracing ? 'tracing' : 'browser' ;
109
+ const useTracingBundle = tracingOnly || this . requiresTracing ;
110
+ const bundleName = useTracingBundle ? 'tracing' : 'browser' ;
103
111
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 ] ) ,
105
113
} ) ;
106
114
107
115
data . assetTags . scripts . unshift ( bundleObject ) ;
0 commit comments