Skip to content

Commit

Permalink
Merge pull request #2036 from hydrosquall/cameron.yick/modify-npm-bum…
Browse files Browse the repository at this point in the history
…ping-logic

feat(plugins/npm): exclude pre-release branches from greaterRelease calculation
  • Loading branch information
hipstersmoothie committed Mar 4, 2022
2 parents d715128 + 14b69aa commit 178f55c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions plugins/npm/__tests__/npm.test.ts
Expand Up @@ -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", () => {
Expand Down
9 changes: 8 additions & 1 deletion plugins/npm/src/index.ts
Expand Up @@ -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(
Expand All @@ -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 =
Expand Down

0 comments on commit 178f55c

Please sign in to comment.