Skip to content

Commit

Permalink
Merge pull request #2414 from jazmon/fix-latest-release-lerna-monorepo
Browse files Browse the repository at this point in the history
fix(npm): mark releases as latest with lerna
  • Loading branch information
hipstersmoothie committed Feb 22, 2024
2 parents 6426278 + a55aac0 commit b4464d5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
44 changes: 28 additions & 16 deletions plugins/npm/__tests__/npm.test.ts
Expand Up @@ -50,8 +50,16 @@ const monorepoPackagesWithPrereleaseResult = [
{ path: "packages/c", name: "@packages/c", package: { version: "0.1.2" } },
{ path: "packages/d", name: "@packages/d", package: { version: "0.1.1" } },
// This can happen if a new module is published with a breaking version
{ path: "packages/e", name: "@packages/e", package: { version: "1.0.0-next.0" } },
{ path: "packages/f", name: "@packages/f", package: { version: "1.0.0-next.0" } },
{
path: "packages/e",
name: "@packages/e",
package: { version: "1.0.0-next.0" },
},
{
path: "packages/f",
name: "@packages/f",
package: { version: "1.0.0-next.0" },
},
];

const packageTemplate = ({
Expand Down Expand Up @@ -406,7 +414,7 @@ describe("getPreviousVersion", () => {
});

test("should ignore greatest published monorepo package in maintenance mode", async () => {
execPromise.mockClear()
execPromise.mockClear();
mockFs({
"lerna.json": `
{
Expand All @@ -424,21 +432,19 @@ describe("getPreviousVersion", () => {
// published version of test package
execPromise.mockReturnValueOnce("2.1.0");

jest.spyOn(Auto, 'getCurrentBranch').mockReturnValueOnce('major-2')

jest.spyOn(Auto, "getCurrentBranch").mockReturnValueOnce("major-2");

plugin.apply({
config: { prereleaseBranches: ["next"], versionBranches: 'major-' },
config: { prereleaseBranches: ["next"], versionBranches: "major-" },
hooks,
remote: "origin",
baseBranch: "main",
logger: dummyLog(),
prefixRelease: (str) => str,
} as Auto.Auto);


expect(await hooks.getPreviousVersion.promise()).toBe("1.5.0");
expect(execPromise).not.toHaveBeenCalled()
expect(execPromise).not.toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -681,7 +687,7 @@ describe("publish", () => {
"--yes",
"from-package",
"--exact",
"--no-verify-access"
"--no-verify-access",
]);
});

Expand All @@ -704,7 +710,7 @@ describe("publish", () => {
"--yes",
"from-package",
false,
"--no-verify-access"
"--no-verify-access",
]);
});

Expand All @@ -730,7 +736,7 @@ describe("publish", () => {
false,
"--legacy-auth",
"abcd",
"--no-verify-access"
"--no-verify-access",
]);
});

Expand All @@ -755,7 +761,7 @@ describe("publish", () => {
false,
"--contents",
"dist/publish-folder",
"--no-verify-access"
"--no-verify-access",
]);
});

Expand Down Expand Up @@ -1258,7 +1264,7 @@ describe("canary", () => {
"--no-git-reset",
"--no-git-tag-version",
"--exact",
"--no-verify-access"
"--no-verify-access",
]);
});

Expand Down Expand Up @@ -1429,7 +1435,7 @@ describe("canary", () => {
"--no-git-reset",
"--no-git-tag-version",
"--exact",
"--no-verify-access"
"--no-verify-access",
]);
});

Expand Down Expand Up @@ -1650,6 +1656,7 @@ describe("makeRelease", () => {
logger: dummyLog(),
prefixRelease: (str) => str,
git: { publish } as any,
inOldVersionBranch: (bool: boolean) => bool,
release: {
makeChangelog: () => ({
generateReleaseNotes: (commits: IExtendedCommit[]) =>
Expand All @@ -1661,6 +1668,7 @@ describe("makeRelease", () => {
await hooks.makeRelease.promise({
newVersion: "0.1.2",
from: "",
to: "",
isPrerelease: false,
fullReleaseNotes: "",
commits: [
Expand All @@ -1684,12 +1692,16 @@ describe("makeRelease", () => {
expect(publish).toHaveBeenCalledWith(
"update package 1",
"@packages/a",
false
false,
undefined,
true
);
expect(publish).toHaveBeenCalledWith(
"update package 2",
"@packages/b",
false
false,
undefined,
true
);
});
});
Expand Down
17 changes: 14 additions & 3 deletions plugins/npm/src/index.ts
Expand Up @@ -1577,8 +1577,17 @@ export default class NPMPlugin implements IPlugin {

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

const isLatestRelease =
!options.isPrerelease || !auto.inOldVersionBranch();

// 2. make a release for just that package
return auto.git?.publish(releaseNotes, tag, options.isPrerelease);
return auto.git?.publish(
releaseNotes,
tag,
options.isPrerelease,
undefined,
isLatestRelease
);
})
);

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

0 comments on commit b4464d5

Please sign in to comment.