microsoft / ado-npm-auth

This package can automatically use the azureauth CLI to fetch tokens and update a user's .npmrc file for authenticating to Azure DevOps npm feeds.
MIT License
9 stars 7 forks source link

Executing ado-npm-auth with preinstall on a fresh environment #14

Closed kwickramasekara closed 4 months ago

kwickramasekara commented 4 months ago

Hey all, thanks for this amazing tool. We started using it today but are running into an issue with the preinstall setup mentioned in the docs. In a repository with a private registry, it looks like you need to already have a PAT saved locally for the preinstall script to successfully run. Otherwise, you get the following error:

image

This means, the tool won't be able to generate a new PAT for you? An example scenario for this case would be someone cloning and setting up the said repository for the first time with no pre-existing PATs.

Note: to reproduce the issue, you may need to clear the npm cache (npm cache clean --force).

Edit: I see there is a section about this in the docs, but it still doesnt work when I set the preinstall script to: npm_config_registry=https://registry.npmjs.org npm exec ado-npm-auth

kwickramasekara commented 4 months ago

As a workaround, I'v updated our project readme to run this before the npm install on fresh clones of the repo:

npm_config_registry=https://registry.npmjs.org npm i -g ado-npm-auth && npm exec ado-npm-auth && npm un -g ado-npm-auth

It installs the ado-npm-auth package globally using the public registry, obtains a PAT and uninstalls the package. This ensures a valid token exists before the npm install.