Skip to content

Commit

Permalink
fix: use the new flush flag when writing executables with
Browse files Browse the repository at this point in the history
createWriteStream
  • Loading branch information
stefreak committed Nov 8, 2023
1 parent 29cb6cf commit e877399
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 44 deletions.
9 changes: 6 additions & 3 deletions cli/src/build-pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ async function zipAndHash({ targetDir, archiveName, cwd, prefix, fileNames }: Zi

const archiveHash = archiveStream.pipe(createHash("sha256"))

await finished(archiveStream.pipe(createWriteStream(targetArchive)))
// TODO: Remove "as any" as soon as @types/node ^21 is available. The flush flag is new in NodeJS v21.0.0
await finished(archiveStream.pipe(createWriteStream(targetArchive, { flush: true } as any)))

await writeFile(resolve(targetDir, `${archiveName}.sha256`), archiveHash.digest("hex") + "\n")
}
Expand Down Expand Up @@ -360,7 +361,8 @@ async function buildBinaries(args: string[]) {
const entry = i as Entry
const fileName = entry.path
if (fileName.endsWith(`/${nodeFileName}`)) {
await finished(entry.pipe(createWriteStream(resolve(extractionDir, nodeFileName))))
// TODO: Remove "as any" as soon as @types/node ^21 is available. The flush flag is new in NodeJS v21.0.0
await finished(entry.pipe(createWriteStream(resolve(extractionDir, nodeFileName), { flush: true } as any)))
} else {
entry.autodrain()
}
Expand Down Expand Up @@ -588,7 +590,8 @@ async function downloadFromWeb({

const hash = body.pipe(createHash("sha256"))

const writeStream = createWriteStream(targetPath)
// TODO: Remove "as any" as soon as @types/node ^21 is available. The flush flag is new in NodeJS v21.0.0
const writeStream = createWriteStream(targetPath, { flush: true } as any)
await finished(body.pipe(writeStream))

const sha256 = hash.digest("hex")
Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
"@types/micromatch": "^4.0.2",
"@types/minimist": "^1.2.2",
"@types/mocha": "^10.0.1",
"@types/node": "^18",
"@types/node": "^20",
"@types/node-forge": "^1.3.1",
"@types/normalize-path": "^3.0.0",
"@types/parse-git-config": "^3.0.1",
Expand Down
3 changes: 2 additions & 1 deletion core/src/commands/self-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ export class SelfUpdateCommand extends Command<SelfUpdateArgs, SelfUpdateOpts> {
try {
// See https://github.com/sindresorhus/got/blob/main/documentation/3-streams.md
const pipeline = promisify(stream.pipeline)
await pipeline(got.stream(url), createWriteStream(tempPath))
// TODO: Remove "as any" as soon as @types/node ^21 is available. The flush flag is new in NodeJS v21.0.0
await pipeline(got.stream(url), createWriteStream(tempPath, { flush: true } as any))
} catch (err) {
if (
err instanceof GotHttpError &&
Expand Down
6 changes: 5 additions & 1 deletion core/src/plugins/kubernetes/commands/pull-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ensureBuilderSecret } from "../container/build/common.js"
import type { ContainerBuildAction } from "../../container/config.js"
import { k8sGetContainerBuildActionOutputs } from "../container/handlers.js"
import type { Resolved } from "../../../actions/types.js"
import { finished } from "stream/promises"

const tmpTarPath = "/tmp/image.tar"
const imagePullTimeoutSeconds = 60 * 20
Expand Down Expand Up @@ -203,7 +204,8 @@ async function pullFromExternalRegistry({ ctx, log, localId, remoteId }: PullPar

async function loadImage({ ctx, runner, log }: { ctx: PluginContext; runner: PodRunner; log: Log }) {
await tmp.withFile(async ({ path }) => {
const writeStream = fs.createWriteStream(path)
// TODO: Remove "as any" as soon as @types/node ^21 is available. The flush flag is new in NodeJS v21.0.0
const writeStream = fs.createWriteStream(path, { flush: true } as any)

await runner.exec({
command: ["cat", tmpTarPath],
Expand All @@ -220,5 +222,7 @@ async function loadImage({ ctx, runner, log }: { ctx: PluginContext; runner: Pod
args: ["load", "-i", path],
log,
})

await finished(writeStream)
})
}
3 changes: 2 additions & 1 deletion core/src/util/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { createWriteStream } from "fs"
export async function zipFolder(src: string, dest: string, log: Log) {
const { default: archiver } = await import("archiver")
return new Promise<void>((resolve, reject) => {
const output = createWriteStream(dest)
// TODO: Remove "as any" as soon as @types/node ^21 is available. The flush flag is new in NodeJS v21.0.0
const output = createWriteStream(dest, { flush: true } as any)
const archiveOpts = {
zlib: {
level: 9,
Expand Down
3 changes: 2 additions & 1 deletion core/src/util/ext-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ export class PluginTool extends CliWrapper {

if (!this.buildSpec.extract) {
const targetExecutable = join(tmpPath, ...this.targetSubpath.split(posix.sep))
response.pipe(createWriteStream(targetExecutable))
// TODO: Remove "as any" as soon as @types/node ^21 is available. The flush flag is new in NodeJS v21.0.0
response.pipe(createWriteStream(targetExecutable, { flush: true } as any))
response.on("end", () => resolve())
} else {
const format = this.buildSpec.extract.format
Expand Down
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@types/lodash-es": "^4.17.9",
"@types/minimist": "^1.2.2",
"@types/mocha": "^10.0.1",
"@types/node": "^18",
"@types/node": "^20",
"chai": "^4.3.7",
"chalk": "^4.1.2",
"dedent": "^0.7.0",
Expand Down
39 changes: 13 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@rollup/plugin-url": "^8.0.2",
"@types/fs-extra": "^9.0.1",
"@types/lodash-es": "^4.17.9",
"@types/node": "^18",
"@types/node": "^20",
"@types/prettier": "2.7.3",
"@types/semver": "^7.5.0",
"@types/treeify": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion plugins/conftest-container/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^18",
"@types/node": "^20",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"source-map-support": "^0.5.21",
Expand Down
2 changes: 1 addition & 1 deletion plugins/conftest-kubernetes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^18",
"@types/node": "^20",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"strip-ansi": "^6.0.0"
Expand Down
2 changes: 1 addition & 1 deletion plugins/conftest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^18",
"@types/node": "^20",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"strip-ansi": "^6.0.0"
Expand Down
2 changes: 1 addition & 1 deletion plugins/jib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/fs-extra": "^11.0.1",
"@types/lodash-es": "^4.17.9",
"@types/mocha": "^10.0.1",
"@types/node": "^18",
"@types/node": "^20",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"source-map-support": "^0.5.21",
Expand Down
2 changes: 1 addition & 1 deletion plugins/pulumi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/hapi__joi": "^17.1.9",
"@types/json-merge-patch": "0.0.8",
"@types/mocha": "^10.0.1",
"@types/node": "^18",
"@types/node": "^20",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"strip-ansi": "^6.0.0"
Expand Down
2 changes: 1 addition & 1 deletion plugins/terraform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/node": "^18",
"@types/node": "^20",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"source-map-support": "^0.5.21",
Expand Down
4 changes: 2 additions & 2 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"minimist": "^1.2.8"
},
"devDependencies": {
"@types/node": "^18",
"@types/node": "^20",
"prettier": "3.0.0",
"typescript": "^5.1.3"
},
Expand All @@ -32,4 +32,4 @@
"fix-format": "npm run lint -- --fix --quiet",
"lint": "eslint --ext .ts ."
}
}
}

0 comments on commit e877399

Please sign in to comment.