diff --git a/plugins/npm/__tests__/npm.test.ts b/plugins/npm/__tests__/npm.test.ts index 276e26e88..4504aa369 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", () => { diff --git a/plugins/npm/src/index.ts b/plugins/npm/src/index.ts index f9dc7e4c7..d591a8785 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 =