1- import * as child_process from "child_process" ;
21import * as choki from "chokidar" ;
32import { hook } from "../common/helpers" ;
43import { performanceLog } from "../common/decorators" ;
@@ -7,7 +6,7 @@ import * as path from "path";
76import { PREPARE_READY_EVENT_NAME , WEBPACK_COMPILATION_COMPLETE , PACKAGE_JSON_FILE_NAME , PLATFORMS_DIR_NAME } from "../constants" ;
87
98interface IPlatformWatcherData {
10- webpackCompilerProcess : child_process . ChildProcess ;
9+ hasWebpackCompilerProcess : boolean ;
1110 nativeFilesWatcher : choki . FSWatcher ;
1211}
1312
@@ -63,9 +62,9 @@ export class PrepareController extends EventEmitter {
6362 this . watchersData [ projectDir ] [ platformLowerCase ] . nativeFilesWatcher = null ;
6463 }
6564
66- if ( this . watchersData && this . watchersData [ projectDir ] && this . watchersData [ projectDir ] [ platformLowerCase ] && this . watchersData [ projectDir ] [ platformLowerCase ] . webpackCompilerProcess ) {
65+ if ( this . watchersData && this . watchersData [ projectDir ] && this . watchersData [ projectDir ] [ platformLowerCase ] && this . watchersData [ projectDir ] [ platformLowerCase ] . hasWebpackCompilerProcess ) {
6766 await this . $webpackCompilerService . stopWebpackCompiler ( platform ) ;
68- this . watchersData [ projectDir ] [ platformLowerCase ] . webpackCompilerProcess = null ;
67+ this . watchersData [ projectDir ] [ platformLowerCase ] . hasWebpackCompilerProcess = false ;
6968 }
7069 }
7170
@@ -78,38 +77,39 @@ export class PrepareController extends EventEmitter {
7877 if ( ! this . watchersData [ projectData . projectDir ] [ platformData . platformNameLowerCase ] ) {
7978 this . watchersData [ projectData . projectDir ] [ platformData . platformNameLowerCase ] = {
8079 nativeFilesWatcher : null ,
81- webpackCompilerProcess : null
80+ hasWebpackCompilerProcess : false
8281 } ;
83- await this . startJSWatcherWithPrepare ( platformData , projectData , prepareData ) ; // -> start watcher + initial compilation
84- const hasNativeChanges = await this . startNativeWatcherWithPrepare ( platformData , projectData , prepareData ) ; // -> start watcher + initial prepare
85- const result = { platform : platformData . platformNameLowerCase , hasNativeChanges } ;
82+ }
8683
87- const hasPersistedDataWithNativeChanges = this . persistedData . find ( data => data . platform === result . platform && data . hasNativeChanges ) ;
88- if ( hasPersistedDataWithNativeChanges ) {
89- result . hasNativeChanges = true ;
90- }
84+ await this . startJSWatcherWithPrepare ( platformData , projectData , prepareData ) ; // -> start watcher + initial compilation
85+ const hasNativeChanges = await this . startNativeWatcherWithPrepare ( platformData , projectData , prepareData ) ; // -> start watcher + initial prepare
86+ const result = { platform : platformData . platformNameLowerCase , hasNativeChanges } ;
9187
92- // TODO: Do not persist this in `this` context. Also it should be per platform.
93- this . isInitialPrepareReady = true ;
88+ const hasPersistedDataWithNativeChanges = this . persistedData . find ( data => data . platform === result . platform && data . hasNativeChanges ) ;
89+ if ( hasPersistedDataWithNativeChanges ) {
90+ result . hasNativeChanges = true ;
91+ }
9492
95- if ( this . persistedData && this . persistedData . length ) {
96- this . emitPrepareEvent ( { files : [ ] , hasOnlyHotUpdateFiles : false , hasNativeChanges : result . hasNativeChanges , hmrData : null , platform : platformData . platformNameLowerCase } ) ;
97- }
93+ // TODO: Do not persist this in `this` context. Also it should be per platform.
94+ this . isInitialPrepareReady = true ;
9895
99- return result ;
96+ if ( this . persistedData && this . persistedData . length ) {
97+ this . emitPrepareEvent ( { files : [ ] , hasOnlyHotUpdateFiles : false , hasNativeChanges : result . hasNativeChanges , hmrData : null , platform : platformData . platformNameLowerCase } ) ;
10098 }
99+
100+ return result ;
101101 }
102102
103103 private async startJSWatcherWithPrepare ( platformData : IPlatformData , projectData : IProjectData , prepareData : IPrepareData ) : Promise < void > {
104- if ( ! this . watchersData [ projectData . projectDir ] [ platformData . platformNameLowerCase ] . webpackCompilerProcess ) {
104+ if ( ! this . watchersData [ projectData . projectDir ] [ platformData . platformNameLowerCase ] . hasWebpackCompilerProcess ) {
105105 this . $webpackCompilerService . on ( WEBPACK_COMPILATION_COMPLETE , data => {
106106 if ( data . platform . toLowerCase ( ) === platformData . platformNameLowerCase ) {
107107 this . emitPrepareEvent ( { ...data , hasNativeChanges : false } ) ;
108108 }
109109 } ) ;
110110
111- const childProcess = await this . $webpackCompilerService . compileWithWatch ( platformData , projectData , prepareData ) ;
112- this . watchersData [ projectData . projectDir ] [ platformData . platformNameLowerCase ] . webpackCompilerProcess = childProcess ;
111+ this . watchersData [ projectData . projectDir ] [ platformData . platformNameLowerCase ] . hasWebpackCompilerProcess = true ;
112+ await this . $webpackCompilerService . compileWithWatch ( platformData , projectData , prepareData ) ;
113113 }
114114 }
115115
0 commit comments