Skip to content

Commit

Permalink
fix: add monorepo build package command to build a single package
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed May 31, 2024
1 parent b8d5cfc commit 304dea1
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
13 changes: 13 additions & 0 deletions packages/monorepo/bin/monorepo-build-hybrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node
const {program} = require("commander");

program
.usage("monorepo build-hybrid [options]")
.option("-v, --verbose", "Enable verbose log", (v, t) => t + 1, 0)
.parse(process.argv);

(async () => {
const {commands, runCommand} = await import("../src/index.js");

runCommand(commands.BuildHybridCmd, program.opts());
})();
1 change: 1 addition & 0 deletions packages/monorepo/bin/monorepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ program
.version(cliPkg.version)
.command("ci <type>", "Perform ci actions (configure)")
.command("build <type>", "Build artifacts (workspace, packages)")
.command("build-hybrid <type>", "Build hybrid esm/cjs package (must be run over a single package)")
.command("clean <type>", "Clean artifacts (workspace, docker)")
.command("publish <type>", "Publish artifacts (packages, examples, ghpages, docker, heroku)")
.command("sync <type>", "Perform synchronisation on given type (repository, packages, examples)")
Expand Down
13 changes: 0 additions & 13 deletions packages/monorepo/src/MonoRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {cleanTagsDocker} from "./utils/docker/cleanTagsDocker.js";
import {getWorkspaces} from "./utils/workspace/getWorkspaces.js";
import {cleanPackages} from "./utils/packages/cleanPackages.js";
import {yarnBerry} from "./utils/cli/YarnBerry.js";
import {buildHybridPackage, buildHybridPackages} from "./utils/packages/buildHybridPackages.js";

function getDefaultOptions(rootPkg) {
return {
Expand Down Expand Up @@ -336,8 +335,6 @@ export class MonoRepo {
const newCtx = this.fork(options);

switch (type) {
case "package":
return buildHybridPackage(process.cwd(), null, newCtx);
case "workspaces":
case "workspace":
return this.buildWorkspace();
Expand All @@ -357,16 +354,6 @@ export class MonoRepo {
}
}

async buildPackage() {
if (this.hasBuild) {
await this.manager.run("build");
}

if (this.hasE2E) {
await this.manager.run("test:e2e");
}
}

async configureWorkspace(options = {}) {
return configureWorkspace(this.fork(options));
}
Expand Down
13 changes: 13 additions & 0 deletions packages/monorepo/src/commands/build/BuildHybridCmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {buildHybridPackage} from "../../utils/packages/buildHybridPackages.js";

export class BuildHybridCmd {
getTasks(context) {
return [
{
task() {
return buildHybridPackage(process.cwd(), null, context);
}
}
];
}
}
1 change: 1 addition & 0 deletions packages/monorepo/src/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./clean/CleanCmd.js";
export * from "./build/BuildCmd.js";
export * from "./build/BuildHybridCmd.js";
export * from "./version/VersionCmd.js";
export * from "./publish/PublishCmd.js";
export * from "./sync/SyncCmd.js";
Expand Down
6 changes: 5 additions & 1 deletion packages/monorepo/src/runCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ async function importConfig() {
try {
return await import(`${process.cwd()}/release.config.mjs`);
} catch (er) {
return await import(`${process.cwd()}/release.config.js`);
try {
return await import(`${process.cwd()}/release.config.js`);
} catch (er) {
return {};
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion packages/monorepo/src/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,43 @@ import {copyPackages} from "../utils/packages/copyPackages.js";
import {writePackages} from "../utils/packages/writePackages.js";
import {syncDependencies} from "../utils/depencencies/syncDependencies.js";
import {clean} from "../utils/common/clean.js";
import {buildHybridPackages} from "../utils/packages/buildHybridPackages.js";
import {buildHybridPackage, buildHybridPackages} from "../utils/packages/buildHybridPackages.js";

export function build(context) {
return [
{
when: () => context.type === "package",
task() {
return buildHybridPackage(process.cwd(), null, newCtx);
}
},
{
when: () => context.type !== "package",
title: "Clean workspace",
task: () => clean([context.outputDir])
},
{
when: () => context.type !== "package",
title: "Compile packages",
task: () => compilePackages(context)
},
{
when: () => context.type !== "package",
title: "Sync dependencies",
task: () => syncDependencies(context)
},
{
when: () => context.type !== "package",
title: "Copy packages",
task: () => copyPackages(context)
},
{
when: () => context.type !== "package",
title: "Write package.json",
task: () => writePackages(context)
},
{
when: () => context.type !== "package",
title: "Build hybrid CommonJS/ESM modules",
task: () => buildHybridPackages(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export async function transformCjsFileToEsm(dir, context) {
.flatMap((t) => transform(t))
.map(async ({code, file}) => {
try {
await writeFile(context?.out ? file + ".mjs" : "", code, {encoding: "utf8"});
await writeFile(context?.out ? file + ".mjs" : file, code, {encoding: "utf8"});
} catch (er) {
!context.silent && logger.warn(er);
}
Expand Down

0 comments on commit 304dea1

Please sign in to comment.