Skip to content

Commit 32e36ef

Browse files
committed
fix: respect publishConfig.registry when specified
PR-URL: #35 Credit: @nlf Close: #35 Reviewed-by: @darcyclarke
1 parent b6a309e commit 32e36ef

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function regFetch (uri, /* istanbul ignore next */ opts_ = {}) {
2929
}
3030
const registry = opts.registry = (
3131
(opts.spec && pickRegistry(opts.spec, opts)) ||
32+
(opts.publishConfig && opts.publishConfig.registry) ||
3233
opts.registry ||
3334
/* istanbul ignore next */
3435
'https://registry.npmjs.org/'
@@ -155,6 +156,10 @@ function pickRegistry (spec, opts = {}) {
155156
registry = opts[opts.scope.replace(/^@?/, '@') + ':registry']
156157
}
157158

159+
if (!registry && opts.publishConfig) {
160+
registry = opts.publishConfig.registry
161+
}
162+
158163
if (!registry) {
159164
registry = opts.registry || 'https://registry.npmjs.org/'
160165
}

test/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,18 @@ test('pickRegistry() utility', t => {
422422
'https://my.scoped.registry/here/',
423423
'scope @ is option@l'
424424
)
425+
t.equal(
426+
pick('foo@1.2.3', {
427+
registry: 'https://my.registry/here/',
428+
scope: '@otherscope',
429+
'@myscope:registry': 'https://my.scoped.registry/here/',
430+
publishConfig: {
431+
registry: 'https://my.package.registry'
432+
}
433+
}),
434+
'https://my.package.registry',
435+
'respects publishConfig setting'
436+
)
425437
t.done()
426438
})
427439

@@ -461,6 +473,34 @@ test('pickRegistry through opts.spec', t => {
461473
))
462474
})
463475

476+
test('pickRegistry through publishConfig', t => {
477+
tnock(t, OPTS.registry)
478+
.get('/pkg')
479+
.reply(200, { source: OPTS.registry })
480+
const publishRegistry = 'https://my.publish.registry'
481+
tnock(t, publishRegistry)
482+
.get('/pkg')
483+
.reply(200, { source: publishRegistry })
484+
485+
return fetch.json('/pkg', {
486+
...OPTS,
487+
publishConfig: {}
488+
}).then(json => t.equal(
489+
json.source,
490+
OPTS.registry,
491+
'request made to default registry when publishConfig specifies no registry'
492+
)).then(() => fetch.json('/pkg', {
493+
...OPTS,
494+
publishConfig: {
495+
registry: publishRegistry
496+
}
497+
}).then(json => t.equal(
498+
json.source,
499+
publishRegistry,
500+
'request made to publishConfig.registry when one is specified'
501+
)))
502+
})
503+
464504
test('log warning header info', t => {
465505
tnock(t, OPTS.registry)
466506
.get('/hello')

0 commit comments

Comments
 (0)