Skip to content

Commit 60a5edc

Browse files
committed
Wrap callback in compiler's run method
1 parent 81a1cd8 commit 60a5edc

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

lib/Compiler.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,28 +155,32 @@ class Compiler extends Tapable {
155155
)
156156
);
157157

158+
const finalCallback = (err, stats) => {
159+
this.running = false;
160+
161+
if (callback !== undefined) return callback(err, stats);
162+
};
163+
158164
const startTime = Date.now();
159165

160166
this.running = true;
161167

162168
const onCompiled = (err, compilation) => {
163-
if (err) return callback(err);
169+
if (err) return finalCallback(err);
164170

165171
if (this.hooks.shouldEmit.call(compilation) === false) {
166172
const stats = new Stats(compilation);
167173
stats.startTime = startTime;
168174
stats.endTime = Date.now();
169175
this.hooks.done.callAsync(stats, err => {
170-
this.running = false;
171-
172-
if (err) return callback(err);
173-
return callback(null, stats);
176+
if (err) return finalCallback(err);
177+
return finalCallback(null, stats);
174178
});
175179
return;
176180
}
177181

178182
this.emitAssets(compilation, err => {
179-
if (err) return callback(err);
183+
if (err) return finalCallback(err);
180184

181185
if (compilation.hooks.needAdditionalPass.call()) {
182186
compilation.needAdditionalPass = true;
@@ -185,40 +189,38 @@ class Compiler extends Tapable {
185189
stats.startTime = startTime;
186190
stats.endTime = Date.now();
187191
this.hooks.done.callAsync(stats, err => {
188-
if (err) return callback(err);
192+
if (err) return finalCallback(err);
189193

190194
this.hooks.additionalPass.callAsync(err => {
191-
if (err) return callback(err);
195+
if (err) return finalCallback(err);
192196
this.compile(onCompiled);
193197
});
194198
});
195199
return;
196200
}
197201

198202
this.emitRecords(err => {
199-
if (err) return callback(err);
203+
if (err) return finalCallback(err);
200204

201205
const stats = new Stats(compilation);
202206
stats.startTime = startTime;
203207
stats.endTime = Date.now();
204208
this.hooks.done.callAsync(stats, err => {
205-
this.running = false;
206-
207-
if (err) return callback(err);
208-
return callback(null, stats);
209+
if (err) return finalCallback(err);
210+
return finalCallback(null, stats);
209211
});
210212
});
211213
});
212214
};
213215

214216
this.hooks.beforeRun.callAsync(this, err => {
215-
if (err) return callback(err);
217+
if (err) return finalCallback(err);
216218

217219
this.hooks.run.callAsync(this, err => {
218-
if (err) return callback(err);
220+
if (err) return finalCallback(err);
219221

220222
this.readRecords(err => {
221-
if (err) return callback(err);
223+
if (err) return finalCallback(err);
222224

223225
this.compile(onCompiled);
224226
});

0 commit comments

Comments
 (0)