Skip to content

Commit 7370d6e

Browse files
feat: run makers simultaneously (#3363)
1 parent cfab773 commit 7370d6e

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

packages/api/core/src/api/make.ts

+9-20
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type MakeContext = {
5252
dir: string;
5353
forgeConfig: ResolvedForgeConfig;
5454
actualOutDir: string;
55-
makers: MakerBase<unknown>[];
55+
makers: Array<() => MakerBase<unknown>>;
5656
outputs: ForgeMakeResult[];
5757
};
5858

@@ -134,7 +134,7 @@ export const listrMake = (
134134
}
135135

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

139139
const possibleMakers = generateTargets(forgeConfig, overrideTargets);
140140

@@ -182,7 +182,7 @@ export const listrMake = (
182182

183183
maker.ensureExternalBinariesExist();
184184

185-
makers.push(maker);
185+
makers.push(() => maker.clone());
186186
}
187187

188188
if (makers.length === 0) {
@@ -234,6 +234,7 @@ export const listrMake = (
234234

235235
const subRunner = task.newListr([], {
236236
...listrOptions,
237+
concurrent: true,
237238
rendererOptions: {
238239
collapse: false,
239240
collapseErrors: false,
@@ -247,25 +248,13 @@ export const listrMake = (
247248
}
248249

249250
for (const maker of makers) {
251+
const uniqMaker = maker();
250252
subRunner.add({
251-
title: `Making a ${chalk.magenta(maker.name)} distributable for ${chalk.cyan(`${platform}/${targetArch}`)}`,
253+
title: `Making a ${chalk.magenta(uniqMaker.name)} distributable for ${chalk.cyan(`${platform}/${targetArch}`)}`,
252254
task: async () => {
253255
try {
254-
/**
255-
* WARNING: DO NOT ATTEMPT TO PARALLELIZE MAKERS
256-
*
257-
* Currently it is assumed we have 1 maker per make call but that is
258-
* not enforced. It is technically possible to have 1 maker be called
259-
* multiple times. The "prepareConfig" method however implicitly
260-
* requires a lock that is not enforced. There are two options:
261-
*
262-
* * Provide makers a getConfig() method
263-
* * Remove support for config being provided as a method
264-
* * Change the entire API of maker from a single constructor to
265-
* providing a MakerFactory
266-
*/
267-
await Promise.resolve(maker.prepareConfig(targetArch));
268-
const artifacts = await maker.make({
256+
await Promise.resolve(uniqMaker.prepareConfig(targetArch));
257+
const artifacts = await uniqMaker.make({
269258
appName,
270259
forgeConfig,
271260
packageJSON,
@@ -285,7 +274,7 @@ export const listrMake = (
285274
if (err) {
286275
throw err;
287276
} else {
288-
throw new Error(`An unknown error occurred while making for target: ${maker.name}`);
277+
throw new Error(`An unknown error occurred while making for target: ${uniqMaker.name}`);
289278
}
290279
}
291280
},

packages/maker/base/src/Maker.ts

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ export default abstract class Maker<C> implements IForgeMaker {
9393
return true;
9494
}
9595

96+
clone(): Maker<C> {
97+
const MakerClass = (this as any).constructor;
98+
return new MakerClass(this.configOrConfigFetcher, this.platformsToMakeOn);
99+
}
100+
96101
/**
97102
* Makers must implement this method and return an array of absolute paths
98103
* to the artifacts generated by your maker

0 commit comments

Comments
 (0)