Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKat Marchán <kzm@sykosomatic.org>2017-05-31 08:04:55 +0300
committerKat Marchán <kzm@sykosomatic.org>2017-05-31 09:01:17 +0300
commite61e68dac4fa51c0540a064204a75b19f8052e58 (patch)
treec96a5fbd310b9b9bdd0b972f20876dc8188743a7
parent9aac984cbbfef22182ee42b51a193c0b47146ad6 (diff)
publish: adapt config for publish RegClient (#16762)
Fixes: #16746 PR-URL: https://github.com/npm/npm/pull/16762 Credit: @zkat
-rw-r--r--lib/config/reg-client.js29
-rw-r--r--lib/npm.js30
-rw-r--r--lib/utils/get-publish-config.js16
-rw-r--r--test/tap/publish-config.js45
4 files changed, 67 insertions, 53 deletions
diff --git a/lib/config/reg-client.js b/lib/config/reg-client.js
new file mode 100644
index 000000000..d4e241709
--- /dev/null
+++ b/lib/config/reg-client.js
@@ -0,0 +1,29 @@
+'use strict'
+
+module.exports = regClientConfig
+function regClientConfig (npm, log, config) {
+ return {
+ proxy: {
+ http: config.get('proxy'),
+ https: config.get('https-proxy'),
+ localAddress: config.get('local-address')
+ },
+ ssl: {
+ certificate: config.get('cert'),
+ key: config.get('key'),
+ ca: config.get('ca'),
+ strict: config.get('strict-ssl')
+ },
+ retry: {
+ retries: config.get('fetch-retries'),
+ factor: config.get('fetch-retry-factor'),
+ minTimeout: config.get('fetch-retry-mintimeout'),
+ maxTimeout: config.get('fetch-retry-maxtimeout')
+ },
+ userAgent: config.get('user-agent'),
+ log: log,
+ defaultTag: config.get('tag'),
+ maxSockets: config.get('maxsockets'),
+ scope: npm.projectScope
+ }
+}
diff --git a/lib/npm.js b/lib/npm.js
index dbd8e9715..990d8c510 100644
--- a/lib/npm.js
+++ b/lib/npm.js
@@ -33,6 +33,7 @@
var rimraf = require('rimraf')
var lazyProperty = require('lazy-property')
var parseJSON = require('./utils/parse-json.js')
+ var clientConfig = require('./config/reg-client.js')
var aliases = require('./config/cmd-list').aliases
var cmdList = require('./config/cmd-list').cmdList
var plumbing = require('./config/cmd-list').plumbing
@@ -344,7 +345,7 @@
lazyProperty(npm, 'registry', function () {
registryLoaded = true
var RegClient = require('npm-registry-client')
- var registry = new RegClient(adaptClientConfig(npm.config))
+ var registry = new RegClient(clientConfig(npm, log, npm.config))
registry.version = npm.version
registry.refer = registryRefer
return registry
@@ -467,31 +468,4 @@
return ''
}
}
-
- function adaptClientConfig (config) {
- return {
- proxy: {
- http: config.get('proxy'),
- https: config.get('https-proxy'),
- localAddress: config.get('local-address')
- },
- ssl: {
- certificate: config.get('cert'),
- key: config.get('key'),
- ca: config.get('ca'),
- strict: config.get('strict-ssl')
- },
- retry: {
- retries: config.get('fetch-retries'),
- factor: config.get('fetch-retry-factor'),
- minTimeout: config.get('fetch-retry-mintimeout'),
- maxTimeout: config.get('fetch-retry-maxtimeout')
- },
- userAgent: config.get('user-agent'),
- log: log,
- defaultTag: config.get('tag'),
- maxSockets: config.get('maxsockets'),
- scope: npm.projectScope
- }
- }
})()
diff --git a/lib/utils/get-publish-config.js b/lib/utils/get-publish-config.js
index fa475434f..ac0ef0934 100644
--- a/lib/utils/get-publish-config.js
+++ b/lib/utils/get-publish-config.js
@@ -1,12 +1,16 @@
-var Conf = require('../config/core.js').Conf
-var RegClient = require('npm-registry-client')
-var log = require('npmlog')
+'use strict'
+
+const clientConfig = require('../config/reg-client.js')
+const Conf = require('../config/core.js').Conf
+const log = require('npmlog')
+const npm = require('../npm.js')
+const RegClient = require('npm-registry-client')
module.exports = getPublishConfig
function getPublishConfig (publishConfig, defaultConfig, defaultClient) {
- var config = defaultConfig
- var client = defaultClient
+ let config = defaultConfig
+ let client = defaultClient
log.verbose('getPublishConfig', publishConfig)
if (publishConfig) {
config = new Conf(defaultConfig)
@@ -18,7 +22,7 @@ function getPublishConfig (publishConfig, defaultConfig, defaultClient) {
s[k] = publishConfig[k]
return s
}, {}))
- client = new RegClient(config)
+ client = new RegClient(clientConfig(npm, log, config))
}
return { config: config, client: client }
diff --git a/test/tap/publish-config.js b/test/tap/publish-config.js
index 399fd0f93..fb430af21 100644
--- a/test/tap/publish-config.js
+++ b/test/tap/publish-config.js
@@ -1,36 +1,43 @@
-var common = require('../common-tap.js')
-var test = require('tap').test
-var fs = require('fs')
-var osenv = require('osenv')
-var pkg = process.env.npm_config_tmp || '/tmp'
-pkg += '/npm-test-publish-config'
+'use strict'
+
+const common = require('../common-tap.js')
+const test = require('tap').test
+const fs = require('fs')
+const osenv = require('osenv')
+const pkg = `${process.env.npm_config_tmp || '/tmp'}/npm-test-publish-config`
require('mkdirp').sync(pkg)
fs.writeFileSync(pkg + '/package.json', JSON.stringify({
name: 'npm-test-publish-config',
version: '1.2.3',
- publishConfig: { registry: common.registry }
+ publishConfig: {
+ registry: common.registry
+ }
}), 'utf8')
fs.writeFileSync(pkg + '/fixture_npmrc',
'//localhost:1337/:email = fancy@feast.net\n' +
'//localhost:1337/:username = fancy\n' +
- '//localhost:1337/:_password = ' + new Buffer('feast').toString('base64') + '\n' +
- 'registry = http://localhost:1337/')
+ '//localhost:1337/:_password = ' + new Buffer('feast').toString('base64'))
test(function (t) {
- var child
- t.plan(4)
+ let child
+ t.plan(5)
require('http').createServer(function (req, res) {
t.pass('got request on the fakey fake registry')
- this.close()
- res.statusCode = 500
- res.end(JSON.stringify({
- error: 'sshhh. naptime nao. \\^O^/ <(YAWWWWN!)'
- }))
- child.kill('SIGINT')
- }).listen(common.port, function () {
+ let body = ''
+ req.on('data', (d) => { body += d })
+ req.on('end', () => {
+ this.close()
+ res.statusCode = 500
+ res.end(JSON.stringify({
+ error: 'sshhh. naptime nao. \\^O^/ <(YAWWWWN!)'
+ }))
+ t.match(body, /"beta"/, 'got expected tag')
+ child.kill('SIGINT')
+ })
+ }).listen(common.port, () => {
t.pass('server is listening')
// don't much care about listening to the child's results
@@ -40,7 +47,7 @@ test(function (t) {
// itself functions normally.
//
// Make sure that we don't sit around waiting for lock files
- child = common.npm(['publish', '--userconfig=' + pkg + '/fixture_npmrc'], {
+ child = common.npm(['publish', '--userconfig=' + pkg + '/fixture_npmrc', '--tag=beta'], {
cwd: pkg,
stdio: 'inherit',
env: {