Skip to content

Commit bc80a83

Browse files
authored
Merge pull request #15157 from markjm/markjm/watch-mode-profile-plugin
Fix ProfilingPlugin for watch scenarios
2 parents 508877c + 822c3b3 commit bc80a83

6 files changed

Lines changed: 28 additions & 11 deletions

File tree

lib/debug/ProfilingPlugin.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ class Profiler {
123123
* @returns {Trace} The trace object
124124
*/
125125
const createTrace = (fs, outputPath) => {
126-
const trace = new Tracer({
127-
noStream: true
128-
});
126+
const trace = new Tracer();
129127
const profiler = new Profiler(inspector);
130128
if (/\/|\\/.test(outputPath)) {
131129
const dirPath = dirname(fs, outputPath);
@@ -173,6 +171,7 @@ const createTrace = (fs, outputPath) => {
173171
counter,
174172
profiler,
175173
end: callback => {
174+
trace.push("]");
176175
// Wait until the write stream finishes.
177176
fsStream.on("close", () => {
178177
callback();
@@ -242,10 +241,10 @@ class ProfilingPlugin {
242241
stage: Infinity
243242
},
244243
(stats, callback) => {
244+
if (compiler.watchMode) return callback();
245245
tracer.profiler.stopProfiling().then(parsedResults => {
246246
if (parsedResults === undefined) {
247247
tracer.profiler.destroy();
248-
tracer.trace.flush();
249248
tracer.end(callback);
250249
return;
251250
}
@@ -293,7 +292,6 @@ class ProfilingPlugin {
293292
});
294293

295294
tracer.profiler.destroy();
296-
tracer.trace.flush();
297295
tracer.end(callback);
298296
});
299297
}
@@ -346,11 +344,15 @@ const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => {
346344

347345
const makeInterceptorFor = (instance, tracer) => hookName => ({
348346
register: ({ name, type, context, fn }) => {
349-
const newFn = makeNewProfiledTapFn(hookName, tracer, {
350-
name,
351-
type,
352-
fn
353-
});
347+
const newFn =
348+
// Don't tap our own hooks to ensure stream can close cleanly
349+
name === pluginName
350+
? fn
351+
: makeNewProfiledTapFn(hookName, tracer, {
352+
name,
353+
type,
354+
fn
355+
});
354356
return {
355357
name,
356358
type,

test/WatchTestCases.template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ const describeCases = config => {
396396
done
397397
)
398398
) {
399-
compiler.close();
399+
compiler.close(() => {});
400400
return;
401401
}
402402
compiler.close(done);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("compiles", function() {
2+
expect(WATCH_STEP).toBe("0");
3+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should not crash on recompile", function() {
2+
expect(WATCH_STEP).toBe("1");
3+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [
2+
{ code: /DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK/ }
3+
];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var webpack = require("../../../../");
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {
5+
plugins: [new webpack.debug.ProfilingPlugin()]
6+
};

0 commit comments

Comments
 (0)