@@ -14,7 +14,8 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
14
14
public $hostInfo : IHostInfo ,
15
15
private $logger : ILogger ,
16
16
private $pluginsService : IPluginsService ,
17
- private $mobileHelper : Mobile . IMobileHelper
17
+ private $mobileHelper : Mobile . IMobileHelper ,
18
+ private $cleanupService : ICleanupService
18
19
) { super ( ) ; }
19
20
20
21
public async compileWithWatch ( platformData : IPlatformData , projectData : IProjectData , prepareData : IPrepareData ) : Promise < any > {
@@ -70,15 +71,19 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
70
71
}
71
72
} ) ;
72
73
73
- childProcess . on ( "close" , ( arg : any ) => {
74
+ childProcess . on ( "error" , ( err ) => {
75
+ this . $logger . trace ( `Unable to start webpack process in watch mode. Error is: ${ err } ` ) ;
76
+ reject ( err ) ;
77
+ } ) ;
78
+
79
+ childProcess . on ( "close" , async ( arg : any ) => {
80
+ await this . $cleanupService . removeKillProcess ( childProcess . pid . toString ( ) ) ;
81
+
74
82
const exitCode = typeof arg === "number" ? arg : arg && arg . code ;
75
- if ( exitCode === 0 ) {
76
- resolve ( childProcess ) ;
77
- } else {
78
- const error = new Error ( `Executing webpack failed with exit code ${ exitCode } .` ) ;
79
- error . code = exitCode ;
80
- reject ( error ) ;
81
- }
83
+ this . $logger . trace ( `Webpack process exited with code ${ exitCode } when we expected it to be long living with watch.` ) ;
84
+ const error = new Error ( `Executing webpack failed with exit code ${ exitCode } .` ) ;
85
+ error . code = exitCode ;
86
+ reject ( error ) ;
82
87
} ) ;
83
88
} ) ;
84
89
}
@@ -91,7 +96,14 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
91
96
}
92
97
93
98
const childProcess = await this . startWebpackProcess ( platformData , projectData , prepareData ) ;
94
- childProcess . on ( "close" , ( arg : any ) => {
99
+ childProcess . on ( "error" , ( err ) => {
100
+ this . $logger . trace ( `Unable to start webpack process in non-watch mode. Error is: ${ err } ` ) ;
101
+ reject ( err ) ;
102
+ } ) ;
103
+
104
+ childProcess . on ( "close" , async ( arg : any ) => {
105
+ await this . $cleanupService . removeKillProcess ( childProcess . pid . toString ( ) ) ;
106
+
95
107
const exitCode = typeof arg === "number" ? arg : arg && arg . code ;
96
108
if ( exitCode === 0 ) {
97
109
resolve ( ) ;
@@ -104,11 +116,15 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
104
116
} ) ;
105
117
}
106
118
107
- public stopWebpackCompiler ( platform : string ) : void {
119
+ public async stopWebpackCompiler ( platform : string ) : Promise < void > {
108
120
if ( platform ) {
109
- this . stopWebpackForPlatform ( platform ) ;
121
+ await this . stopWebpackForPlatform ( platform ) ;
110
122
} else {
111
- Object . keys ( this . webpackProcesses ) . forEach ( pl => this . stopWebpackForPlatform ( pl ) ) ;
123
+ const webpackedPlatforms = Object . keys ( this . webpackProcesses ) ;
124
+
125
+ for ( let i = 0 ; i < webpackedPlatforms . length ; i ++ ) {
126
+ await this . stopWebpackForPlatform ( webpackedPlatforms [ i ] ) ;
127
+ }
112
128
}
113
129
}
114
130
@@ -136,9 +152,10 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
136
152
}
137
153
138
154
const stdio = prepareData . watch ? [ "inherit" , "inherit" , "inherit" , "ipc" ] : "inherit" ;
139
- const childProcess = this . $childProcess . spawn ( "node" , args , { cwd : projectData . projectDir , stdio } ) ;
155
+ const childProcess = this . $childProcess . spawn ( process . execPath , args , { cwd : projectData . projectDir , stdio } ) ;
140
156
141
157
this . webpackProcesses [ platformData . platformNameLowerCase ] = childProcess ;
158
+ await this . $cleanupService . addKillProcess ( childProcess . pid . toString ( ) ) ;
142
159
143
160
return childProcess ;
144
161
}
@@ -233,9 +250,10 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
233
250
} ;
234
251
}
235
252
236
- private stopWebpackForPlatform ( platform : string ) {
253
+ private async stopWebpackForPlatform ( platform : string ) {
237
254
this . $logger . trace ( `Stopping webpack watch for platform ${ platform } .` ) ;
238
255
const webpackProcess = this . webpackProcesses [ platform ] ;
256
+ await this . $cleanupService . removeKillProcess ( webpackProcess . pid . toString ( ) ) ;
239
257
if ( webpackProcess ) {
240
258
webpackProcess . kill ( "SIGINT" ) ;
241
259
delete this . webpackProcesses [ platform ] ;
0 commit comments