Skip to content

Commit

Permalink
Update package script to throw for existing NPM packages (#895)
Browse files Browse the repository at this point in the history
* Update package script to throw for existing NPM packages

* changeset
  • Loading branch information
nihalbhatnagar authored Oct 22, 2024
1 parent d3b3f35 commit c170ecd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eleven-kids-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/tool.release": patch
---

Throws error when trying to generate PR with package versions that are already published to NPM
2 changes: 1 addition & 1 deletion packages/tool.release/src/publishPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function publishSinglePackage(
};
}

async function packageVersionsOrEmptySet(name: string) {
export async function packageVersionsOrEmptySet(name: string) {
try {
return await packageVersionsOrThrow(name);
} catch (e) {
Expand Down
10 changes: 10 additions & 0 deletions packages/tool.release/src/runVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { createOrUpdatePr } from "./createOrUpdatePr.js";
import { FailedWithUserMessage } from "./FailedWithUserMessage.js";
import * as gitUtils from "./gitUtils.js";
import { mutateReleasePlan } from "./mutateReleasePlan.js";
import { packageVersionsOrEmptySet } from "./publishPackages.js";
import { getChangedPackages } from "./util/getChangedPackages.js";
import { getVersionPrBody } from "./util/getVersionPrBody.js";
import { getVersionsByDirectory } from "./util/getVersionsByDirectory.js";
Expand Down Expand Up @@ -167,6 +168,15 @@ export async function runVersion({

mutateReleasePlan(releasePlan, isMainBranch ? "main" : "patch");

for (const release of releasePlan.releases) {
const versions = await packageVersionsOrEmptySet(release.name);
if (versions.has(release.newVersion)) {
throw new FailedWithUserMessage(
`The version ${release.newVersion} of ${release.name} is already published on npm`,
);
}
}

const touchedFiles = await applyReleasePlan(
releasePlan,
packages,
Expand Down

0 comments on commit c170ecd

Please sign in to comment.