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: incremental build #123

Merged
merged 4 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-moles-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bob-the-bundler": minor
---

better performance by incrementally building only packages that had changes
36 changes: 28 additions & 8 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ function assertTypeScriptBuildResult(result: execa.ExecaReturnValue<string>) {
}
}

async function buildTypeScript(buildPath: string) {
async function buildTypeScript(
buildPath: string,
options: { incremental?: boolean } = {}
) {
assertTypeScriptBuildResult(
await execa("npx", [
"tsc",
...compilerOptionsToArgs(typeScriptCompilerOptions("esm")),
options.incremental ? "--incremental" : "",
"--outDir",
join(buildPath, "esm"),
])
Expand All @@ -88,22 +92,34 @@ async function buildTypeScript(buildPath: string) {
await execa("npx", [
"tsc",
...compilerOptionsToArgs(typeScriptCompilerOptions("cjs")),
options.incremental ? "--incremental" : "",
"--outDir",
join(buildPath, "cjs"),
])
);
}

export const buildCommand = createCommand<{}, {}>((api) => {
export const buildCommand = createCommand<
{},
{
incremental?: boolean;
}
>((api) => {
const { reporter } = api;

return {
command: "build",
describe: "Build",
builder(yargs) {
return yargs.options({});
return yargs.options({
incremental: {
describe:
"Better performance by building only packages that had changes.",
type: "boolean",
},
});
},
async handler() {
async handler({ incremental }) {
const cwd = process.cwd();
const rootPackageJSON = await getRootPackageJSON(cwd);
const workspaces = getWorkspaces(rootPackageJSON);
Expand All @@ -112,8 +128,10 @@ export const buildCommand = createCommand<{}, {}>((api) => {
if (isSinglePackage) {
const buildPath = join(cwd, ".bob");

await fse.remove(buildPath);
await buildTypeScript(buildPath);
if (!incremental) {
await fse.remove(buildPath);
}
await buildTypeScript(buildPath, { incremental });
const pkg = await fse.readJSON(resolve(cwd, "package.json"));
const fullName: string = pkg.name;

Expand Down Expand Up @@ -150,8 +168,10 @@ export const buildCommand = createCommand<{}, {}>((api) => {
);

const bobBuildPath = join(cwd, ".bob");
await fse.remove(bobBuildPath);
await buildTypeScript(bobBuildPath);
if (!incremental) {
await fse.remove(bobBuildPath);
}
await buildTypeScript(bobBuildPath, { incremental });

await Promise.all(
packageInfoList.map(({ cwd, pkg, fullName }) =>
Expand Down