Skip to content

Commit

Permalink
feat: run makers simultaneously (#3363)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Oct 31, 2023
1 parent cfab773 commit 7370d6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
29 changes: 9 additions & 20 deletions packages/api/core/src/api/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type MakeContext = {
dir: string;
forgeConfig: ResolvedForgeConfig;
actualOutDir: string;
makers: MakerBase<unknown>[];
makers: Array<() => MakerBase<unknown>>;
outputs: ForgeMakeResult[];
};

Expand Down Expand Up @@ -134,7 +134,7 @@ export const listrMake = (
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const makers: MakerBase<any>[] = [];
const makers: Array<() => MakerBase<any>> = [];

const possibleMakers = generateTargets(forgeConfig, overrideTargets);

Expand Down Expand Up @@ -182,7 +182,7 @@ export const listrMake = (

maker.ensureExternalBinariesExist();

makers.push(maker);
makers.push(() => maker.clone());
}

if (makers.length === 0) {
Expand Down Expand Up @@ -234,6 +234,7 @@ export const listrMake = (

const subRunner = task.newListr([], {
...listrOptions,
concurrent: true,
rendererOptions: {
collapse: false,
collapseErrors: false,
Expand All @@ -247,25 +248,13 @@ export const listrMake = (
}

for (const maker of makers) {
const uniqMaker = maker();
subRunner.add({
title: `Making a ${chalk.magenta(maker.name)} distributable for ${chalk.cyan(`${platform}/${targetArch}`)}`,
title: `Making a ${chalk.magenta(uniqMaker.name)} distributable for ${chalk.cyan(`${platform}/${targetArch}`)}`,
task: async () => {
try {
/**
* WARNING: DO NOT ATTEMPT TO PARALLELIZE MAKERS
*
* Currently it is assumed we have 1 maker per make call but that is
* not enforced. It is technically possible to have 1 maker be called
* multiple times. The "prepareConfig" method however implicitly
* requires a lock that is not enforced. There are two options:
*
* * Provide makers a getConfig() method
* * Remove support for config being provided as a method
* * Change the entire API of maker from a single constructor to
* providing a MakerFactory
*/
await Promise.resolve(maker.prepareConfig(targetArch));
const artifacts = await maker.make({
await Promise.resolve(uniqMaker.prepareConfig(targetArch));
const artifacts = await uniqMaker.make({
appName,
forgeConfig,
packageJSON,
Expand All @@ -285,7 +274,7 @@ export const listrMake = (
if (err) {
throw err;
} else {
throw new Error(`An unknown error occurred while making for target: ${maker.name}`);
throw new Error(`An unknown error occurred while making for target: ${uniqMaker.name}`);
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions packages/maker/base/src/Maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export default abstract class Maker<C> implements IForgeMaker {
return true;
}

clone(): Maker<C> {
const MakerClass = (this as any).constructor;
return new MakerClass(this.configOrConfigFetcher, this.platformsToMakeOn);
}

/**
* Makers must implement this method and return an array of absolute paths
* to the artifacts generated by your maker
Expand Down

0 comments on commit 7370d6e

Please sign in to comment.