diff --git a/commands/publish/__tests__/publish-canary.test.js b/commands/publish/__tests__/publish-canary.test.js index 3cf5984033..e8858e177d 100644 --- a/commands/publish/__tests__/publish-canary.test.js +++ b/commands/publish/__tests__/publish-canary.test.js @@ -373,3 +373,31 @@ test("publish --canary --include-merged-tags calls git describe correctly", asyn expect.objectContaining({ cwd }) ); }); + +test("publish --canary without _any_ tags", async () => { + const cwd = await initFixture("normal"); + await lernaPublish(cwd)("--canary"); + + 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 without _any_ tags (independent)", async () => { + const cwd = await initFixture("independent"); + await lernaPublish(cwd)("--canary"); + + expect(writePkg.updatedVersions()).toMatchInlineSnapshot(` + Object { + "package-1": 1.0.1-alpha.0+SHA, + "package-2": 2.0.1-alpha.0+SHA, + "package-3": 3.0.1-alpha.0+SHA, + "package-4": 4.0.1-alpha.0+SHA, + } + `); +}); diff --git a/commands/publish/index.js b/commands/publish/index.js index 07d99dd7c2..8cc8eea0f1 100644 --- a/commands/publish/index.js +++ b/commands/publish/index.js @@ -390,7 +390,10 @@ class PublishCommand extends Command { }, includeMergedTags ) - .then(makeVersion) + .then(({ lastVersion = this.project.version, refCount, sha }) => + // a repo with no tags should default to whatever lerna.json claims + makeVersion({ lastVersion, refCount, sha }) + ) .then(version => updates.map(({ pkg }) => [pkg.name, version])) .then(updatesVersions => ({ updates,