Skip to content

Commit

Permalink
fix(npm): don't mark release as latest if in old version branch
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
  • Loading branch information
jazmon and jackw committed Feb 22, 2024
1 parent b122fe8 commit a55aac0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
36 changes: 22 additions & 14 deletions plugins/npm/__tests__/npm.test.ts
Original file line number Diff line number Diff line change
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 Down
17 changes: 14 additions & 3 deletions plugins/npm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1579,8 +1579,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, undefined, !options.isPrerelease);
return auto.git?.publish(
releaseNotes,
tag,
options.isPrerelease,
undefined,
isLatestRelease
);
})
);

Expand All @@ -1604,8 +1613,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 a55aac0

Please sign in to comment.