Skip to content

Commit

Permalink
feat(npm): use version commit message from lerna.json
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleDave committed Feb 5, 2023
1 parent 7a6f340 commit 3829561
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
43 changes: 43 additions & 0 deletions plugins/npm/__tests__/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,49 @@ describe("publish", () => {
]);
});

test("monorepo - should use commit message from lerna.json", async () => {
mockFs({
"lerna.json": `
{
"command": {
"version": {
"message": "Custom version commit message"
}
}
}
`,
...monorepoPackagesOnFs,
});

const plugin = new NPMPlugin();
const hooks = makeHooks();

plugin.apply({
config: { prereleaseBranches: ["next"] },
hooks,
remote: "origin",
baseBranch: "main",
logger: dummyLog(),
} as Auto.Auto);

monorepoPackages.mockReturnValueOnce(monorepoPackagesResult);
execPromise.mockReturnValueOnce("1.0.0");

await hooks.version.promise({ bump: Auto.SEMVER.patch });
expect(execPromise).toHaveBeenNthCalledWith(2, "npx", [
"lerna",
"version",
"1.0.1",
"--force-publish",
"--no-commit-hooks",
"--yes",
"--no-push",
"-m",
"'\"Custom version commit message\"'",
false,
]);
});

test("should publish private scoped packages to private", async () => {
const plugin = new NPMPlugin();
const hooks = makeHooks();
Expand Down
13 changes: 9 additions & 4 deletions plugins/npm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,8 @@ export default class NPMPlugin implements IPlugin {

if (isMonorepo()) {
auto.logger.verbose.info("Detected monorepo, using lerna");
const monorepoVersion = getLernaJson().version;
const lernaJson = getLernaJson();
const monorepoVersion = lernaJson.version;
const isIndependent = monorepoVersion === "independent";

if (dryRun) {
Expand Down Expand Up @@ -995,6 +996,12 @@ export default class NPMPlugin implements IPlugin {
? useVersion || bump
: useVersion || (await bumpLatest(getMonorepoPackage(), bump)) || bump;

const defaultCommitMessage = isIndependent
? "Bump independent versions [skip ci]"
: "Bump version to: %s [skip ci]";
const customCommitMessage = lernaJson.command?.version?.message;
const commitMessage = customCommitMessage ?? defaultCommitMessage;

await execPromise("npx", [
"lerna",
"version",
Expand All @@ -1004,9 +1011,7 @@ export default class NPMPlugin implements IPlugin {
"--yes",
"--no-push",
"-m",
isIndependent
? `'"Bump independent versions [skip ci]"'`
: `'"Bump version to: %s [skip ci]"'`,
`'"${commitMessage}"'`,
this.exact && "--exact",
...verboseArgs,
]);
Expand Down

0 comments on commit 3829561

Please sign in to comment.