1
+ /* eslint-disable no-console */
1
2
import { Package } from '@sentry/types' ;
2
3
import { existsSync , mkdirSync , promises } from 'fs' ;
3
4
import HtmlWebpackPlugin from 'html-webpack-plugin' ;
@@ -8,6 +9,29 @@ import webpackConfig from '../webpack.config';
8
9
9
10
const PACKAGE_PATH = '../../packages' ;
10
11
12
+ const bundleKey = process . env . PW_BUNDLE || '' ;
13
+ const useCompiledModule = ( bundleKey && bundleKey === 'esm' ) || bundleKey === 'dist' ;
14
+ const useBundle = bundleKey && ! useCompiledModule ;
15
+
16
+ const TEST_PATHS : Record < string , Record < string , string > > = {
17
+ browser : {
18
+ dist : 'dist/index.js' ,
19
+ esm : 'esm/index.js' ,
20
+ bundle : 'build/bundle.js' ,
21
+ bundle_min : 'build/bundle.min.js' ,
22
+ bundle_es6 : 'build/bundle.es6.js' ,
23
+ bundle_es6_min : 'build/bundle.es6.min.js' ,
24
+ } ,
25
+ tracing : {
26
+ dist : 'dist/index.js' ,
27
+ esm : 'esm/index.js' ,
28
+ bundle : 'build/bundle.tracing.js' ,
29
+ bundle_min : 'build/bundle.tracing.min.js' ,
30
+ bundle_es6 : 'build/bundle.tracing.js' ,
31
+ bundle_es6_min : 'build/bundle.tracing.min.js' ,
32
+ } ,
33
+ } ;
34
+
11
35
/**
12
36
* Generate webpack aliases based on packages in monorepo
13
37
* Example of an alias: '@sentry/serverless': 'path/to/sentry-javascript/packages/serverless',
@@ -19,11 +43,26 @@ async function generateSentryAlias(): Promise<Record<string, string>> {
19
43
20
44
return Object . fromEntries (
21
45
await Promise . all (
22
- dirents . map ( async d => {
46
+ dirents . map ( async packageName => {
23
47
const packageJSON : Package = JSON . parse (
24
- ( await promises . readFile ( path . resolve ( PACKAGE_PATH , d , 'package.json' ) , { encoding : 'utf-8' } ) ) . toString ( ) ,
48
+ (
49
+ await promises . readFile ( path . resolve ( PACKAGE_PATH , packageName , 'package.json' ) , { encoding : 'utf-8' } )
50
+ ) . toString ( ) ,
25
51
) ;
26
- return [ packageJSON [ 'name' ] , path . resolve ( PACKAGE_PATH , d ) ] ;
52
+
53
+ const packagePath = path . resolve ( PACKAGE_PATH , packageName ) ;
54
+
55
+ if ( useCompiledModule && TEST_PATHS [ packageName ] ) {
56
+ const bundlePath = path . resolve ( packagePath , TEST_PATHS [ packageName ] [ bundleKey ] ) ;
57
+
58
+ if ( ! existsSync ( bundlePath ) ) {
59
+ console . warn ( `${ bundlePath } is not found. Try building the package before running tests.` ) ;
60
+ }
61
+
62
+ return [ packageJSON [ 'name' ] , bundlePath ] ;
63
+ }
64
+
65
+ return [ packageJSON [ 'name' ] , packagePath ] ;
27
66
} ) ,
28
67
) ,
29
68
) ;
@@ -44,6 +83,14 @@ export async function generatePage(
44
83
mkdirSync ( localPath , { recursive : true } ) ;
45
84
}
46
85
86
+ const bundlesToInject = useBundle
87
+ ? [ 'browser' , 'tracing' ] . map ( sentryPackage =>
88
+ path . resolve ( PACKAGE_PATH , sentryPackage , TEST_PATHS [ sentryPackage ] [ bundleKey ] ) ,
89
+ )
90
+ : [ ] ;
91
+
92
+ const initializationEntry = bundlesToInject . concat ( initializationPath ) ;
93
+
47
94
if ( ! existsSync ( bundlePath ) ) {
48
95
await new Promise < void > ( ( resolve , reject ) => {
49
96
const compiler = webpack (
@@ -52,7 +99,7 @@ export async function generatePage(
52
99
alias,
53
100
} ,
54
101
entry : {
55
- initialization : initializationPath ,
102
+ initialization : initializationEntry ,
56
103
subject : subjectPath ,
57
104
} ,
58
105
output : {
@@ -65,7 +112,6 @@ export async function generatePage(
65
112
template : templatePath ,
66
113
initialization : 'initialization.bundle.js' ,
67
114
subject : `subject.bundle.js` ,
68
- inject : false ,
69
115
} ) ,
70
116
] ,
71
117
} ) ,
0 commit comments