Skip to content

Commit 85c4ac9

Browse files
committedMar 16, 2018
feat(specs): can use opts.spec to trigger pickManifest
1 parent 4371de5 commit 85c4ac9

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed
 

‎index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ function regFetch (uri, opts) {
1616
opts = config(Object.assign({
1717
log: silentLog
1818
}, opts))
19-
const registry = opts.get('registry') ||
19+
const registry = (
20+
(opts.get('spec') && pickRegistry(opts.get('spec'), opts)) ||
21+
opts.get('registry') ||
2022
'https://registry.npmjs.org/'
23+
)
2124
uri = url.parse(uri).protocol
2225
? uri
2326
: `${

‎test/index.js

+39
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,45 @@ test('pickRegistry() utility', t => {
243243
t.done()
244244
})
245245

246+
test('pickRegistry through opts.spec', t => {
247+
tnock(t, OPTS.config.get('registry'))
248+
.get('/pkg')
249+
.reply(200, {source: OPTS.config.get('registry')})
250+
const scopedReg = 'https://scoped.mock.reg/'
251+
tnock(t, scopedReg)
252+
.get('/pkg')
253+
.times(2)
254+
.reply(200, {source: scopedReg})
255+
return fetch.json('/pkg', Object.assign({
256+
spec: 'pkg@1.2.3',
257+
'@myscope:registry': scopedReg
258+
}, OPTS))
259+
.then(json => t.equal(
260+
json.source,
261+
OPTS.config.get('registry'),
262+
'request made to main registry'
263+
))
264+
.then(() => fetch.json('/pkg', Object.assign({
265+
spec: 'pkg@1.2.3',
266+
'@myscope:registry': scopedReg,
267+
'scope': '@myscope'
268+
})))
269+
.then(json => t.equal(
270+
json.source,
271+
scopedReg,
272+
'request made to scope registry using opts.scope'
273+
))
274+
.then(() => fetch.json('/pkg', Object.assign({
275+
spec: '@myscope/pkg@1.2.3',
276+
'@myscope:registry': scopedReg
277+
})))
278+
.then(json => t.equal(
279+
json.source,
280+
scopedReg,
281+
'request made to scope registry using spec scope'
282+
))
283+
})
284+
246285
// TODO
247286
// * npm-session
248287
// * npm-in-ci

0 commit comments

Comments
 (0)
Please sign in to comment.