diff --git a/__scripts/test.mjs b/__scripts/test.mjs index ecf8f2597..bcc43b63f 100755 --- a/__scripts/test.mjs +++ b/__scripts/test.mjs @@ -1,13 +1,19 @@ #!/usr/bin/env node import path from "node:path"; +import os from "node:os"; import { execa } from "execa"; import { detect, getCommand } from "@antfu/ni"; import PackageJson from "@npmcli/package-json"; import fse from "fs-extra"; +import PQueue from "p-queue"; -const TO_IGNORE = [".github", "__scripts", "yarn.lock", "package.json"]; +console.log({ concurrency: os.cpus().length }); + +const queue = new PQueue({ concurrency: os.cpus().length }); + +const TO_IGNORE = [".git", ".github", "__scripts", "yarn.lock", "package.json"]; let examples = []; @@ -32,15 +38,19 @@ if (process.env.CI) { const entries = await fse.readdir(process.cwd(), { withFileTypes: true }); examples = entries .filter((entry) => entry.isDirectory()) - .filter((d) => !TO_IGNORE.includes(d)); + .filter((entry) => !TO_IGNORE.includes(entry.name)) + .map((entry) => entry.name) + .filter((entry) => { + return fse.existsSync(path.join(entry, "package.json")); + }); } const list = new Intl.ListFormat("en", { style: "long", type: "conjunction" }); console.log(`Testing changed examples: ${list.format(examples)}`); -const settled = await Promise.allSettled( - examples.map(async (example) => { +for (const example of examples) { + queue.add(async () => { const pkgJson = await PackageJson.load(example); const remixDeps = Object.keys(pkgJson.content.dependencies).filter((d) => { @@ -139,9 +149,16 @@ const settled = await Promise.allSettled( }); await pkgJson.save(); - }) -); + }); +} + +try { + queue.start(); +} catch (error) { + console.error(error); + process.exit(1); +} -const rejected = settled.filter((s) => s.status === "rejected"); -rejected.forEach((s) => console.error(s.reason)); -process.exit(rejected.length > 0 ? 1 : 0); +// const rejected = promises.filter((s) => s.status === "rejected"); +// rejected.forEach((s) => console.error(s.reason)); +// process.exit(rejected.length > 0 ? 1 : 0); diff --git a/package.json b/package.json index fd46541c9..ae2912fe9 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@antfu/ni": "^0.18.8", "@npmcli/package-json": "^3.0.0", "execa": "^6.1.0", - "fs-extra": "11.1.0" + "fs-extra": "11.1.0", + "p-queue": "^7.3.0" } } diff --git a/prettier.config.js b/prettier.config.js index 27cca4c3d..1c0267e89 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1,2 +1,2 @@ -/** @type {import('prettier').Options} */ +/** @type {import('prettier').Config} */ module.exports = {}; diff --git a/yarn.lock b/yarn.lock index 23f31a819..6945b3768 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1953,6 +1953,11 @@ esutils@^2.0.2: resolved "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== +eventemitter3@^4.0.7: + version "4.0.7" + resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" + integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== + execa@^5.0.0: version "5.1.1" resolved "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd" @@ -3426,6 +3431,19 @@ p-locate@^5.0.0: dependencies: p-limit "^3.0.2" +p-queue@^7.3.0: + version "7.3.0" + resolved "https://registry.npmjs.org/p-queue/-/p-queue-7.3.0.tgz#90dfa104894b286dc2f3638961380fb6dc262e55" + integrity sha512-5fP+yVQ0qp0rEfZoDTlP2c3RYBgxvRsw30qO+VtPPc95lyvSG+x6USSh1TuLB4n96IO6I8/oXQGsTgtna4q2nQ== + dependencies: + eventemitter3 "^4.0.7" + p-timeout "^5.0.2" + +p-timeout@^5.0.2: + version "5.1.0" + resolved "https://registry.npmjs.org/p-timeout/-/p-timeout-5.1.0.tgz#b3c691cf4415138ce2d9cfe071dba11f0fee085b" + integrity sha512-auFDyzzzGZZZdHz3BtET9VEz0SE/uMEAx7uWfGPucfzEwwe/xH0iVeZibQmANYE/hp9T2+UUZT5m+BKyrDp3Ew== + p-try@^2.0.0: version "2.2.0" resolved "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"