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: support parallel builds #461

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
33 changes: 22 additions & 11 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ async function _build(
respectExternal: true,
},
},
parallel: false,
},
) as BuildOptions;

Expand Down Expand Up @@ -274,17 +275,27 @@ async function _build(
// await symlink(resolve(ctx.rootDir), nodemodulesDir).catch(() => {})
// }

// untyped
await typesBuild(ctx);

// mkdist
await mkdistBuild(ctx);

// rollup
await rollupBuild(ctx);

// copy
await copyBuild(ctx);
const buildTasks = [
// untyped
(): Promise<void> => typesBuild(ctx),
// mkdist
(): Promise<void> => mkdistBuild(ctx),
// rollup
(): Promise<void> => rollupBuild(ctx),
// copy
(): Promise<void> => copyBuild(ctx),
];

// Run build tasks
if (options.parallel) {
// Start all tasks in parallel
await Promise.all(buildTasks.map((task) => task()));
} else {
// Run tasks sequentially
for (const task of buildTasks) {
await task();
}
}

// Skip rest for stub and watch mode
if (options.stub || options.watch) {
Expand Down
4 changes: 4 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const main = defineCommand({
type: "boolean",
description: "Generate sourcemaps (experimental)",
},
parallel: {
type: "boolean",
description: "Run build in parallel (experimental)",
},
},
async run({ args }) {
const rootDir = resolve(process.cwd(), args.dir || ".");
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ export interface BuildOptions {
* [Rollup](https://rollupjs.org/configuration-options) Build Options
*/
rollup: RollupBuildOptions;

/**
* @experimental
* Run build in parallel
*/
parallel: boolean;
}

export interface BuildContext {
Expand Down
Loading