From 00d2cc9f44e1756b4653bb552b74a54f305a6a2e Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Wed, 3 Jul 2024 10:53:26 +0200 Subject: [PATCH] Improved speed of monobundle script - right now, it loops through all packages serially, which isn't effectively using multi-core machines - by using `concurrently`, we can rely on it to use all the cores it can, so this should dramatically speed up the bundling step --- ghost/core/monobundle.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/ghost/core/monobundle.js b/ghost/core/monobundle.js index 7d471749a0..72157fbf56 100755 --- a/ghost/core/monobundle.js +++ b/ghost/core/monobundle.js @@ -4,9 +4,8 @@ const fs = require('fs'); const path = require('path'); -const util = require('util'); -const exec = util.promisify(require('node:child_process').exec); +const concurrently = require('concurrently'); const detectIndent = require('detect-indent'); const detectNewline = require('detect-newline'); const findRoot = require('find-root'); @@ -111,6 +110,8 @@ function getWorkspaces(from) { console.log('workspaces', workspaces); console.log('\n-------------------------\n'); + const packagesToPack = []; + for (const w of workspaces) { const workspacePkgInfo = JSONFile.for(path.join(w, 'package.json')); @@ -118,7 +119,7 @@ function getWorkspaces(from) { continue; } - console.log(`packaging ${w}\n`); + console.log(`packaging ${w}`); workspacePkgInfo.pkg.version = pkgInfo.pkg.version; workspacePkgInfo.write(); @@ -144,17 +145,24 @@ function getWorkspaces(from) { console.log(`- resolution override for ${workspacePkgInfo.pkg.name} to ${packedFilename}\n`); pkgInfo.pkg.resolutions[workspacePkgInfo.pkg.name] = packedFilename; - const command = `npm pack --pack-destination ../core/components`; - console.log(`running '${command}' in ${w}\n`); - - const {stdout, stderr} = await exec(command, {cwd: w}); - console.log('stdout', stdout); - console.log('stderr', stderr); - console.log('\n-------------------------\n'); + packagesToPack.push(w); } pkgInfo.write(); + const {result} = concurrently(packagesToPack.map(w => ({ + name: w, + cwd: w, + command: 'npm pack --pack-destination ../core/components' + }))); + + try { + await result; + } catch (e) { + console.error(e); + throw e; + } + const filesToCopy = [ 'README.md', 'LICENSE',