Skip to content

Commit

Permalink
fix: respect publishConfig.registry when specified
Browse files Browse the repository at this point in the history
PR-URL: #35
Credit: @nlf
Close: #35
Reviewed-by: @darcyclarke
  • Loading branch information
nlf committed Oct 12, 2020
1 parent b6a309e commit 32e36ef
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function regFetch (uri, /* istanbul ignore next */ opts_ = {}) {
}
const registry = opts.registry = (
(opts.spec && pickRegistry(opts.spec, opts)) ||
(opts.publishConfig && opts.publishConfig.registry) ||
opts.registry ||
/* istanbul ignore next */
'https://registry.npmjs.org/'
Expand Down Expand Up @@ -155,6 +156,10 @@ function pickRegistry (spec, opts = {}) {
registry = opts[opts.scope.replace(/^@?/, '@') + ':registry']
}

if (!registry && opts.publishConfig) {
registry = opts.publishConfig.registry
}

if (!registry) {
registry = opts.registry || 'https://registry.npmjs.org/'
}
Expand Down
40 changes: 40 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,18 @@ test('pickRegistry() utility', t => {
'https://my.scoped.registry/here/',
'scope @ is option@l'
)
t.equal(
pick('foo@1.2.3', {
registry: 'https://my.registry/here/',
scope: '@otherscope',
'@myscope:registry': 'https://my.scoped.registry/here/',
publishConfig: {
registry: 'https://my.package.registry'
}
}),
'https://my.package.registry',
'respects publishConfig setting'
)
t.done()
})

Expand Down Expand Up @@ -461,6 +473,34 @@ test('pickRegistry through opts.spec', t => {
))
})

test('pickRegistry through publishConfig', t => {
tnock(t, OPTS.registry)
.get('/pkg')
.reply(200, { source: OPTS.registry })
const publishRegistry = 'https://my.publish.registry'
tnock(t, publishRegistry)
.get('/pkg')
.reply(200, { source: publishRegistry })

return fetch.json('/pkg', {
...OPTS,
publishConfig: {}
}).then(json => t.equal(
json.source,
OPTS.registry,
'request made to default registry when publishConfig specifies no registry'
)).then(() => fetch.json('/pkg', {
...OPTS,
publishConfig: {
registry: publishRegistry
}
}).then(json => t.equal(
json.source,
publishRegistry,
'request made to publishConfig.registry when one is specified'
)))
})

test('log warning header info', t => {
tnock(t, OPTS.registry)
.get('/hello')
Expand Down

0 comments on commit 32e36ef

Please sign in to comment.