Skip to content

Commit

Permalink
Fixed invalid attempts to tag packages already tagged on remote (#1369)
Browse files Browse the repository at this point in the history
* Fixed invalid attempts to tag packages already tagged on remote

* rename helper
  • Loading branch information
Andarist authored May 28, 2024
1 parent 954a16a commit d729d8c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-snakes-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

`changeset tag` should now correctly skip tags that exist on the remote
4 changes: 2 additions & 2 deletions packages/cli/src/commands/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { readPreState } from "@changesets/pre";
import { Config, PreState } from "@changesets/types";
import { getPackages } from "@manypkg/get-packages";
import chalk from "chalk";
import { getUntaggedPrivatePackages } from "./getUntaggedPrivatePackages";
import { getUntaggedPackages } from "../../utils/getUntaggedPackages";

function logReleases(pkgs: Array<{ name: string; newVersion: string }>) {
const mappedPkgs = pkgs.map((p) => `${p.name}@${p.newVersion}`).join("\n");
Expand Down Expand Up @@ -72,7 +72,7 @@ export default async function publish(
(pkg) => pkg.packageJson.private && pkg.packageJson.version
);
const untaggedPrivatePackageReleases = tagPrivatePackages
? await getUntaggedPrivatePackages(privatePackages, cwd, tool)
? await getUntaggedPackages(privatePackages, cwd, tool)
: [];

if (
Expand Down
12 changes: 7 additions & 5 deletions packages/cli/src/commands/tag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { log } from "@changesets/logger";
import { shouldSkipPackage } from "@changesets/should-skip-package";
import { Config } from "@changesets/types";
import { getPackages } from "@manypkg/get-packages";
import { getUntaggedPackages } from "../../utils/getUntaggedPackages";

export default async function tag(cwd: string, config: Config) {
const { packages, tool } = await getPackages(cwd);
Expand All @@ -17,11 +18,12 @@ export default async function tag(cwd: string, config: Config) {
})
);

for (const pkg of taggablePackages) {
const tag =
tool !== "root"
? `${pkg.packageJson.name}@${pkg.packageJson.version}`
: `v${pkg.packageJson.version}`;
for (const { name, newVersion } of await getUntaggedPackages(
taggablePackages,
cwd,
tool
)) {
const tag = tool !== "root" ? `${name}@${newVersion}` : `v${newVersion}`;

if (allExistingTags.has(tag)) {
log("Skipping tag (already exists): ", tag);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import * as git from "@changesets/git";
import { Package, Tool } from "@manypkg/get-packages";
import { PublishedResult } from "./publishPackages";
import { PublishedResult } from "../commands/publish/publishPackages";

export async function getUntaggedPrivatePackages(
privatePackages: Package[],
export async function getUntaggedPackages(
packages: Package[],
cwd: string,
tool: Tool
) {
const packageWithTags = await Promise.all(
privatePackages.map(async (privatePkg) => {
packages.map(async (pkg) => {
const tagName =
tool === "root"
? `v${privatePkg.packageJson.version}`
: `${privatePkg.packageJson.name}@${privatePkg.packageJson.version}`;
? `v${pkg.packageJson.version}`
: `${pkg.packageJson.name}@${pkg.packageJson.version}`;
const isMissingTag = !(
(await git.tagExists(tagName, cwd)) ||
(await git.remoteTagExists(tagName))
);

return { pkg: privatePkg, isMissingTag };
return { pkg, isMissingTag };
})
);

Expand Down

0 comments on commit d729d8c

Please sign in to comment.