Skip to content

Commit

Permalink
Create a simple tag for single-package projects (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed May 24, 2020
1 parent 6d0790a commit 5dc389f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fixtures from "fixturez";

import publishPackages from "../publishPackages";
import * as npmUtils from "../npm-utils";
import { getPackages } from "@manypkg/get-packages";

jest.mock("../npm-utils");
jest.mock("is-ci", () => true);
Expand Down Expand Up @@ -34,7 +35,11 @@ describe("publishPackages", () => {

describe("when isCI", () => {
it("does not call out to npm to see if otp is required", async () => {
await publishPackages({ cwd, access: "public", preState: undefined });
await publishPackages({
packages: (await getPackages(cwd)).packages,
access: "public",
preState: undefined
});
expect(npmUtils.getTokenIsRequired).not.toHaveBeenCalled();
});
});
Expand Down
17 changes: 13 additions & 4 deletions packages/cli/src/commands/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { error, log, success, warn } from "@changesets/logger";
import * as git from "@changesets/git";
import { readPreState } from "@changesets/pre";
import { Config, PreState } from "@changesets/types";
import { getPackages } from "@manypkg/get-packages";
import chalk from "chalk";

function logReleases(pkgs: Array<{ name: string; newVersion: string }>) {
Expand Down Expand Up @@ -54,8 +55,10 @@ export default async function run(
showNonLatestTagWarning(tag, preState);
}

const { packages } = await getPackages(cwd);

const response = await publishPackages({
cwd,
packages,
// if not public, we wont pass the access, and it works as normal
access: config.access,
otp,
Expand All @@ -72,9 +75,15 @@ export default async function run(
// We create the tags after the push above so that we know that HEAD wont change and that pushing
// wont suffer from a race condition if another merge happens in the mean time (pushing tags wont
// fail if we are behind master).
log("Creating git tags...");
for (const pkg of successful) {
const tag = `${pkg.name}@${pkg.newVersion}`;
log(`Creating git tag${successful.length > 1 ? "s" : ""}...`);
if (packages.length > 1) {
for (const pkg of successful) {
const tag = `${pkg.name}@${pkg.newVersion}`;
log("New tag: ", tag);
await git.tag(tag, cwd);
}
} else {
const tag = `v${successful[0].newVersion}`;
log("New tag: ", tag);
await git.tag(tag, cwd);
}
Expand Down
15 changes: 5 additions & 10 deletions packages/cli/src/commands/publish/publishPackages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import semver from "semver";
import chalk from "chalk";
import { AccessType } from "@changesets/types";
import { getPackages, Package } from "@manypkg/get-packages";
import { Package } from "@manypkg/get-packages";
import * as npmUtils from "./npm-utils";
import { info, warn } from "@changesets/logger";
import { TwoFactorState } from "../../utils/types";
Expand All @@ -19,25 +19,20 @@ function getReleaseTag(pkgInfo: PkgInfo, preState?: PreState, tag?: string) {
}

export default async function publishPackages({
cwd,
packages,
access,
otp,
preState,
tag
}: {
cwd: string;
packages: Package[];
access: AccessType;
otp?: string;
preState: PreState | undefined;
tag?: string;
}) {
const packages = await getPackages(cwd);
const packagesByName = new Map(
packages.packages.map(x => [x.packageJson.name, x])
);
const publicPackages = packages.packages.filter(
pkg => !pkg.packageJson.private
);
const packagesByName = new Map(packages.map(x => [x.packageJson.name, x]));
const publicPackages = packages.filter(pkg => !pkg.packageJson.private);
let twoFactorState: TwoFactorState =
otp === undefined
? {
Expand Down

0 comments on commit 5dc389f

Please sign in to comment.