cli: pass npm_token for private repos (#2987)

This commit is contained in:
Ouwen Huang 2022-10-18 16:01:35 -10:00 committed by GitHub
parent 26cc87a2ac
commit 5482de08bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -110,8 +110,13 @@ function validate(packageName, version, keyword) {
// Gets the registry of the package. Scoped packages may not be using the global default.
const registryUrlOfPackage = registryUrl(scope);
const response = await fetch(`${registryUrlOfPackage}${packageName}`);
let options = {}
if (process.env.NPM_TOKEN){
options['headers'] = {
'Authorization': `Bearer ${process.env.NPM_TOKEN}`,
}
}
const response = await fetch(`${registryUrlOfPackage}${packageName}`, options);
const json = await response.json();
if (json.error && json.error === NOT_FOUND) {

View File

@ -289,3 +289,14 @@ can take a look at what this file contains by going to
`platform/viewer/PluginConfig.json` in your project's root directory. In short,
this file tracks and stores all the extensions/modes and the their version that
are currently being used by the viewer.
## Private NPM Repos
For the `yarn cli` to view private NPM repos, create a read-only token with the
following steps and export it as an environmental variable. You may also export
an existing npm token.
```
npm login
npm token create --read-only
export NPM_TOKEN=<your readonly token>
```