From 90b8ae966fe0cd7c6aa1e7863bc39e992d7c5de1 Mon Sep 17 00:00:00 2001 From: Cameron Yick Date: Thu, 22 Jul 2021 13:48:48 -0400 Subject: [PATCH 1/2] feat(plugins/npm): exclude pre-release branches from greaterRelease calculation --- plugins/npm/src/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/npm/src/index.ts b/plugins/npm/src/index.ts index 0cfa8cb50..cdabd4975 100644 --- a/plugins/npm/src/index.ts +++ b/plugins/npm/src/index.ts @@ -52,7 +52,7 @@ async function getPublishedVersion(name: string) { } /** - * Determine the greatest version between last published version of a + * Determine the greatest version between @latest published version of a * package and the version in the package.json. */ export async function greaterRelease( @@ -67,6 +67,13 @@ export async function greaterRelease( return packageVersion; } + // If @latest published version is a pre-release, + // this means the package has not been published as a stable tag yet + // Prefer local version to prevent a new package from adjusting the versions for a whole monorepo. + if (prerelease(publishedVersion) !== null) { + return packageVersion; + } + const publishedPrefixed = prefixRelease(publishedVersion); // The branch (ex: next) is also the --preid const baseVersion = From 14b69aabba4c4bb0b678a0587c0204d9aee2fc57 Mon Sep 17 00:00:00 2001 From: Cameron Yick Date: Thu, 22 Jul 2021 15:01:28 -0400 Subject: [PATCH 2/2] test(plugins/npm): test public pre-releases cannot be greater than local version --- plugins/npm/__tests__/npm.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/npm/__tests__/npm.test.ts b/plugins/npm/__tests__/npm.test.ts index 453b1cf7e..b498daa94 100644 --- a/plugins/npm/__tests__/npm.test.ts +++ b/plugins/npm/__tests__/npm.test.ts @@ -183,6 +183,12 @@ describe("greaterRelease", () => { await greaterRelease(prefixRelease, "test-package-name", "1.0.0") ).toBe("1.0.1"); }); + test("should default to packageVersion if (publishedVersion is greater, but is a pre-release)", async () => { + execPromise.mockReturnValueOnce("1.0.1-next.0"); + expect( + await greaterRelease(prefixRelease, "test-package-name", "1.0.0") + ).toBe("1.0.0"); + }); }); describe("getAuthor", () => {