Skip to content

Commit

Permalink
feat(specs): can use opts.spec to trigger pickManifest
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 16, 2018
1 parent 4371de5 commit 85c4ac9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ function regFetch (uri, opts) {
opts = config(Object.assign({
log: silentLog
}, opts))
const registry = opts.get('registry') ||
const registry = (
(opts.get('spec') && pickRegistry(opts.get('spec'), opts)) ||
opts.get('registry') ||
'https://registry.npmjs.org/'
)
uri = url.parse(uri).protocol
? uri
: `${
Expand Down
39 changes: 39 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,45 @@ test('pickRegistry() utility', t => {
t.done()
})

test('pickRegistry through opts.spec', t => {
tnock(t, OPTS.config.get('registry'))
.get('/pkg')
.reply(200, {source: OPTS.config.get('registry')})
const scopedReg = 'https://scoped.mock.reg/'
tnock(t, scopedReg)
.get('/pkg')
.times(2)
.reply(200, {source: scopedReg})
return fetch.json('/pkg', Object.assign({
spec: 'pkg@1.2.3',
'@myscope:registry': scopedReg
}, OPTS))
.then(json => t.equal(
json.source,
OPTS.config.get('registry'),
'request made to main registry'
))
.then(() => fetch.json('/pkg', Object.assign({
spec: 'pkg@1.2.3',
'@myscope:registry': scopedReg,
'scope': '@myscope'
})))
.then(json => t.equal(
json.source,
scopedReg,
'request made to scope registry using opts.scope'
))
.then(() => fetch.json('/pkg', Object.assign({
spec: '@myscope/pkg@1.2.3',
'@myscope:registry': scopedReg
})))
.then(json => t.equal(
json.source,
scopedReg,
'request made to scope registry using spec scope'
))
})

// TODO
// * npm-session
// * npm-in-ci
Expand Down

0 comments on commit 85c4ac9

Please sign in to comment.