use hand-crafted promise, pipeline does not resolve properly

This commit is contained in:
Waldemar Reusch
2023-02-05 13:32:24 +01:00
parent 45ed359bef
commit 38ad47ea75

View File

@ -1,5 +1,4 @@
import { Readable, Transform } from "stream";
import { pipeline } from "stream/promises";
import { dirname, relative, sep } from "path";
import { createWriteStream } from "fs";
@ -71,19 +70,20 @@ export default async function jar({ groupId, artifactId, version, rootPath, targ
});
await mkdir(dirname(targetPath), { recursive: true });
/**
* Create an async pipeline, wait until everything is fully processed
*/
await pipeline(
// Create an async pipeline, wait until everything is fully processed
await new Promise<void>((resolve, reject) => {
// walk all files in `rootPath` recursively
Readable.from(walk(rootPath)),
Readable.from(walk(rootPath))
// transform every path into a ZipSource object
pathToRecord(),
.pipe(pathToRecord())
// let the zip lib convert all ZipSource objects into a byte stream
zip(),
.pipe(zip())
// write that byte stream to targetPath
createWriteStream(targetPath, { encoding: "binary" })
);
.pipe(createWriteStream(targetPath, { encoding: "binary" }))
.on("finish", () => resolve())
.on("error", e => reject(e));
});
}
/**