Skip to content

Commit

Permalink
fix(publish): Allow --force-publish in a canary release
Browse files Browse the repository at this point in the history
Fixes #1638
  • Loading branch information
evocateur committed Sep 12, 2018
1 parent 7971bf3 commit b97d9a3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
41 changes: 41 additions & 0 deletions commands/publish/__tests__/publish-canary.test.js
Expand Up @@ -299,6 +299,47 @@ test("publish --canary on tagged release exits early", async () => {
expect(logMessages).toContain("No changed packages to publish");
});

test("publish --canary --force-publish on tagged release avoids early exit", async () => {
const cwd = await initTaggedFixture("normal");

await lernaPublish(cwd)("--canary", "--force-publish");

const logMessages = loggingOutput("warn");
expect(logMessages).toContain("all packages");
// lerna WARN force-publish all packages

expect(writePkg.updatedVersions()).toMatchInlineSnapshot(`
Object {
"package-1": 1.0.1-alpha.0+SHA,
"package-2": 1.0.1-alpha.0+SHA,
"package-3": 1.0.1-alpha.0+SHA,
"package-4": 1.0.1-alpha.0+SHA,
}
`);
});

test("publish --canary --force-publish <arg> on tagged release avoids early exit", async () => {
const cwd = await initTaggedFixture("independent");

// canary committish needs to have a parent, but still tagged on same revision
await setupChanges(cwd, ["packages/package-5/arbitrary.js", "change"]);
await gitTag(cwd, "package-5@5.0.1");

// there are no _actual_ changes to package-2 or any of its dependencies
await lernaPublish(cwd)("--canary", "--force-publish", "package-2");

const logMessages = loggingOutput("warn");
expect(logMessages).toContain("package-2");
// lerna WARN force-publish package-2

expect(writePkg.updatedVersions()).toMatchInlineSnapshot(`
Object {
"package-2": 2.0.1-alpha.0+SHA,
"package-3": 3.0.1-alpha.0+SHA,
}
`);
});

test("publish --canary with dirty tree throws error", async () => {
checkWorkingTree.throwIfUncommitted.mockImplementationOnce(() => {
throw new Error("uncommitted");
Expand Down
11 changes: 9 additions & 2 deletions commands/publish/index.js
Expand Up @@ -195,7 +195,13 @@ class PublishCommand extends Command {
}

detectCanaryVersions() {
const { bump = "prepatch", preid = "alpha", tagVersionPrefix = "v", ignoreChanges } = this.options;
const {
bump = "prepatch",
preid = "alpha",
tagVersionPrefix = "v",
ignoreChanges,
forcePublish,
} = this.options;
// "prerelease" and "prepatch" are identical, for our purposes
const release = bump.startsWith("pre") ? bump.replace("release", "patch") : `pre${bump}`;

Expand All @@ -210,6 +216,7 @@ class PublishCommand extends Command {
bump: "prerelease",
canary: true,
ignoreChanges,
forcePublish,
})
);

Expand All @@ -219,7 +226,7 @@ class PublishCommand extends Command {

// semver.inc() starts a new prerelease at .0, git describe starts at .1
// and build metadata is always ignored when comparing dependency ranges
return `${nextVersion}-${preid}.${refCount - 1}+${sha}`;
return `${nextVersion}-${preid}.${Math.max(0, refCount - 1)}+${sha}`;
};

if (this.project.isIndependent()) {
Expand Down
5 changes: 5 additions & 0 deletions utils/collect-updates/collect-updates.js
Expand Up @@ -43,6 +43,11 @@ function collectUpdates(filteredPackages, packageGraph, execOpts, commandOptions

log.info("", `Looking for changed packages since ${committish || "initial commit."}`);

if (forced.size) {
// "warn" might seem a bit loud, but it is appropriate for logging anything _forced_
log.warn("force-publish", forced.has("*") ? "all packages" : Array.from(forced.values()).join("\n"));
}

let candidates;

if (!committish || forced.has("*")) {
Expand Down

0 comments on commit b97d9a3

Please sign in to comment.