Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: run makers simultaneously #3363

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
erikian marked this conversation as resolved.
Show resolved Hide resolved
const artifacts = await uniqMaker.make({
erikian marked this conversation as resolved.
Show resolved Hide resolved
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