yarn registry scopes - injecting scope name + %2f into the registry url - npm-install

trying to setup yarn scoped registry using example here
but the installer keeps appending scope name to the url.
.yarnrc
#myscope:registry" "https://artifactory.mycompany.com/artifactory/api/npm/myco
package.json
"dependencies": {
"#myscope/web-components": "0.0.29",
yarn install --verbose
Performing "GET" request to "https://artifactory.mycompany.com/artifactory/api/npm/myco/#myscope%2fweb-components finished with status code 404.
verbose 1.176178875 Error: Couldn't find package "#myscope/web-components#0.0.29" required by "web#0.1.0" on the "npm" registry.".
so #myscope%2f is injected into the request address.
expcting
https://artifactory.mycompany.com/artifactory/api/npm/myco/web-components
getting
https://artifactory.mycompany.com/artifactory/api/npm/myco/#myscope%2fweb-components
yarn version
1.22.19

Related

npm access ls-collaborators is not reading from the custom registry in .npmrc

I have a custom .npmrc file as follows
#foo:registry=https://gitlab.com/api/v4/packages/npm/
// This works and it returns the latest dist tag from the registry as configured in .npmrc
npm view --json #foo/my-package dist-tags
// This fails with a 404
npm access ls-collaborators #foo/my-package
// npm ERR! 404 Not Found - GET https://registry.npmjs.org/-/package/%40foo%2Fmy-package/collaborators?format=cli - Package not found
Some more context:
I am trying to publish an npm package to a private package registry on gitlab using the np module. These commands seem to be executing as part of one of its steps for user authentication.
What am I missing?
Make sure "private": true is in your package.json file. I was running into a similar problem as you, and adding this fixed it for me.

Use custom registy, ideally from package.json

In my package.json I have
"config": {
"registry": "https://registry.example.net"
}
In order to use a local registry. If I execute yarn install --verbose though, I see yarn does not use this but uses its own registry:
Performing "GET" request to "https://registry.yarnpkg.com/ts-node/-/ts-node-8.3.0.tgz".
I managed to set the yarn registry manually
yarn config set registry https://registry.example.net
Even then, in verbose mode, it shows me that it is sending GET requests to registry.yarnpkg.com.
Also I need this to be configured so it also uses this registry on other dev machines and jenkins.
How can I get yarn to use my custom registry, ideally from a config file?

NPM: how to specify registry to publish in the command line?

I'm testing a new version of our npm packages registry. I'd like to run a job in our CI server specifying a registry different of the default.
I tried to execute npm publish --registry "http://nexus.dsv.myhost/nexus/repository/npmjs-registry but it didn't work. It was published to the default registry.
How do I specify a different registry while running npm publish. It is a scoped package.
There's multiple ways to accomplish this.
use npm config to set the registry globally:
npm config set registry http://nexus.dsv.myhost/nexus/repository/npmjs
use npm config to set the registry for the package scope:
npm config set #<your scope here>:registry http://nexus.dsv.myhost/nexus/repository/npmjs
configure your package.json with a publish config:
{
...
"publishConfig": {
"registry": "http://nexus.dsv.myhost/nexus/repository/npmjs"
},
...
}
use npmrc to configure the registry
registry=http://nexus.dsv.myhost/nexus/repository/npmjs
It sounds like you have a scope-specific registry configured somewhere in your npm config.
npm will merge your global, local and CLI-provided config. But any scope-specific config will take precedence over unscoped config regardless of where each of them are defined.
For example, if you have #myscope:registry=xyz in your ~/.npmrc file, that will take precedence over --registry=abc provided on the CLI, because a scope-specific registry always overrides the unscoped registry.
However, you can also pass a scope-specific registry on the CLI itself like this:
npm publish --#myscope:registry=http://nexus.dsv.myhost/nexus/repository/npmjs-registry
Note that because of how nopt (which is what npm uses under the hood to parse the CLI options) parses freeform switches, the = sign here is required. If you use a space instead, it won't work as expected.

Using .npmrc with npm publish actions

We have a private NPM registry to which we are publishing our packages to, and have a publishConfig section in our projects package.json file which juts contains our registry url which gets picked up by our npm publish commands:
"publishConfig": {
"registry": "xxxxxx"
}
I would like to have this registry url read out from am .nprmc file rather than the package.json.
I have tried doing this, but when using npm publish I get:
400 - Repository with ID='xxx' is Read Only, but action was 'create'!
I figured this may be because I hadnt added my user details to my npmrc, which I have now done, but the problem still remains.
Is it possible for npm publish to use the details from an npmrc specifically?
Just add the following to your .npmrc
registry=YOUR_REGISTRY

Jfrog Artifactory does not work with NPM packages from #types (NPM organization/scope)

We use artifactory for npm, bower etc for our projects. now we want to use new feature TypeScript type definitions to fetch the npm package as #types/jasmine (NPM organization/scope) through artifactory but when we try to access it we get http 400
$ npm install -g protractor
npm http 400 http://artifactory/artifactory/api/npm/npm-virtual/#types%2fjasmine
we are able to access the link directly on npm public repo but. it doesn't work through artifactory. is it still not supported . is there a workaround or fix.
From the Artifactory user guide:
Npm 'slash' character encoding
By default, the npm client encodes slash characters ('/') to their ASCII representation ("%2f") before communicating with the npm registry. If you are running Tomcat as your HTTP container (the default for Artifactory), this generates an "HTTP 400" error since Tomcat does not allow encoded slashes by default. To avoid this error when using npm scope packages, you can override this default behavior by defining the following property in the catalina.properties file of your Tomcat:
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true