Skip to content

Commit 1ad34ac

Browse files
committed
chore: tweak concurrency
Signed-off-by: Logan McAnsh <[email protected]>
1 parent b50347d commit 1ad34ac

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

__scripts/test.mjs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#!/usr/bin/env node
22

33
import path from "node:path";
4+
import os from "node:os";
45

56
import { execa } from "execa";
67
import { detect, getCommand } from "@antfu/ni";
78
import PackageJson from "@npmcli/package-json";
89
import fse from "fs-extra";
10+
import PQueue from "p-queue";
911

10-
const TO_IGNORE = [".github", "__scripts", "yarn.lock", "package.json"];
12+
console.log({ concurrency: os.cpus().length });
13+
14+
const queue = new PQueue({ concurrency: os.cpus().length });
15+
16+
const TO_IGNORE = [".git", ".github", "__scripts", "yarn.lock", "package.json"];
1117

1218
let examples = [];
1319

@@ -32,15 +38,19 @@ if (process.env.CI) {
3238
const entries = await fse.readdir(process.cwd(), { withFileTypes: true });
3339
examples = entries
3440
.filter((entry) => entry.isDirectory())
35-
.filter((d) => !TO_IGNORE.includes(d));
41+
.filter((entry) => !TO_IGNORE.includes(entry.name))
42+
.map((entry) => entry.name)
43+
.filter((entry) => {
44+
return fse.existsSync(path.join(entry, "package.json"));
45+
});
3646
}
3747

3848
const list = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
3949

4050
console.log(`Testing changed examples: ${list.format(examples)}`);
4151

42-
const settled = await Promise.allSettled(
43-
examples.map(async (example) => {
52+
for (const example of examples) {
53+
queue.add(async () => {
4454
const pkgJson = await PackageJson.load(example);
4555

4656
const remixDeps = Object.keys(pkgJson.content.dependencies).filter((d) => {
@@ -139,9 +149,16 @@ const settled = await Promise.allSettled(
139149
});
140150

141151
await pkgJson.save();
142-
})
143-
);
152+
});
153+
}
154+
155+
try {
156+
queue.start();
157+
} catch (error) {
158+
console.error(error);
159+
process.exit(1);
160+
}
144161

145-
const rejected = settled.filter((s) => s.status === "rejected");
146-
rejected.forEach((s) => console.error(s.reason));
147-
process.exit(rejected.length > 0 ? 1 : 0);
162+
// const rejected = promises.filter((s) => s.status === "rejected");
163+
// rejected.forEach((s) => console.error(s.reason));
164+
// process.exit(rejected.length > 0 ? 1 : 0);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@antfu/ni": "^0.18.8",
2828
"@npmcli/package-json": "^3.0.0",
2929
"execa": "^6.1.0",
30-
"fs-extra": "11.1.0"
30+
"fs-extra": "11.1.0",
31+
"p-queue": "^7.3.0"
3132
}
3233
}

prettier.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/** @type {import('prettier').Options} */
1+
/** @type {import('prettier').Config} */
22
module.exports = {};

yarn.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,11 @@ esutils@^2.0.2:
19531953
resolved "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
19541954
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
19551955

1956+
eventemitter3@^4.0.7:
1957+
version "4.0.7"
1958+
resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
1959+
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==
1960+
19561961
execa@^5.0.0:
19571962
version "5.1.1"
19581963
resolved "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd"
@@ -3426,6 +3431,19 @@ p-locate@^5.0.0:
34263431
dependencies:
34273432
p-limit "^3.0.2"
34283433

3434+
p-queue@^7.3.0:
3435+
version "7.3.0"
3436+
resolved "https://registry.npmjs.org/p-queue/-/p-queue-7.3.0.tgz#90dfa104894b286dc2f3638961380fb6dc262e55"
3437+
integrity sha512-5fP+yVQ0qp0rEfZoDTlP2c3RYBgxvRsw30qO+VtPPc95lyvSG+x6USSh1TuLB4n96IO6I8/oXQGsTgtna4q2nQ==
3438+
dependencies:
3439+
eventemitter3 "^4.0.7"
3440+
p-timeout "^5.0.2"
3441+
3442+
p-timeout@^5.0.2:
3443+
version "5.1.0"
3444+
resolved "https://registry.npmjs.org/p-timeout/-/p-timeout-5.1.0.tgz#b3c691cf4415138ce2d9cfe071dba11f0fee085b"
3445+
integrity sha512-auFDyzzzGZZZdHz3BtET9VEz0SE/uMEAx7uWfGPucfzEwwe/xH0iVeZibQmANYE/hp9T2+UUZT5m+BKyrDp3Ew==
3446+
34293447
p-try@^2.0.0:
34303448
version "2.2.0"
34313449
resolved "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"

0 commit comments

Comments
 (0)