-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Describe the bug
The documentation states that one way to setup this package is to:
2: configure registry explicilty
If that's the case, set the environment variable npm_config_registry=https://registry.npmjs.org.That will ensure that npx or npm exec grabs from the public NPM feed, bypassing the soon-to-be authenticated ADO feed.
"scripts": {
"preinstall": "npm_config_registry=https://registry.npmjs.org npm exec ado-npm-auth"
},
However, this does not work. More information can be seen in this npm bug report: npm/cli#2660
The problem is that the preinstall script only runs after the packages have been installed. One of the comments in the above bug report even states that a fix to the issue would be desired so that:
Agreed on treating this as a bug. Another example is users who use the preinstall hook to authenticate with private registries on their cloud platforms and/or any other registries with short lived tokens.
Azure: https://github.com/gsoft-inc/azure-devops-npm-auth
AWS: https://aws.amazon.com/blogs/devops/publishing-private-npm-packages-aws-codeartifact/
To Reproduce
Steps to reproduce the behavior:
- Make sure your user's
.npmrcfile does not have any authentication token for the Azure DevOps registry you want to authenticate to. - Create a project
.npmrcfile with an Azure DevOps registry. - Create a
preinstallscript in thepackage.jsonas set it tocross-env npm_config_registry=https://registry.npmjs.org npm exec ado-npm-auth -c ./.npmrc - Run "npm install" from the project root directory where the
package.jsonand.npmrcfiles are. - You get an unable to authenticate error message because the
preinstallscript is not executed before packages are installed.
Expected behavior
Since the issue with the preinstall is still open I would suggest you update the documentation to remove this incorrect information. Unless you know of some workaround, I believe the only way to generate the authentication token is to explicitly invoke the ado-npm-auth package and pass the .npmrc file before you run npm install.
Desktop (please complete the following information):
- OS: Windows
Additional context
In my example above I used cross-env in the preinstall script because I'm running on Windows and that's how I do the equivalent of the preinstall script in the docs which was:
"scripts": {
"preinstall": "npm_config_registry=https://registry.npmjs.org npm exec ado-npm-auth"
},