File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,11 @@ function regFetch (uri, opts) {
16
16
opts = config ( Object . assign ( {
17
17
log : silentLog
18
18
} , opts ) )
19
- const registry = opts . get ( 'registry' ) ||
19
+ const registry = (
20
+ ( opts . get ( 'spec' ) && pickRegistry ( opts . get ( 'spec' ) , opts ) ) ||
21
+ opts . get ( 'registry' ) ||
20
22
'https://registry.npmjs.org/'
23
+ )
21
24
uri = url . parse ( uri ) . protocol
22
25
? uri
23
26
: `${
Original file line number Diff line number Diff line change @@ -243,6 +243,45 @@ test('pickRegistry() utility', t => {
243
243
t . done ( )
244
244
} )
245
245
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
+
246
285
// TODO
247
286
// * npm-session
248
287
// * npm-in-ci
You can’t perform that action at this time.
0 commit comments