1
- import * as vite from "vite" ;
1
+ import * as vite3 from "vite" ;
2
2
import * as path from "path" ;
3
- import * as rollup from "rollup" ;
3
+ import * as rollup3 from "rollup" ;
4
4
import { default as webpack4 } from "webpack4" ;
5
5
import { webpack as webpack5 } from "webpack5" ;
6
6
import * as esbuild from "esbuild" ;
@@ -10,17 +10,48 @@ import { sentryWebpackPlugin } from "@sentry/webpack-plugin";
10
10
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin" ;
11
11
import { sentryRollupPlugin } from "@sentry/rollup-plugin" ;
12
12
13
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14
- const nodejsMajorversion = process . version . split ( "." ) [ 0 ] ! . slice ( 1 ) ;
13
+ const [ NODE_MAJOR_VERSION ] = process . version . split ( "." ) . map ( Number ) as [ number ] ;
14
+
15
+ type Bundlers =
16
+ | "webpack4"
17
+ | "webpack5"
18
+ | "esbuild"
19
+ | "rollup"
20
+ | "rollup4"
21
+ | "vite"
22
+ | "vite6"
23
+ | string ;
15
24
16
25
export function createCjsBundles (
17
26
entrypoints : { [ name : string ] : string } ,
18
27
outFolder : string ,
19
28
sentryUnpluginOptions : Options ,
20
- plugins : string [ ] = [ ]
29
+ plugins : Bundlers [ ] = [ ]
21
30
) : void {
22
31
if ( plugins . length === 0 || plugins . includes ( "vite" ) ) {
23
- void vite . build ( {
32
+ void vite3 . build ( {
33
+ clearScreen : false ,
34
+ build : {
35
+ sourcemap : true ,
36
+ outDir : path . join ( outFolder , "vite" ) ,
37
+ rollupOptions : {
38
+ input : entrypoints ,
39
+ output : {
40
+ format : "cjs" ,
41
+ entryFileNames : "[name].js" ,
42
+ } ,
43
+ } ,
44
+ } ,
45
+ plugins : [ sentryVitePlugin ( sentryUnpluginOptions ) ] ,
46
+ } ) ;
47
+ }
48
+
49
+ if ( NODE_MAJOR_VERSION >= 18 && ( plugins . length === 0 || plugins . includes ( "vite6" ) ) ) {
50
+ // We can't import this at the top of the file because they are not
51
+ // compatible with Node v14
52
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
53
+ const vite6 = require ( "vite6" ) as typeof vite3 ;
54
+ void vite6 . build ( {
24
55
clearScreen : false ,
25
56
build : {
26
57
sourcemap : true ,
@@ -36,8 +67,29 @@ export function createCjsBundles(
36
67
plugins : [ sentryVitePlugin ( sentryUnpluginOptions ) ] ,
37
68
} ) ;
38
69
}
70
+
39
71
if ( plugins . length === 0 || plugins . includes ( "rollup" ) ) {
40
- void rollup
72
+ void rollup3
73
+ . rollup ( {
74
+ input : entrypoints ,
75
+ plugins : [ sentryRollupPlugin ( sentryUnpluginOptions ) ] ,
76
+ } )
77
+ . then ( ( bundle ) =>
78
+ bundle . write ( {
79
+ sourcemap : true ,
80
+ dir : path . join ( outFolder , "rollup" ) ,
81
+ format : "cjs" ,
82
+ exports : "named" ,
83
+ } )
84
+ ) ;
85
+ }
86
+
87
+ if ( NODE_MAJOR_VERSION >= 18 && ( plugins . length === 0 || plugins . includes ( "rollup4" ) ) ) {
88
+ // We can't import this at the top of the file because they are not
89
+ // compatible with Node v14
90
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
91
+ const rollup4 = require ( "rollup4" ) as typeof rollup3 ;
92
+ void rollup4
41
93
. rollup ( {
42
94
input : entrypoints ,
43
95
plugins : [ sentryRollupPlugin ( sentryUnpluginOptions ) ] ,
@@ -65,7 +117,7 @@ export function createCjsBundles(
65
117
}
66
118
67
119
// Webpack 4 doesn't work on Node.js versions >= 18
68
- if ( parseInt ( nodejsMajorversion ) < 18 && ( plugins . length === 0 || plugins . includes ( "webpack4" ) ) ) {
120
+ if ( NODE_MAJOR_VERSION < 18 && ( plugins . length === 0 || plugins . includes ( "webpack4" ) ) ) {
69
121
webpack4 (
70
122
{
71
123
devtool : "source-map" ,
0 commit comments