From 43dd49c9782848c25e5b03448c8a0f923f13c158 Mon Sep 17 00:00:00 2001 From: Kat Marchán Date: Tue, 29 Jan 2019 14:43:00 -0800 Subject: deps: upgrade npm to 6.7.0 PR-URL: https://github.com/nodejs/node/pull/25804 Reviewed-By: Myles Borins --- .../node_modules/libcipm/lib/config/npm-config.js | 72 +++++++++++++--------- 1 file changed, 42 insertions(+), 30 deletions(-) (limited to 'deps/npm/node_modules/libcipm/lib/config/npm-config.js') diff --git a/deps/npm/node_modules/libcipm/lib/config/npm-config.js b/deps/npm/node_modules/libcipm/lib/config/npm-config.js index 76b4054eef..a051190619 100644 --- a/deps/npm/node_modules/libcipm/lib/config/npm-config.js +++ b/deps/npm/node_modules/libcipm/lib/config/npm-config.js @@ -1,40 +1,22 @@ 'use strict' const BB = require('bluebird') -const lifecycleOpts = require('./lifecycle-opts.js') -const pacoteOpts = require('./pacote-opts.js') -const protoduck = require('protoduck') -const spawn = require('child_process').spawn -class NpmConfig extends Map {} +const fs = require('fs') +const figgyPudding = require('figgy-pudding') +const ini = require('ini') +const path = require('path') +const spawn = require('child_process').spawn -const CipmConfig = protoduck.define({ - get: [], - set: [], - toPacote: [], - toLifecycle: [] -}, { - name: 'CipmConfig' -}) -module.exports.CipmConfig = CipmConfig +const readFileAsync = BB.promisify(fs.readFile) -CipmConfig.impl(NpmConfig, { - get: Map.prototype.get, - set: Map.prototype.set, - toPacote (opts) { - return pacoteOpts(this, opts) - }, - toLifecycle () { - return lifecycleOpts(this) - } +const NpmConfig = figgyPudding({ + cache: { default: '' }, + then: {}, + userconfig: {} }) -module.exports.fromObject = fromObj -function fromObj (obj) { - const map = new NpmConfig() - Object.keys(obj).forEach(k => map.set(k, obj[k])) - return map -} +module.exports = NpmConfig module.exports.fromNpm = getNpmConfig function getNpmConfig (argv) { @@ -62,11 +44,41 @@ function getNpmConfig (argv) { reject(new Error('`npm` command not found. Please ensure you have npm@5.4.0 or later installed.')) } else { try { - resolve(fromObj(JSON.parse(stdout))) + resolve(JSON.parse(stdout)) } catch (e) { reject(new Error('`npm config ls --json` failed to output json. Please ensure you have npm@5.4.0 or later installed.')) } } }) + }).then(opts => { + return BB.all( + process.cwd().split(path.sep).reduce((acc, next) => { + acc.path = path.join(acc.path, next) + acc.promises.push(maybeReadIni(path.join(acc.path, '.npmrc'))) + acc.promises.push(maybeReadIni(path.join(acc.path, 'npmrc'))) + return acc + }, { + path: '', + promises: [] + }).promises.concat( + opts.userconfig ? maybeReadIni(opts.userconfig) : {} + ) + ).then(configs => NpmConfig(...configs, opts)) + }).then(opts => { + if (opts.cache) { + return opts.concat({ cache: path.join(opts.cache, '_cacache') }) + } else { + return opts + } }) } + +function maybeReadIni (f) { + return readFileAsync(f, 'utf8').catch(err => { + if (err.code === 'ENOENT') { + return '' + } else { + throw err + } + }).then(ini.parse) +} -- cgit v1.2.3