Skip to content

Commit e5412a1

Browse files
committed
refactor using readline
1 parent 08f3945 commit e5412a1

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

scripts/npmPack.js

+15-16
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
// recreates the artifact list and verifies that it has no changes compared to the committed state.
1212

1313
import { execSync, spawn } from "node:child_process";
14-
import fs from "node:fs";
14+
import * as fs from "node:fs/promises";
15+
import * as readline from "node:readline/promises";
1516
import { parseArgs } from "node:util";
1617
import { artifactListFile } from "#dev/paths";
1718

@@ -50,23 +51,21 @@ const exitCode = new Promise((resolve, reject) => {
5051
child.once("close", code => resolve(code));
5152
});
5253

53-
fs.unlinkSync(artifactListFile);
54+
await fs.unlink(artifactListFile);
5455

55-
for await (const chunk of child.stdout.setEncoding("utf8")) {
56-
const lines = /** @type {string} */ (chunk)
57-
.trim()
58-
.split(/\s/);
59-
for (const line of lines) {
60-
/** @type {YarnPackOutputLine} */
61-
const json = JSON.parse(line);
62-
if ("location" in json) {
63-
// Workaround for false positive reports
64-
// See https://github.com/yarnpkg/berry/issues/6766
65-
if (json.location.startsWith("_build")) {
66-
continue;
67-
}
68-
fs.appendFileSync(artifactListFile, json.location + "\n", "utf8");
56+
for await (const line of readline.createInterface({
57+
input: child.stdout.setEncoding("utf8"),
58+
crlfDelay: Number.POSITIVE_INFINITY,
59+
})) {
60+
/** @type {YarnPackOutputLine} */
61+
const json = JSON.parse(line);
62+
if ("location" in json) {
63+
// Workaround for false positive reports
64+
// See https://github.com/yarnpkg/berry/issues/6766
65+
if (json.location.startsWith("_build")) {
66+
continue;
6967
}
68+
await fs.appendFile(artifactListFile, json.location + "\n", "utf8");
7069
}
7170
}
7271

0 commit comments

Comments
 (0)