33 */
44
55import { builtinModules } from 'module' ;
6-
6+ import path from 'node:path' ;
7+ import fs from 'node:fs' ;
78import deepMerge from 'deepmerge' ;
89
910import {
1011 makeBrowserBuildPlugin ,
11- makeCleanupPlugin ,
1212 makeIsDebugBuildPlugin ,
13- makeLicensePlugin ,
1413 makeRrwebBuildPlugin ,
1514 makeSetSDKSourcePlugin ,
16- makeSucrasePlugin ,
15+ makeBannerOptions ,
1716 makeTerserPlugin ,
1817} from './plugins/index.mjs' ;
1918import { mergePlugins } from './utils.mjs' ;
20- import { makeProductionReplacePlugin } from './plugins/npmPlugins.mjs' ;
2119
2220const BUNDLE_VARIANTS = [ '.js' , '.min.js' , '.debug.min.js' ] ;
2321
22+ const packageDotJSON = JSON . parse ( fs . readFileSync ( path . resolve ( process . cwd ( ) , './package.json' ) , { encoding : 'utf8' } ) ) ;
23+
2424export function makeBaseBundleConfig ( options ) {
25- const { bundleType, entrypoints, licenseTitle, outputFileBase, packageSpecificConfig, sucrase } = options ;
25+ const { bundleType, entrypoints, licenseTitle, outputFileBase, packageSpecificConfig } = options ;
2626
27- const sucrasePlugin = makeSucrasePlugin ( { } , sucrase ) ;
28- const cleanupPlugin = makeCleanupPlugin ( ) ;
2927 const markAsBrowserBuildPlugin = makeBrowserBuildPlugin ( true ) ;
30- const licensePlugin = makeLicensePlugin ( licenseTitle ) ;
28+ const banner = makeBannerOptions ( licenseTitle , packageDotJSON . version ) ;
3129 const rrwebBuildPlugin = makeRrwebBuildPlugin ( {
3230 excludeIframe : false ,
3331 excludeShadowDom : false ,
3432 } ) ;
35- const productionReplacePlugin = makeProductionReplacePlugin ( ) ;
3633
3734 // used by `@sentry/browser`
3835 const standAloneBundleConfig = {
3936 output : {
37+ banner,
4038 format : 'iife' ,
4139 name : 'Sentry' ,
4240 intro : ( ) => {
4341 return 'exports = window.Sentry || {};' ;
4442 } ,
4543 } ,
4644 context : 'window' ,
47- plugins : [ rrwebBuildPlugin , markAsBrowserBuildPlugin , licensePlugin ] ,
45+ plugins : [ rrwebBuildPlugin , markAsBrowserBuildPlugin ] ,
4846 } ;
4947
5048 // used by `@sentry/wasm` & pluggable integrations from core/browser (bundles which need to be combined with a stand-alone SDK bundle)
@@ -55,7 +53,7 @@ export function makeBaseBundleConfig(options) {
5553 format : 'cjs' ,
5654
5755 // code to add before the CJS wrapper
58- banner : ' (function (__window) {' ,
56+ banner : ` ${ banner } \n (function (__window) {` ,
5957
6058 // code to add just inside the CJS wrapper, before any of the wrapped code
6159 intro : 'var exports = {};' ,
@@ -78,14 +76,15 @@ export function makeBaseBundleConfig(options) {
7876 // code to add after the CJS wrapper
7977 footer : '}(window));' ,
8078 } ,
81- plugins : [ rrwebBuildPlugin , markAsBrowserBuildPlugin , licensePlugin ] ,
79+ plugins : [ rrwebBuildPlugin , markAsBrowserBuildPlugin ] ,
8280 } ;
8381
8482 const workerBundleConfig = {
8583 output : {
84+ banner,
8685 format : 'esm' ,
8786 } ,
88- plugins : [ makeTerserPlugin ( ) , licensePlugin ] ,
87+ plugins : [ makeTerserPlugin ( ) ] ,
8988 // Don't bundle any of Node's core modules
9089 external : builtinModules ,
9190 } ;
@@ -110,7 +109,6 @@ export function makeBaseBundleConfig(options) {
110109 strict : false ,
111110 esModule : false ,
112111 } ,
113- plugins : [ sucrasePlugin , cleanupPlugin ] ,
114112 treeshake : 'smallest' ,
115113 } ;
116114
@@ -144,25 +142,35 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
144142 const terserPlugin = makeTerserPlugin ( ) ;
145143 const setSdkSourcePlugin = makeSetSDKSourcePlugin ( 'cdn' ) ;
146144
145+ const baseOutput = baseConfig . output ;
146+ if ( ! baseOutput || Array . isArray ( baseOutput ) ) {
147+ throw new Error ( 'Base config must have a single output object' ) ;
148+ }
149+
150+ const baseOutputEntryFileNames = baseOutput . entryFileNames ;
151+ if ( typeof baseOutputEntryFileNames !== 'function' ) {
152+ throw new Error ( 'Base config must have a function for entryFileNames' ) ;
153+ }
154+
147155 // The additional options to use for each variant we're going to create.
148156 const variantSpecificConfigMap = {
149157 '.js' : {
150158 output : {
151- entryFileNames : chunkInfo => `${ baseConfig . output . entryFileNames ( chunkInfo ) } .js` ,
159+ entryFileNames : chunkInfo => `${ baseOutputEntryFileNames ( chunkInfo ) } .js` ,
152160 } ,
153161 plugins : [ includeDebuggingPlugin , setSdkSourcePlugin ] ,
154162 } ,
155163
156164 '.min.js' : {
157165 output : {
158- entryFileNames : chunkInfo => `${ baseConfig . output . entryFileNames ( chunkInfo ) } .min.js` ,
166+ entryFileNames : chunkInfo => `${ baseOutputEntryFileNames ( chunkInfo ) } .min.js` ,
159167 } ,
160168 plugins : [ stripDebuggingPlugin , setSdkSourcePlugin , terserPlugin ] ,
161169 } ,
162170
163171 '.debug.min.js' : {
164172 output : {
165- entryFileNames : chunkInfo => `${ baseConfig . output . entryFileNames ( chunkInfo ) } .debug.min.js` ,
173+ entryFileNames : chunkInfo => `${ baseOutputEntryFileNames ( chunkInfo ) } .debug.min.js` ,
166174 } ,
167175 plugins : [ includeDebuggingPlugin , setSdkSourcePlugin , terserPlugin ] ,
168176 } ,
@@ -172,10 +180,12 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
172180 if ( ! BUNDLE_VARIANTS . includes ( variant ) ) {
173181 throw new Error ( `Unknown bundle variant requested: ${ variant } ` ) ;
174182 }
183+
175184 return deepMerge ( baseConfig , variantSpecificConfigMap [ variant ] , {
176185 // Merge the plugin arrays and make sure the end result is in the correct order. Everything else can use the
177186 // default merge strategy.
178187 customMerge : key => ( key === 'plugins' ? mergePlugins : undefined ) ,
179188 } ) ;
180189 } ) ;
181190}
191+
0 commit comments