@@ -21,69 +21,56 @@ function saveBundle(output, bundle, args) {
2121}
2222
2323function buildBundle ( args , config , output = outputBundle , packagerInstance ) {
24- return new Promise ( ( resolve , reject ) => {
24+ // This is used by a bazillion of npm modules we don't control so we don't
25+ // have other choice than defining it as an env variable here.
26+ process . env . NODE_ENV = args . dev ? 'development' : 'production' ;
2527
26- // This is used by a bazillion of npm modules we don't control so we don't
27- // have other choice than defining it as an env variable here.
28- if ( ! process . env . NODE_ENV ) {
29- // If you're inlining environment variables, you can use babel to remove
30- // this line:
31- // https://www.npmjs.com/package/babel-remove-process-env-assignment
32- process . env . NODE_ENV = args . dev ? 'development' : 'production' ;
33- }
28+ const options = {
29+ projectRoots : config . getProjectRoots ( ) ,
30+ assetRoots : config . getAssetRoots ( ) ,
31+ blacklistRE : config . getBlacklistRE ( args . platform ) ,
32+ getTransformOptionsModulePath : config . getTransformOptionsModulePath ,
33+ transformModulePath : args . transformer ,
34+ extraNodeModules : config . extraNodeModules ,
35+ nonPersistent : true ,
36+ resetCache : args . resetCache ,
37+ } ;
3438
35- const transformModulePath =
36- args . transformer ? path . resolve ( args . transformer ) :
37- typeof config . getTransformModulePath === 'function' ? config . getTransformModulePath ( ) :
38- undefined ;
39+ const requestOpts = {
40+ entryFile : args . entryFile ,
41+ sourceMapUrl : args . sourcemapOutput ,
42+ dev : args . dev ,
43+ minify : ! args . dev ,
44+ platform : args . platform ,
45+ } ;
3946
40- const options = {
41- projectRoots : config . getProjectRoots ( ) ,
42- assetRoots : config . getAssetRoots ( ) ,
43- blacklistRE : config . getBlacklistRE ( args . platform ) ,
44- getTransformOptionsModulePath : config . getTransformOptionsModulePath ,
45- transformModulePath : transformModulePath ,
46- extraNodeModules : config . extraNodeModules ,
47- nonPersistent : true ,
48- resetCache : args [ 'reset-cache' ] ,
49- } ;
47+ // If a packager instance was not provided, then just create one for this
48+ // bundle command and close it down afterwards.
49+ var shouldClosePackager = false ;
50+ if ( ! packagerInstance ) {
51+ packagerInstance = new Server ( options ) ;
52+ shouldClosePackager = true ;
53+ }
5054
51- const requestOpts = {
52- entryFile : args [ 'entry-file' ] ,
53- sourceMapUrl : args [ 'sourcemap-output' ] ,
54- dev : args . dev ,
55- minify : ! args . dev ,
56- platform : args . platform ,
57- } ;
55+ const bundlePromise = output . build ( packagerInstance , requestOpts )
56+ . then ( bundle => {
57+ if ( shouldClosePackager ) {
58+ packagerInstance . end ( ) ;
59+ }
60+ return saveBundle ( output , bundle , args ) ;
61+ } ) ;
5862
59- // If a packager instance was not provided, then just create one for this
60- // bundle command and close it down afterwards.
61- var shouldClosePackager = false ;
62- if ( ! packagerInstance ) {
63- packagerInstance = new Server ( options ) ;
64- shouldClosePackager = true ;
65- }
63+ // Save the assets of the bundle
64+ const assets = bundlePromise
65+ . then ( bundle => bundle . getAssets ( ) )
66+ . then ( outputAssets => saveAssets (
67+ outputAssets ,
68+ args . platform ,
69+ args . assetsDest ,
70+ ) ) ;
6671
67- const bundlePromise = output . build ( packagerInstance , requestOpts )
68- . then ( bundle => {
69- if ( shouldClosePackager ) {
70- packagerInstance . end ( ) ;
71- }
72- return saveBundle ( output , bundle , args ) ;
73- } ) ;
74-
75- // Save the assets of the bundle
76- const assets = bundlePromise
77- . then ( bundle => bundle . getAssets ( ) )
78- . then ( outputAssets => saveAssets (
79- outputAssets ,
80- args . platform ,
81- args [ 'assets-dest' ]
82- ) ) ;
83-
84- // When we're done saving bundle output and the assets, we're done.
85- resolve ( assets ) ;
86- } ) ;
72+ // When we're done saving bundle output and the assets, we're done.
73+ return assets ;
8774}
8875
8976module . exports = buildBundle ;
0 commit comments