Skip to content

Commit

Permalink
refactor(internal): Prefer fs.WriteStream close() over stream.Writabl…
Browse files Browse the repository at this point in the history
…e end()
  • Loading branch information
gibson042 authored and mujahidkay committed Mar 3, 2025
1 parent ff29903 commit 77b835b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/internal/src/node/fs-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ export const makeFsStreamWriter = async filePath => {
})();
await fsStreamReady(stream);
const writeAsync = promisify(stream.write.bind(stream));
const endAsync = useStdout
? undefined
: stream.end && promisify(stream.end.bind(stream));
const closeAsync =
useStdout || !(/** @type {any} */ (stream).close)
? undefined
: promisify(
/** @type {import('fs').WriteStream} */ (stream).close.bind(stream),
);

let flushed = Promise.resolve();
let closed = false;
Expand Down Expand Up @@ -104,7 +107,7 @@ export const makeFsStreamWriter = async filePath => {
// TODO: Consider creating a single Error here to use a write rejection
closed = true;
await flush();
await endAsync?.();
await closeAsync?.();
};

stream.on('error', err => updateFlushed(Promise.reject(err)));
Expand Down

0 comments on commit 77b835b

Please sign in to comment.