Skip to content

Commit af8de03

Browse files
committed
Transform done hook into async
1 parent c963e3d commit af8de03

2 files changed

Lines changed: 30 additions & 20 deletions

File tree

‎lib/Compiler.js‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Compiler extends Tapable {
2828
super();
2929
this.hooks = {
3030
shouldEmit: new SyncBailHook(["compilation"]),
31-
done: new SyncHook(["stats"]),
31+
done: new AsyncSeriesHook(["stats"]),
3232
additionalPass: new AsyncSeriesHook([]),
3333
beforeRun: new AsyncSeriesHook(["compilation"]),
3434
run: new AsyncSeriesHook(["compilation"]),
@@ -171,8 +171,11 @@ class Compiler extends Tapable {
171171
const stats = new Stats(compilation);
172172
stats.startTime = startTime;
173173
stats.endTime = Date.now();
174-
this.hooks.done.call(stats);
175-
return callback(null, stats);
174+
this.hooks.done.callAsync(stats, err => {
175+
if(err) return callback(err);
176+
return callback(null, stats);
177+
});
178+
return;
176179
}
177180

178181
this.emitAssets(compilation, err => {
@@ -184,11 +187,13 @@ class Compiler extends Tapable {
184187
const stats = new Stats(compilation);
185188
stats.startTime = startTime;
186189
stats.endTime = Date.now();
187-
this.hooks.done.call(stats);
188-
189-
this.hooks.additionalPass.callAsync(err => {
190+
this.hooks.done.callAsync(stats, err => {
190191
if(err) return callback(err);
191-
this.compile(onCompiled);
192+
193+
this.hooks.additionalPass.callAsync(err => {
194+
if(err) return callback(err);
195+
this.compile(onCompiled);
196+
});
192197
});
193198
return;
194199
}
@@ -199,8 +204,10 @@ class Compiler extends Tapable {
199204
const stats = new Stats(compilation);
200205
stats.startTime = startTime;
201206
stats.endTime = Date.now();
202-
this.hooks.done.call(stats);
203-
return callback(null, stats);
207+
this.hooks.done.callAsync(stats, err => {
208+
if(err) return callback(err);
209+
return callback(null, stats);
210+
});
204211
});
205212
});
206213
};

‎lib/Watching.js‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ class Watching {
5959
const stats = new Stats(compilation);
6060
stats.startTime = this.startTime;
6161
stats.endTime = Date.now();
62-
this.compiler.hooks.done.call(stats);
63-
64-
this.compiler.hooks.additionalPass.callAsync(err => {
62+
this.compiler.hooks.done.callAsync(stats, err => {
6563
if(err) return this._done(err);
66-
this.compiler.compile(onCompiled);
64+
65+
this.compiler.hooks.additionalPass.callAsync(err => {
66+
if(err) return this._done(err);
67+
this.compiler.compile(onCompiled);
68+
});
6769
});
6870
return;
6971
}
@@ -93,13 +95,14 @@ class Watching {
9395
return;
9496
}
9597

96-
this.compiler.hooks.done.call(stats);
97-
this.handler(null, stats);
98-
if(!this.closed) {
99-
this.watch(Array.from(compilation.fileDependencies), Array.from(compilation.contextDependencies), Array.from(compilation.missingDependencies));
100-
}
101-
for(const cb of this.callbacks) cb();
102-
this.callbacks.length = 0;
98+
this.compiler.hooks.done.callAsync(stats, () => {
99+
this.handler(null, stats);
100+
if(!this.closed) {
101+
this.watch(Array.from(compilation.fileDependencies), Array.from(compilation.contextDependencies), Array.from(compilation.missingDependencies));
102+
}
103+
for(const cb of this.callbacks) cb();
104+
this.callbacks.length = 0;
105+
});
103106
}
104107

105108
watch(files, dirs, missing) {

0 commit comments

Comments
 (0)