@@ -6,7 +6,7 @@ const archiver = require('archiver');
66const { execSync} = require ( 'child_process' ) ;
77const { readFileSync, writeFileSync, createWriteStream} = require ( 'fs' ) ;
88const { copy, ensureDir, move, remove, pathExistsSync} = require ( 'fs-extra' ) ;
9- const { join, resolve} = require ( 'path' ) ;
9+ const { join, resolve, basename } = require ( 'path' ) ;
1010const { getGitCommit} = require ( './utils' ) ;
1111
1212// These files are copied along with Webpack-bundled files
@@ -80,8 +80,25 @@ const build = async (tempPath, manifestPath, envExtension = {}) => {
8080
8181 const copiedManifestPath = join ( zipPath , 'manifest.json' ) ;
8282
83+ let webpackStatsFilePath = null ;
8384 // Copy unbuilt source files to zip dir to be packaged:
84- await copy ( binPath , join ( zipPath , 'build' ) ) ;
85+ await copy ( binPath , join ( zipPath , 'build' ) , {
86+ filter : filePath => {
87+ if ( basename ( filePath ) . startsWith ( 'webpack-stats.' ) ) {
88+ webpackStatsFilePath = filePath ;
89+ // The ZIP is the actual extension and doesn't need this metadata.
90+ return false ;
91+ }
92+ return true ;
93+ } ,
94+ } ) ;
95+ if ( webpackStatsFilePath !== null ) {
96+ await copy (
97+ webpackStatsFilePath ,
98+ join ( tempPath , basename ( webpackStatsFilePath ) ) ,
99+ ) ;
100+ webpackStatsFilePath = join ( tempPath , basename ( webpackStatsFilePath ) ) ;
101+ }
85102 await copy ( manifestPath , copiedManifestPath ) ;
86103 await Promise . all (
87104 STATIC_FILES . map ( file => copy ( join ( __dirname , file ) , join ( zipPath , file ) ) ) ,
@@ -120,16 +137,26 @@ const build = async (tempPath, manifestPath, envExtension = {}) => {
120137 archive . finalize ( ) ;
121138 zipStream . on ( 'close' , ( ) => resolvePromise ( ) ) ;
122139 } ) ;
140+
141+ return webpackStatsFilePath ;
123142} ;
124143
125- const postProcess = async ( tempPath , destinationPath ) => {
144+ const postProcess = async ( tempPath , destinationPath , webpackStatsFilePath ) => {
126145 const unpackedSourcePath = join ( tempPath , 'zip' ) ;
127146 const packedSourcePath = join ( tempPath , 'ReactDevTools.zip' ) ;
128147 const packedDestPath = join ( destinationPath , 'ReactDevTools.zip' ) ;
129148 const unpackedDestPath = join ( destinationPath , 'unpacked' ) ;
130149
131150 await move ( unpackedSourcePath , unpackedDestPath ) ; // Copy built files to destination
132151 await move ( packedSourcePath , packedDestPath ) ; // Copy built files to destination
152+ if ( webpackStatsFilePath !== null ) {
153+ await move (
154+ webpackStatsFilePath ,
155+ join ( destinationPath , basename ( webpackStatsFilePath ) ) ,
156+ ) ;
157+ } else {
158+ console . log ( 'No webpack-stats.json file was generated.' ) ;
159+ }
133160 await remove ( tempPath ) ; // Clean up temp directory and files
134161} ;
135162
@@ -158,10 +185,14 @@ const main = async buildId => {
158185 const tempPath = join ( __dirname , 'build' , buildId ) ;
159186 await ensureLocalBuild ( ) ;
160187 await preProcess ( destinationPath , tempPath ) ;
161- await build ( tempPath , manifestPath , envExtension ) ;
188+ const webpackStatsFilePath = await build (
189+ tempPath ,
190+ manifestPath ,
191+ envExtension ,
192+ ) ;
162193
163194 const builtUnpackedPath = join ( destinationPath , 'unpacked' ) ;
164- await postProcess ( tempPath , destinationPath ) ;
195+ await postProcess ( tempPath , destinationPath , webpackStatsFilePath ) ;
165196
166197 return builtUnpackedPath ;
167198 } catch ( error ) {
0 commit comments