Skip to content

Commit

Permalink
fix(publish): Deprecate --npm-tag, replaced by --dist-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Jan 4, 2019
1 parent 7a65a87 commit 196d663
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 13 deletions.
8 changes: 4 additions & 4 deletions commands/publish/README.md
Expand Up @@ -51,7 +51,7 @@ This is useful when a previous `lerna publish` failed to publish all packages to

- [`--canary`](#--canary)
- [`--contents <dir>`](#--contents-dir)
- [`--npm-tag <dist-tag>`](#--npm-tag-dist-tag)
- [`--dist-tag <tag>`](#--dist-tag-tag)
- [`--no-git-reset`](#--no-git-reset)
- [`--no-verify-access`](#--no-verify-access)
- [`--registry <url>`](#--registry-url)
Expand Down Expand Up @@ -91,10 +91,10 @@ lerna publish --contents dist
# publish the "dist" subfolder of every Lerna-managed leaf package
```

### `--npm-tag <dist-tag>`
### `--dist-tag <tag>`

```sh
lerna publish --npm-tag next
lerna publish --dist-tag next
```

When run with this flag, `lerna publish` will publish to npm with the given npm [dist-tag](https://docs.npmjs.com/cli/dist-tag) (defaults to `latest`).
Expand Down Expand Up @@ -134,7 +134,7 @@ private registries.

When passed, this flag will alter the default publish process by first publishing
all changed packages to a temporary dist-tag (`lerna-temp`) and then moving the
new version(s) to the dist-tag configured by [`--npm-tag`](#--npm-tag-dist-tag) (default `latest`).
new version(s) to the dist-tag configured by [`--dist-tag`](#--dist-tag-tag) (default `latest`).

This is not generally necessary, as Lerna will publish packages in topological
order (all dependencies before dependents) by default.
Expand Down
48 changes: 43 additions & 5 deletions commands/publish/__tests__/publish-tagging.test.js
Expand Up @@ -21,14 +21,36 @@ const initFixture = require("@lerna-test/init-fixture")(__dirname);
// test command
const lernaPublish = require("@lerna-test/command-runner")(require("../command"));

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

collectUpdates.setUpdated(cwd, "package-1");

await lernaPublish(cwd)("--dist-tag", "next");

expect(npmPublish.registry.get("package-1")).toBe("next");
expect(npmDistTag.remove).not.toHaveBeenCalled();
});

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

collectUpdates.setUpdated(cwd, "package-2");

await lernaPublish(cwd)("--dist-tag", "nightly", "--canary");

expect(npmPublish.registry.get("package-2")).toBe("nightly");
expect(npmDistTag.remove).not.toHaveBeenCalled();
});

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

collectUpdates.setUpdated(cwd, "package-3");

await lernaPublish(cwd)("--npm-tag", "custom");
await lernaPublish(cwd)("--npm-tag", "deprecated");

expect(npmPublish.registry.get("package-3")).toBe("custom");
expect(npmPublish.registry.get("package-3")).toBe("deprecated");
expect(npmDistTag.remove).not.toHaveBeenCalled();
});

Expand All @@ -44,6 +66,22 @@ test("publish --temp-tag", async () => {
const conf = expect.objectContaining({
registry: "test-registry",
});
expect(npmDistTag.remove).toHaveBeenLastCalledWith("package-4@1.0.1", "lerna-temp", conf);
expect(npmDistTag.add).toHaveBeenLastCalledWith("package-4@1.0.1", "latest", conf);
expect(npmDistTag.remove).toHaveBeenCalledWith("package-4@1.0.1", "lerna-temp", conf);
expect(npmDistTag.add).toHaveBeenCalledWith("package-4@1.0.1", "latest", conf);
});

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

collectUpdates.setUpdated(cwd, "package-1");

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

expect(npmPublish.registry.get("package-1")).toBe("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);
});
23 changes: 22 additions & 1 deletion commands/publish/command.js
@@ -1,5 +1,6 @@
"use strict";

const log = require("libnpm/log");
const versionCommand = require("@lerna/version/command");

/**
Expand Down Expand Up @@ -29,7 +30,7 @@ exports.builder = yargs => {
requiresArg: true,
defaultDescription: ".",
},
"npm-tag": {
"dist-tag": {
describe: "Publish packages with the specified npm dist-tag",
type: "string",
requiresArg: true,
Expand Down Expand Up @@ -79,6 +80,13 @@ exports.builder = yargs => {
yargs.group(Object.keys(opts).concat(sharedKeys), "Command Options:");

return yargs
.option("npm-tag", {
// TODO: remove in next major release
hidden: true,
conflicts: "dist-tag",
type: "string",
requiresArg: true,
})
.option("verify-registry", {
// TODO: remove in next major release
hidden: true,
Expand All @@ -89,6 +97,19 @@ exports.builder = yargs => {
// deprecation notice handled in initialize()
hidden: true,
type: "boolean",
})
.check(argv => {
/* eslint-disable no-param-reassign */
if (argv.npmTag) {
argv.distTag = argv.npmTag;
argv["dist-tag"] = argv.npmTag;
delete argv.npmTag;
delete argv["npm-tag"];
log.warn("deprecated", "--npm-tag has been renamed --dist-tag");
}
/* eslint-enable no-param-reassign */

return argv;
});
};

Expand Down
6 changes: 3 additions & 3 deletions commands/publish/index.js
Expand Up @@ -93,7 +93,7 @@ class PublishCommand extends Command {
this.conf.set("registry", "https://registry.npmjs.org/", "cli");
}

// inject --npm-tag into opts, if present
// inject --dist-tag into opts, if present
const distTag = this.getDistTag();

if (distTag) {
Expand Down Expand Up @@ -629,8 +629,8 @@ class PublishCommand extends Command {
}

getDistTag() {
if (this.options.npmTag) {
return this.options.npmTag;
if (this.options.distTag) {
return this.options.distTag;
}

if (this.options.canary) {
Expand Down
1 change: 1 addition & 0 deletions core/project/__fixtures__/extends-deprecated/base.json
Expand Up @@ -5,6 +5,7 @@
"command": {
"publish": {
"cdVersion": "major",
"npmTag": "ignored",
"loglevel": "success"
}
},
Expand Down
1 change: 1 addition & 0 deletions core/project/__fixtures__/extends-deprecated/lerna.json
Expand Up @@ -5,5 +5,6 @@
"hoist": true
}
},
"npmTag": "next",
"version": "1.0.0"
}
1 change: 1 addition & 0 deletions core/project/__tests__/project.test.js
Expand Up @@ -152,6 +152,7 @@ Object {
},
"publish": Object {
"bump": "prerelease",
"distTag": "next",
"ignoreChanges": Array [
"ignored-file",
],
Expand Down
1 change: 1 addition & 0 deletions core/project/lib/deprecate-config.js
Expand Up @@ -6,6 +6,7 @@ const path = require("path");

module.exports = compose(
// add new predicates HERE
remap("command.publish.npmTag", "command.publish.distTag", { alsoRoot: true }),
remap("command.publish.cdVersion", "command.publish.bump", { alsoRoot: true }),
remap("command.publish.ignore", "command.publish.ignoreChanges"),
remap("commands", "command"),
Expand Down

0 comments on commit 196d663

Please sign in to comment.