Skip to content

Commit 6912f24

Browse files
authored
feat: add allowRegistry option (#451)
This adds the last option needed to aggregate these in npm itself. Ref: npm/statusboard#1064
1 parent ab37bc1 commit 6912f24

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ Options object is cloned, and mutated along the way to add integrity, resolved,
160160
Possible values and defaults are the same as `allowGit`
161161
* `allowDirectory` Whether or not to allow data to be fetched from directory specs.
162162
Possible values and defaults are the same as `allowGit`
163+
* `allowRegistry` Whether or not to allow data to be fetched from registry specs. This includes `version`, `range`, `tag`, and `alias`.
163164
* `_isRoot` Whether or not the package being fetched is in a root context.
164165
Defaults to `false`,
165166
For `npm` itself this means a package that is defined in the local project or workspace package.json, or a package that is being fetched for another command like `npm view`. This informs the `allowX` options to let them know the context of the current request.

lib/fetcher.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ FetcherBase.get = (rawSpec, opts = {}) => {
502502
case 'range':
503503
case 'tag':
504504
case 'alias':
505+
canUse({ allow: opts.allowRegistry, isRoot: opts._isRoot, allowType: 'registry', spec })
505506
return new RegistryFetcher(spec.subSpec || spec, opts)
506507

507508
case 'file':

test/fetcher.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ t.test('allowX', t => {
542542
['allowRemote', 'http://npmjs.org/package'],
543543
['allowFile', './local.tgz'],
544544
['allowDirectory', './local/dir'],
545+
['allowRegistry', '@npmcli/test'],
546+
['allowRegistry', '@npmcli/test@1.0.0'],
547+
['allowRegistry', '@npmcli/test@latest'],
548+
['allowRegistry', 'myalias@npm:@npmcli/test@1.2.3'],
545549
]
546550
for (const [allowType, spec] of allowTypes) {
547551
t.test(`${allowType}: ${spec}`, t => {

0 commit comments

Comments
 (0)