fix(registry): be better at using the correct registry (relevant for npme)
Closes #53
This commit is contained in:
+4
-2
@@ -1,5 +1,6 @@
|
||||
const { readFileSync, writeFileSync } = require('fs')
|
||||
const path = require('path')
|
||||
const url = require('url')
|
||||
|
||||
const _ = require('lodash')
|
||||
const log = require('npmlog')
|
||||
@@ -45,11 +46,12 @@ npmconf.load({}, (err, conf) => {
|
||||
token: env.NPM_TOKEN
|
||||
},
|
||||
loglevel: conf.get('loglevel'),
|
||||
registry: conf.get('registry'),
|
||||
registry: require('./lib/get-registry')(pkg, conf),
|
||||
tag: (pkg.publishConfig || {}).tag || conf.get('tag') || 'latest'
|
||||
}
|
||||
|
||||
if (npm.registry[npm.registry.length - 1] !== '/') npm.registry += '/'
|
||||
// normalize trailing slash
|
||||
npm.registry = url.format(url.parse(npm.registry))
|
||||
|
||||
log.level = npm.loglevel
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
module.exports = function (pkg, conf) {
|
||||
if (pkg.publishConfig && pkg.publishConfig.registry) return pkg.publishConfig.registry
|
||||
|
||||
if (pkg.name[0] !== '@') return conf.get('registry') || 'https://registry.npmjs.org/'
|
||||
|
||||
const scope = pkg.name.split('/')[0]
|
||||
const scopedRegistry = conf.get(`${scope}/registry`)
|
||||
|
||||
if (scopedRegistry) return scopedRegistry
|
||||
|
||||
return conf.get('registry') || 'https://registry.npmjs.org/'
|
||||
}
|
||||
Reference in New Issue
Block a user