feat: build/pack in parallel
MODIFY
src/commands/pack/tarballs.ts
src/commands/pack/tarballs.ts
@@ -13,6 +13,7 @@ This can be used to create oclif CLIs that use the system node or that come prel
root: Flags.string({char: 'r', description: 'path to oclif CLI root', default: '.', required: true}),
targets: Flags.string({char: 't', description: 'comma-separated targets to pack (e.g.: linux-arm,win32-x64)'}),
xz: Flags.boolean({description: 'also build xz', allowNo: true}),
+ parallel: Flags.boolean({description: 'build tarballs in parallel'}),
tarball: Flags.string({char: 'l', description: 'optionally specify a path to a tarball already generated by NPM', required: false}),
}
@@ -27,6 +28,7 @@ This can be used to create oclif CLIs that use the system node or that come prel
await Tarballs.build(buildConfig, {
tarball: flags.tarball,
+ parallel: flags.parallel,
})
qq.cd(prevCwd)
}

MODIFY
src/tarballs/build.ts
src/tarballs/build.ts
@@ -25,6 +25,7 @@ export async function build(c: BuildConfig, options: {
platform?: string;
pack?: boolean;
tarball?: string;
+ parallel?: boolean;
} = {}): Promise<void> {
const {xz, config} = c
const prevCwd = qq.cwd()
@@ -115,8 +116,16 @@ export async function build(c: BuildConfig, options: {
tmp: qq.join(config.root, 'tmp'),
})
if (options.pack === false) return
+ if (options.parallel) {
+ await Promise.all(
+ [pack(workspace, c.dist(gzLocalKey))]
+ .concat(xz ? [pack(workspace, c.dist(xzLocalKey))] : []),
+ )
+ } else {
await pack(workspace, c.dist(gzLocalKey))
if (xz) await pack(workspace, c.dist(xzLocalKey))
+ }
+
if (!c.updateConfig.s3.host) return
const rollout = (typeof c.updateConfig.autoupdate === 'object' && c.updateConfig.autoupdate.rollout)
@@ -153,8 +162,13 @@ export async function build(c: BuildConfig, options: {
await addDependencies()
await writeBinScripts({config, baseWorkspace: c.workspace(), nodeVersion: c.nodeVersion})
await pretarball()
- for (const target of c.targets) {
- if (!options.platform || options.platform === target.platform) {
+ const targetsToBuild = c.targets.filter(t => !options.platform || options.platform === t.platform)
+ if (options.parallel) {
+ log(`will build ${targetsToBuild.length} targets in parallel`)
+ await Promise.all(targetsToBuild.map(t => buildTarget(t)))
+ } else {
+ log(`will build ${targetsToBuild.length} targets sequentially`)
+ for (const target of targetsToBuild) {
// eslint-disable-next-line no-await-in-loop
await buildTarget(target)
}

MODIFY
src/tarballs/node.ts
src/tarballs/node.ts
@@ -53,14 +53,11 @@ export async function fetchNodeBinary({nodeVersion, output, platform, arch, tmp}
const extract = async () => {
log(`extracting ${nodeBase}`)
const nodeTmp = path.join(tmp, 'node')
- await qq.rm([nodeTmp, nodeBase])
await qq.mkdirp(nodeTmp)
await qq.mkdirp(path.dirname(cache))
if (platform === 'win32') {
- qq.pushd(nodeTmp)
- await qq.x(`7z x -bd -y "${tarball}"`)
- await qq.mv([nodeBase, 'node.exe'], cache)
- qq.popd()
+ await qq.x(`7z x -bd -y "${tarball}"`, {cwd: nodeTmp})
+ await qq.mv([nodeTmp, nodeBase, 'node.exe'], cache)
} else {
await qq.x(`tar -C "${tmp}/node" -xJf "${tarball}"`)
await qq.mv([nodeTmp, nodeBase, 'bin/node'], cache)

feat: build/pack in parallel (#914)