CLI arguments should take precedence over `package.json#publishConfig`


(Pierre Vanduynslager) #1

What I Wanted to Do

I have the following configuration in my package.json:

{
  "publishConfig": {
    "tag": "next"
  }
}

So when I run npm publish the package is publish with the dist-tag @next, which is my most common scenario.
However if I want to publish a version on a different dist-tag, for example @beta I would do npm publish --tag beta.

What Happened Instead

The package is published on @next and not @beta. It seems npm give priority to package.json#publishConfig over CLI arguments.

This is quite unexpected as most tools would give priority to CLI arguments over configuration files. This allow to have a workflow like:

  • For my common/frequent case, pass no argument to the CLI and use the config file
  • For my uncommon/unfrequent case, pass arguments to the CLI to override the config parameters

Reproduction Steps

Create a new npm package and add the following to the package.json:

{
  "publishConfig": {
    "tag": "next"
  }
}

Run npm publish --tag beta.
Check the dist-tag on which the package is available with npm view <my-package>.

Platform Info

$ npm --versions
6.4.1
$ node -p process.platform
darwin

(Alan) #2

I, and many others, would argue this is not an “idea” but a “bug”, related issue: