1
- import * as child_process from "child_process" ;
2
1
import * as choki from "chokidar" ;
3
2
import { hook } from "../common/helpers" ;
4
3
import { performanceLog } from "../common/decorators" ;
@@ -7,7 +6,7 @@ import * as path from "path";
7
6
import { PREPARE_READY_EVENT_NAME , WEBPACK_COMPILATION_COMPLETE , PACKAGE_JSON_FILE_NAME , PLATFORMS_DIR_NAME } from "../constants" ;
8
7
9
8
interface IPlatformWatcherData {
10
- webpackCompilerProcess : child_process . ChildProcess ;
9
+ hasWebpackCompilerProcess : boolean ;
11
10
nativeFilesWatcher : choki . FSWatcher ;
12
11
}
13
12
@@ -63,9 +62,9 @@ export class PrepareController extends EventEmitter {
63
62
this . watchersData [ projectDir ] [ platformLowerCase ] . nativeFilesWatcher = null ;
64
63
}
65
64
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 ) {
67
66
await this . $webpackCompilerService . stopWebpackCompiler ( platform ) ;
68
- this . watchersData [ projectDir ] [ platformLowerCase ] . webpackCompilerProcess = null ;
67
+ this . watchersData [ projectDir ] [ platformLowerCase ] . hasWebpackCompilerProcess = false ;
69
68
}
70
69
}
71
70
@@ -78,38 +77,39 @@ export class PrepareController extends EventEmitter {
78
77
if ( ! this . watchersData [ projectData . projectDir ] [ platformData . platformNameLowerCase ] ) {
79
78
this . watchersData [ projectData . projectDir ] [ platformData . platformNameLowerCase ] = {
80
79
nativeFilesWatcher : null ,
81
- webpackCompilerProcess : null
80
+ hasWebpackCompilerProcess : false
82
81
} ;
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
+ }
86
83
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 } ;
91
87
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
+ }
94
92
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 ;
98
95
99
- return result ;
96
+ if ( this . persistedData && this . persistedData . length ) {
97
+ this . emitPrepareEvent ( { files : [ ] , hasOnlyHotUpdateFiles : false , hasNativeChanges : result . hasNativeChanges , hmrData : null , platform : platformData . platformNameLowerCase } ) ;
100
98
}
99
+
100
+ return result ;
101
101
}
102
102
103
103
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 ) {
105
105
this . $webpackCompilerService . on ( WEBPACK_COMPILATION_COMPLETE , data => {
106
106
if ( data . platform . toLowerCase ( ) === platformData . platformNameLowerCase ) {
107
107
this . emitPrepareEvent ( { ...data , hasNativeChanges : false } ) ;
108
108
}
109
109
} ) ;
110
110
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 ) ;
113
113
}
114
114
}
115
115
0 commit comments