Skip to content

Commit

Permalink
refactor(concurrency): get rid of useless if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
floydspace committed Oct 1, 2021
1 parent bfa8040 commit 074ca48
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface PackagerOptions {
}

export interface Configuration extends Omit<BuildOptions, 'nativeZip' | 'watch' | 'plugins'> {
concurrency: number;
concurrency?: number;
packager: 'npm' | 'yarn';
packagePath: string;
exclude: '*' | string[];
Expand Down Expand Up @@ -246,7 +246,7 @@ export class EsbuildServerlessPlugin implements ServerlessPlugin {
this.prepare();
this.serverless.cli.log(`Compiling to ${this.buildOptions.target} bundle with esbuild...`);

const bundlePromise = async (bundleInfo) => {
const bundleMapper = async (bundleInfo) => {
const { entry, func, functionAlias } = bundleInfo;
const config: Omit<BuildOptions, 'watch'> = {
...this.buildOptions,
Expand Down Expand Up @@ -292,17 +292,12 @@ export class EsbuildServerlessPlugin implements ServerlessPlugin {

return { result, bundlePath, func, functionAlias };
};
// If concurrency is enabled, limit it, otherwise run all in parallel
if (this.buildOptions.concurrency) {
this.serverless.cli.log(`Bundling with concurrency: ${this.buildOptions.concurrency}`);
this.buildResults = await pMap(this.rootFileNames, bundlePromise, {
concurrency: this.buildOptions.concurrency,
});
} else {
this.buildResults = await Promise.all(
this.rootFileNames.map(async (bundleInfo) => bundlePromise(bundleInfo))
);
}
this.serverless.cli.log(
`Compiling with concurrency: ${this.buildOptions.concurrency ?? 'Infinity'}`
);
this.buildResults = await pMap(this.rootFileNames, bundleMapper, {
concurrency: this.buildOptions.concurrency,
});
this.serverless.cli.log('Compiling completed.');
return this.buildResults.map((r) => r.result);
}
Expand Down

0 comments on commit 074ca48

Please sign in to comment.