Skip to content

Commit

Permalink
feat: build/pack in parallel (#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jul 7, 2022
1 parent e4b4a4e commit d86c722
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/commands/pack/tarballs.ts
Expand Up @@ -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}),
}

Expand All @@ -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)
}
Expand Down
22 changes: 18 additions & 4 deletions src/tarballs/build.ts
Expand Up @@ -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()
Expand Down Expand Up @@ -115,8 +116,16 @@ export async function build(c: BuildConfig, options: {
tmp: qq.join(config.root, 'tmp'),
})
if (options.pack === false) return
await pack(workspace, c.dist(gzLocalKey))
if (xz) await pack(workspace, c.dist(xzLocalKey))
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)

Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 2 additions & 5 deletions src/tarballs/node.ts
Expand Up @@ -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)
Expand Down

0 comments on commit d86c722

Please sign in to comment.