@@ -123,9 +123,7 @@ class Profiler {
123123 * @returns {Trace } The trace object
124124 */
125125const 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
347345const 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,
0 commit comments