diff --git a/src/generator/context.ts b/src/generator/context.ts index 5963157..97f8120 100644 --- a/src/generator/context.ts +++ b/src/generator/context.ts @@ -28,6 +28,9 @@ export const run = async ( }), ); + const end = (stream: Writable) => + new Promise((resolve) => stream.end(() => resolve())); + const deferredWrites: string[] = []; // NOTE: if we're running in a nested context, we want to lift deferred @@ -50,10 +53,12 @@ export const run = async ( // NOTE: in order to avoid the output being dependent on the write order, // deferred writes are sorted before written to the output await write(deferredWrites.sort().join("\n"), buffer); + await end(buffer); + await pipeline(buffer, output, { end: false }); } - await new Promise((resolve) => output.end(() => resolve())); + await end(output); return result; };