@agoric/internal
Advanced tools
Comparing version 0.4.0-upgrade-19-dev-0754752.0 to 0.4.0-upgrade-19-dev-6f73842.0
{ | ||
"name": "@agoric/internal", | ||
"version": "0.4.0-upgrade-19-dev-0754752.0+0754752", | ||
"version": "0.4.0-upgrade-19-dev-6f73842.0+6f73842", | ||
"description": "Externally unsupported utilities internal to agoric-sdk", | ||
@@ -23,3 +23,3 @@ "type": "module", | ||
"dependencies": { | ||
"@agoric/base-zone": "0.1.1-upgrade-19-dev-0754752.0+0754752", | ||
"@agoric/base-zone": "0.1.1-upgrade-19-dev-6f73842.0+6f73842", | ||
"@endo/common": "^1.2.9", | ||
@@ -38,3 +38,3 @@ "@endo/errors": "^1.2.9", | ||
"devDependencies": { | ||
"@agoric/cosmic-proto": "0.5.0-upgrade-19-dev-0754752.0+0754752", | ||
"@agoric/cosmic-proto": "0.5.0-upgrade-19-dev-6f73842.0+6f73842", | ||
"@endo/exo": "^1.5.8", | ||
@@ -65,3 +65,3 @@ "@endo/init": "^1.1.8", | ||
}, | ||
"gitHead": "07547522e9d8a06692fa5ff12c35230ddb4b252b" | ||
"gitHead": "6f73842af496b44e61731f3beaf81767d8ea08dd" | ||
} |
@@ -1,4 +0,4 @@ | ||
import { createWriteStream } from 'node:fs'; | ||
import { open } from 'node:fs/promises'; | ||
import process from 'node:process'; | ||
import { open } from 'node:fs/promises'; | ||
import { promisify } from 'node:util'; | ||
@@ -43,6 +43,2 @@ /** | ||
const noPath = /** @type {import('fs').PathLike} */ ( | ||
/** @type {unknown} */ (undefined) | ||
); | ||
/** @typedef {NonNullable<Awaited<ReturnType<typeof makeFsStreamWriter>>>} FsStreamWriter */ | ||
@@ -55,8 +51,18 @@ /** @param {string | undefined | null} filePath */ | ||
const handle = await (filePath !== '-' ? open(filePath, 'a') : undefined); | ||
const stream = handle | ||
? createWriteStream(noPath, { fd: handle.fd }) | ||
: process.stdout; | ||
const useStdout = filePath === '-'; | ||
const { handle, stream } = await (async () => { | ||
if (useStdout) { | ||
return { handle: undefined, stream: process.stdout }; | ||
} | ||
const fh = await open(filePath, 'a'); | ||
return { handle: fh, stream: fh.createWriteStream({ flush: true }) }; | ||
})(); | ||
await fsStreamReady(stream); | ||
const writeAsync = promisify(stream.write.bind(stream)); | ||
const closeAsync = | ||
useStdout || !(/** @type {any} */ (stream).close) | ||
? undefined | ||
: promisify( | ||
/** @type {import('fs').WriteStream} */ (stream).close.bind(stream), | ||
); | ||
@@ -82,16 +88,10 @@ let flushed = Promise.resolve(); | ||
const write = async data => { | ||
/** @type {Promise<void>} */ | ||
const written = closed | ||
? Promise.reject(Error('Stream closed')) | ||
: new Promise((resolve, reject) => { | ||
stream.write(data, err => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
: writeAsync(data); | ||
updateFlushed(written); | ||
return written; | ||
const waitForDrain = await written; | ||
if (waitForDrain) { | ||
await new Promise(resolve => stream.once('drain', resolve)); | ||
} | ||
}; | ||
@@ -113,4 +113,3 @@ | ||
await flush(); | ||
// @ts-expect-error calling a possibly missing method | ||
stream.close?.(); | ||
await closeAsync?.(); | ||
}; | ||
@@ -117,0 +116,0 @@ |
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
182645
4172