Skip to content

Commit

Permalink
fix(publish): Ensure pkg.publishConfig is handled correctly when prom…
Browse files Browse the repository at this point in the history
…oting dist-tags
  • Loading branch information
evocateur committed Jan 5, 2019
1 parent 1877def commit af1c2ad
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
@@ -1,4 +1,8 @@
{
"name": "@integration/package-1",
"version": "1.0.0"
"version": "1.0.0",
"publishConfig": {
"access": "public",
"tag": "CUSTOM"
}
}
@@ -1,6 +1,9 @@
{
"name": "@integration/package-2",
"version": "1.0.0",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@integration/package-1": "^1.0.0"
}
Expand Down
39 changes: 25 additions & 14 deletions commands/publish/__tests__/publish-tagging.test.js
Expand Up @@ -55,33 +55,44 @@ test("publish --npm-tag deprecated", async () => {
});

test("publish --temp-tag", async () => {
const cwd = await initFixture("normal");

collectUpdates.setUpdated(cwd, "package-4");
const cwd = await initFixture("integration");

await lernaPublish(cwd)("--temp-tag", "--registry", "test-registry");
await lernaPublish(cwd)("--temp-tag");

expect(npmPublish.registry.get("package-4")).toBe("lerna-temp");
expect(npmPublish.registry).toMatchInlineSnapshot(`
Map {
"@integration/package-1" => "lerna-temp",
"@integration/package-2" => "lerna-temp",
}
`);

const conf = expect.objectContaining({
registry: "test-registry",
tag: "latest",
});
expect(npmDistTag.remove).toHaveBeenCalledWith("package-4@1.0.1", "lerna-temp", conf);
expect(npmDistTag.add).toHaveBeenCalledWith("package-4@1.0.1", "latest", conf);

expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-1@1.0.1", "lerna-temp", conf);
expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-2@1.0.1", "lerna-temp", conf);

expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "CUSTOM", conf); // <--
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "latest", conf);
});

test("publish --dist-tag beta --temp-tag", async () => {
const cwd = await initFixture("normal");

collectUpdates.setUpdated(cwd, "package-1");
const cwd = await initFixture("integration");

await lernaPublish(cwd)("--dist-tag", "beta", "--temp-tag");

expect(npmPublish.registry.get("package-1")).toBe("lerna-temp");
expect(npmPublish.registry).toMatchInlineSnapshot(`
Map {
"@integration/package-1" => "lerna-temp",
"@integration/package-2" => "lerna-temp",
}
`);

const conf = expect.objectContaining({
tag: "beta",
});
expect(npmDistTag.remove).toHaveBeenCalledWith("package-1@1.0.1", "lerna-temp", conf);
expect(npmDistTag.add).toHaveBeenCalledWith("package-1@1.0.1", "beta", conf);

expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "beta", conf); // <--
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "beta", conf);
});
9 changes: 8 additions & 1 deletion commands/publish/index.js
Expand Up @@ -604,7 +604,6 @@ class PublishCommand extends Command {
}

npmUpdateAsLatest() {
const distTag = this.conf.get("tag");
const tracker = this.logger.newItem("npmUpdateAsLatest");

tracker.addWork(this.packagesToPublish.length);
Expand All @@ -613,8 +612,16 @@ class PublishCommand extends Command {
let chain = Promise.resolve();

const opts = this.conf.snapshot;
const getDistTag = publishConfig => {
if (opts.tag === "latest" && publishConfig && publishConfig.tag) {
return publishConfig.tag;
}

return opts.tag;
};
const mapper = pkg => {
const spec = `${pkg.name}@${pkg.version}`;
const distTag = getDistTag(pkg.get("publishConfig"));

return Promise.resolve()
.then(() => pulseTillDone(npmDistTag.remove(spec, "lerna-temp", opts)))
Expand Down

0 comments on commit af1c2ad

Please sign in to comment.