You can also publish directly to a scoped registry by adding the --scope
parameter, where that scope is already defined in your .npmrc file. I could not find any documentation on this feature, so documenting here:
Given .npmrc
@myscope=https://my.custom.registry.url
Command to publish
npm publish --scope=@myscope
This will publish the package to your scoped/private registry.
I found this particularly useful when consuming/creating NPM packages for Azure DevOps / Azure Artifacts feeds, where we have decided to NOT use upstream sources, and instead use scope to pull/push packages to our private registry.
Note that doing it this way requires your private registry to have @myscope/package-name
as the actual package names. See this microsoft doc for notes.
Azure Artifacts Example Package
Per the note above, here's how your packages you're creating should look when using scope for a private repo + the public npmjs.org registry.
package.json:
...
"name": "@myscope/my-private-package",
...