@@ -7,7 +7,7 @@ const path = require('path');
77const argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ;
88const execa = require ( 'execa' ) ;
99const open = require ( 'open' ) ;
10- const { explore } = require ( 'source-map-explorer' ) ;
10+ const { explore} = require ( 'source-map-explorer' ) ;
1111const pkgJSON = JSON . parse ( fs . readFileSync ( './package.json' ) ) ;
1212
1313function sanitizeString ( str ) {
@@ -37,7 +37,7 @@ function getEntryPoint() {
3737}
3838
3939function getReactNativeBin ( ) {
40- const localBin = './node_modules/.bin/react-native' ;
40+ const localBin = isExpo ? 'node_modules/.bin/expo' : './node_modules/.bin/react-native' ;
4141 if ( fs . existsSync ( localBin ) ) return localBin ;
4242 try {
4343 const reactNativeDir = path . dirname (
@@ -64,9 +64,9 @@ const isExpo = argv.expo || false;
6464const dev = argv . dev || false ;
6565const verbose = argv . verbose || false ;
6666const resetCache = argv [ 'reset-cache' ] || false ;
67- const bundleOutput =
67+ let bundleOutput =
6868 argv [ 'bundle-output' ] || path . join ( tmpDir , platform + '.bundle' ) ;
69- const bundleOutputSourceMap = bundleOutput + '.map' ;
69+ let bundleOutputSourceMap = bundleOutput + '.map' ;
7070const format = argv . format || 'html' ;
7171const bundleOutputExplorerFile = path . join ( outDir , 'explorer.' + format ) ;
7272const onlyMapped = ! ! argv [ 'only-mapped' ] || false ;
@@ -85,8 +85,18 @@ if (fs.existsSync(bundleOutput)) {
8585}
8686
8787// Bundle
88+ const expoOutputDir = path . parse ( bundleOutput ) . dir ;
8889console . log ( chalk . green . bold ( 'Generating bundle...' ) ) ;
89- const commands = [
90+ const commands = isExpo ? [
91+ 'export' ,
92+ '--platform' ,
93+ platform ,
94+ dev && '--dev' ,
95+ '--output-dir' ,
96+ expoOutputDir ,
97+ '--no-bytecode' ,
98+ '--source-maps' ,
99+ ] . filter ( Boolean ) : [
90100 'bundle' ,
91101 '--platform' ,
92102 platform ,
@@ -102,8 +112,12 @@ const commands = [
102112 isExpo ,
103113] ;
104114if ( resetCache ) {
105- commands . push ( '--reset-cache' ) ;
106- commands . push ( resetCache ) ;
115+ if ( isExpo ) {
116+ commands . push ( '--clear' ) ;
117+ } else {
118+ commands . push ( '--reset-cache' ) ;
119+ commands . push ( resetCache ) ;
120+ }
107121}
108122
109123const reactNativeBin = getReactNativeBin ( ) ;
@@ -114,6 +128,12 @@ bundlePromise.stdout.pipe(process.stdout);
114128bundlePromise
115129 . then (
116130 ( ) => {
131+ if ( isExpo ) {
132+ const jsFolder = `${ expoOutputDir } /_expo/static/js/${ platform } ` ;
133+ const files = fs . readdirSync ( `${ expoOutputDir } /_expo/static/js/${ platform } ` ) ;
134+ bundleOutput = jsFolder + '/' + files . find ( ( file ) => file . endsWith ( '.js' ) ) ;
135+ bundleOutputSourceMap = jsFolder + '/' + files . find ( ( file ) => file . endsWith ( '.js.map' ) ) ;
136+ }
117137 // Log bundle-size
118138 const stats = fs . statSync ( bundleOutput ) ;
119139
@@ -136,8 +156,8 @@ bundlePromise
136156 console . log (
137157 chalk . green . bold (
138158 'Bundle is ' +
139- Math . round ( ( stats . size / ( 1024 * 1024 ) ) * 100 ) / 100 +
140- ' MB in size'
159+ Math . round ( ( stats . size / ( 1024 * 1024 ) ) * 100 ) / 100 +
160+ ' MB in size'
141161 ) + deltaSuffix
142162 ) ;
143163
@@ -183,7 +203,9 @@ bundlePromise
183203 } ) ;
184204 }
185205
186- // Open output file
206+ console . log (
207+ chalk . green . bold ( 'Opening bundle visualizer output file: ' + bundleOutputExplorerFile )
208+ )
187209 return open ( bundleOutputExplorerFile ) ;
188210 } )
189211 . catch ( ( error ) => {
0 commit comments