diff --git a/index.js b/index.js index eb48ba6c..2324e7fb 100644 --- a/index.js +++ b/index.js @@ -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/' @@ -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/' } diff --git a/test/index.js b/test/index.js index 339efa19..553f1f6e 100644 --- a/test/index.js +++ b/test/index.js @@ -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() }) @@ -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')