From cd7e0f53801597a27dfa74878208f08bcbf1c346 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Tue, 18 Jul 2023 15:14:40 +0500 Subject: [PATCH] setup: parallelize bootstrap depending on device cpu cores --- scripts/bootstrap.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/bootstrap.mjs b/scripts/bootstrap.mjs index b77806e86..200b029ae 100644 --- a/scripts/bootstrap.mjs +++ b/scripts/bootstrap.mjs @@ -20,10 +20,12 @@ along with this program. If not, see . import { exec } from "child_process"; import { readFile } from "fs/promises"; import path from "path"; +import os from "os"; import parser from "yargs-parser"; import glob from "fast-glob"; import Listr from "listr"; +const THREADS = Math.min(4, process.env.THREADS || os.cpus().length / 2); const args = parser(process.argv, { alias: { scope: ["s"], offline: ["o"] } }); const IS_CI = process.env.CI; const scopes = { @@ -63,9 +65,13 @@ if (IS_BOOTSTRAP_ALL) { async function bootstrapPackages(dependencies) { console.log("> Found", dependencies.length, "dependencies to bootstrap."); + console.log("> Using", THREADS, "threads."); const outputs = { stdout: [], stderr: [] }; - const tasks = new Listr({ concurrent: 4, exitOnError: false }); + const tasks = new Listr({ + concurrent: THREADS, + exitOnError: false + }); for (const dependency of dependencies) { tasks.add({ task: () => bootstrapPackage(dependency, outputs),