Yarn: Support --registry flag from CLI commands

Created on 12 Oct 2016  路  23Comments  路  Source: yarnpkg/yarn

Do you want to request a _feature_ or report a _bug_?

yes, feature

What is the current behavior?

Only global config is available for setting registry

What is the expected behavior?

yarg add/install --registry https://custom.registry works

Please mention your node.js, yarn and operating system version.

Node. 6.4.0
macOS. 10.11
yarn. 0.15.1

cat-compatibility cat-feature good first issue help wanted triaged

Most helpful comment

You can use env variables.

YARN_REGISTRY=my-registry.com yarn install

All 23 comments

Having a CLI flag for this is a bad idea. Imagine if you forget the registry flag and publish an internal package to the public registry. I would instead recommend Yarn support the publishConfig property in package.json. You could then just add "publishConfig":{"registry":"http://my-internal-registry.local"} to package.json.

Imagine if you forget the registry flag and publish an internal package to the public registry

It always happens if people are careless even if they use something like publishConfig. what if I thought I added this property but I just didn't really add it.

And using --registry is more for installing not publishing.

It is necessary for network environment of China.

yarn should support everything npm does, full stop - publishConfig, --registry, registry set in the npmrc, and/or registry set by any of the env vars that npm looks for.

Has there been any update on this since October?
It's necessary for projects in my company to migrate to Yarn.

You can add an .npmrc file?

Sure.
All our projects that publish modules look like this:

.npmrc

registry=http://registry/a
stric-ssl=false
_auth=XXXXXXXXXXXXXXXXX

.yarnrc

registry "http://registry/a"

package.json

{
  "name": "yarn-issue",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "devDependencies": {
    "foo": "0.0.0"
  },
  "publishConfig": {
    "registry": "http://registry/b"
  },
  "author": "",
  "license": "ISC"
}

Here both Yarn and npm will try to fetch foo from registry/a, however only npm will consider the publishConfig and try to publish on registry/b.

Ah, yarn doesn't respect pubilshConfig... Didn't know! I still publish using npm (habit, I suppose), so haven't hit that one

Just send a PR for --registry, FYI though that config.getOption('registry') is used in multiple places

Any news here?

We received no pull requests, and our attention was focused on other features, so no.

So currently there is no way to publish package in repo different from one defined in .npmrc or .yarnrc?

@Eladriell have you found any workaround?

You can use env variables.

YARN_REGISTRY=my-registry.com yarn install

yep that works.
another workaround is to specify the full url of the package with the registry you want to install.

anyway, I'm on it.

would be happy to get some review and feedback on https://github.com/yarnpkg/yarn/pull/4238

@bestander @arcanis can I get some 鉂わ笍 on the PR? :-)

I can confirm yarn publish --registry https://my-custom-registry.com/.../ is working now (1.2.1).
What's missing is a way to override the registry of a scoped package.
This still is a reason to have both yarn and npm in our environment. I really would like to change that.
With npm we are deploying with the command

npm publish --@myscope:registry=https://my-custom-registry.com/.../

Is there a way to achieve the same with yarn without having to use a .npmrc/.yarnrc file?

@pschmoek thanks.
for me the --registry was a reason to actually install a package from a different repo since we have our own sinopia local proxy and we use it by default in npm config.

I haven't explored yarn publish at all and can take a look again on the code on how the scoped packages is different.

If you use the YARN_REGISTRY environment variable will it work?
something like: YARN_REGISTRY='https://registry.yarnpkg.com' yarn publish myscope... etc

@lirantal no it does not.

A scopes registry is different to the 'global' registry. If you were to publish @myscope/test to your sinopia --registry would be insufficient since it only affects the 'global' registry.

The funny thing though, configuring a scopes registry via npm config file works fine.

Inside .npmrc

'@myscope:registry': 'https://domain.com:8081/artifactory/api/npm/npm-virtual/'

Having multiple registry instances to support, makes the .npmrc solution a pain to work with.
yarn --"myscope:registry=..." would be the desired solution. As long as yarn doesn't support it, we will have to stick to use npm for publishing. But the raw functionality is present somewhere inside yarn since .npmrc is interpreted correctly.

I'll close this issue, as the original feature is now implemented - can you open a separate issue for the scope thing? Thanks! 馃槃

@pschmoek open the ticket and I will take a look later, maybe it's a small fix in the publish.js command.

Was this page helpful?
0 / 5 - 0 ratings