Skip to content

Commit b4464d5

Browse files
Merge pull request #2414 from jazmon/fix-latest-release-lerna-monorepo
fix(npm): mark releases as latest with lerna
2 parents 6426278 + a55aac0 commit b4464d5

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

plugins/npm/__tests__/npm.test.ts

+28-16
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,16 @@ const monorepoPackagesWithPrereleaseResult = [
5050
{ path: "packages/c", name: "@packages/c", package: { version: "0.1.2" } },
5151
{ path: "packages/d", name: "@packages/d", package: { version: "0.1.1" } },
5252
// This can happen if a new module is published with a breaking version
53-
{ path: "packages/e", name: "@packages/e", package: { version: "1.0.0-next.0" } },
54-
{ path: "packages/f", name: "@packages/f", package: { version: "1.0.0-next.0" } },
53+
{
54+
path: "packages/e",
55+
name: "@packages/e",
56+
package: { version: "1.0.0-next.0" },
57+
},
58+
{
59+
path: "packages/f",
60+
name: "@packages/f",
61+
package: { version: "1.0.0-next.0" },
62+
},
5563
];
5664

5765
const packageTemplate = ({
@@ -406,7 +414,7 @@ describe("getPreviousVersion", () => {
406414
});
407415

408416
test("should ignore greatest published monorepo package in maintenance mode", async () => {
409-
execPromise.mockClear()
417+
execPromise.mockClear();
410418
mockFs({
411419
"lerna.json": `
412420
{
@@ -424,21 +432,19 @@ describe("getPreviousVersion", () => {
424432
// published version of test package
425433
execPromise.mockReturnValueOnce("2.1.0");
426434

427-
jest.spyOn(Auto, 'getCurrentBranch').mockReturnValueOnce('major-2')
428-
435+
jest.spyOn(Auto, "getCurrentBranch").mockReturnValueOnce("major-2");
429436

430437
plugin.apply({
431-
config: { prereleaseBranches: ["next"], versionBranches: 'major-' },
438+
config: { prereleaseBranches: ["next"], versionBranches: "major-" },
432439
hooks,
433440
remote: "origin",
434441
baseBranch: "main",
435442
logger: dummyLog(),
436443
prefixRelease: (str) => str,
437444
} as Auto.Auto);
438445

439-
440446
expect(await hooks.getPreviousVersion.promise()).toBe("1.5.0");
441-
expect(execPromise).not.toHaveBeenCalled()
447+
expect(execPromise).not.toHaveBeenCalled();
442448
});
443449
});
444450

@@ -681,7 +687,7 @@ describe("publish", () => {
681687
"--yes",
682688
"from-package",
683689
"--exact",
684-
"--no-verify-access"
690+
"--no-verify-access",
685691
]);
686692
});
687693

@@ -704,7 +710,7 @@ describe("publish", () => {
704710
"--yes",
705711
"from-package",
706712
false,
707-
"--no-verify-access"
713+
"--no-verify-access",
708714
]);
709715
});
710716

@@ -730,7 +736,7 @@ describe("publish", () => {
730736
false,
731737
"--legacy-auth",
732738
"abcd",
733-
"--no-verify-access"
739+
"--no-verify-access",
734740
]);
735741
});
736742

@@ -755,7 +761,7 @@ describe("publish", () => {
755761
false,
756762
"--contents",
757763
"dist/publish-folder",
758-
"--no-verify-access"
764+
"--no-verify-access",
759765
]);
760766
});
761767

@@ -1258,7 +1264,7 @@ describe("canary", () => {
12581264
"--no-git-reset",
12591265
"--no-git-tag-version",
12601266
"--exact",
1261-
"--no-verify-access"
1267+
"--no-verify-access",
12621268
]);
12631269
});
12641270

@@ -1429,7 +1435,7 @@ describe("canary", () => {
14291435
"--no-git-reset",
14301436
"--no-git-tag-version",
14311437
"--exact",
1432-
"--no-verify-access"
1438+
"--no-verify-access",
14331439
]);
14341440
});
14351441

@@ -1650,6 +1656,7 @@ describe("makeRelease", () => {
16501656
logger: dummyLog(),
16511657
prefixRelease: (str) => str,
16521658
git: { publish } as any,
1659+
inOldVersionBranch: (bool: boolean) => bool,
16531660
release: {
16541661
makeChangelog: () => ({
16551662
generateReleaseNotes: (commits: IExtendedCommit[]) =>
@@ -1661,6 +1668,7 @@ describe("makeRelease", () => {
16611668
await hooks.makeRelease.promise({
16621669
newVersion: "0.1.2",
16631670
from: "",
1671+
to: "",
16641672
isPrerelease: false,
16651673
fullReleaseNotes: "",
16661674
commits: [
@@ -1684,12 +1692,16 @@ describe("makeRelease", () => {
16841692
expect(publish).toHaveBeenCalledWith(
16851693
"update package 1",
16861694
"@packages/a",
1687-
false
1695+
false,
1696+
undefined,
1697+
true
16881698
);
16891699
expect(publish).toHaveBeenCalledWith(
16901700
"update package 2",
16911701
"@packages/b",
1692-
false
1702+
false,
1703+
undefined,
1704+
true
16931705
);
16941706
});
16951707
});

plugins/npm/src/index.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1577,8 +1577,17 @@ export default class NPMPlugin implements IPlugin {
15771577

15781578
auto.logger.log.info(`Using release notes:\n${releaseNotes}`);
15791579

1580+
const isLatestRelease =
1581+
!options.isPrerelease || !auto.inOldVersionBranch();
1582+
15801583
// 2. make a release for just that package
1581-
return auto.git?.publish(releaseNotes, tag, options.isPrerelease);
1584+
return auto.git?.publish(
1585+
releaseNotes,
1586+
tag,
1587+
options.isPrerelease,
1588+
undefined,
1589+
isLatestRelease
1590+
);
15821591
})
15831592
);
15841593

@@ -1602,8 +1611,10 @@ export default class NPMPlugin implements IPlugin {
16021611
await execPromise("npm", ["root"]);
16031612
} catch (error) {
16041613
if (
1605-
// eslint-disable-next-line no-template-curly-in-string
1606-
error.message?.includes("Failed to replace env in config: ${NPM_TOKEN}")
1614+
(error as Error).message?.includes(
1615+
// eslint-disable-next-line no-template-curly-in-string
1616+
"Failed to replace env in config: ${NPM_TOKEN}"
1617+
)
16071618
) {
16081619
auto.logger.log.error(endent`
16091620
Uh oh! It looks like you don\'t have a NPM_TOKEN available in your environment.

0 commit comments

Comments
 (0)