From 617a39d4f58fc814f0ffda6456458af18a605b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Fri, 31 Aug 2018 15:31:44 -0700 Subject: [PATCH] feat(config): switch to modern, figgy-pudding configuration * updates to pacote@9 * switches to figgy-pudding for config handling * removes config/pacote-opts and config/lifecycle-opts * all config is in opts itself. `opts.config` is no longer used * adds support for auth config reading to npmConfig() utility BREAKING CHANGE: this updates cipm to use pacote@9, which consumes npm-style config objects, not pacoteOpts()-style objects. --- bin/cli.js | 7 +- index.js | 78 +++++++++---- lib/config/lifecycle-opts.js | 29 ----- lib/config/npm-config.js | 72 +++++++----- lib/config/pacote-opts.js | 135 ----------------------- package-lock.json | 200 ++++++++++++++-------------------- package.json | 5 +- test/specs/index.js | 15 +-- test/specs/lib/config.js | 17 +-- test/specs/lib/pacote-opts.js | 35 ------ 10 files changed, 199 insertions(+), 394 deletions(-) delete mode 100644 lib/config/lifecycle-opts.js delete mode 100644 lib/config/pacote-opts.js delete mode 100644 test/specs/lib/pacote-opts.js diff --git a/bin/cli.js b/bin/cli.js index 87bf011..0bb5647 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -17,11 +17,8 @@ function cliMain () { const log = require('npmlog') return fromNpm(process.argv) .then(c => { - log.level = c.get('loglevel') - return new Installer({ - config: c, - log - }) + log.level = c.loglevel + return new Installer(c.concat({log})) }) .then(cipm => cipm.run()) .then( diff --git a/index.js b/index.js index 9061ec4..79fa48c 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ const BB = require('bluebird') const binLink = require('bin-links') const buildLogicalTree = require('npm-logical-tree') const extract = require('./lib/extract.js') +const figgyPudding = require('figgy-pudding') const fs = require('graceful-fs') const getPrefix = require('find-npm-prefix') const lifecycle = require('npm-lifecycle') @@ -20,10 +21,44 @@ const statAsync = BB.promisify(fs.stat) const symlinkAsync = BB.promisify(fs.symlink) const writeFileAsync = BB.promisify(fs.writeFile) +const CipmOpts = figgyPudding({ + also: {}, + dev: 'development', + development: {}, + force: {}, + global: {}, + ignoreScripts: 'ignore-scripts', + 'ignore-scripts': {}, + log: {}, + loglevel: {}, + only: {}, + prefix: {}, + prod: 'production', + production: {}, + Promise: { default: () => BB }, + umask: {} +}) + +const LifecycleOpts = figgyPudding({ + config: {}, + 'script-shell': {}, + scriptShell: 'script-shell', + 'ignore-scripts': {}, + ignoreScripts: 'ignore-scripts', + 'ignore-prepublish': {}, + ignorePrepublish: 'ignore-prepublish', + 'scripts-prepend-node-path': {}, + scriptsPrependNodePath: 'scripts-prepend-node-path', + 'unsafe-perm': {}, + unsafePerm: 'unsafe-perm', + prefix: {}, + dir: 'prefix', + failOk: { default: false } +}, { other () { return true } }) + class Installer { constructor (opts) { - this.opts = opts - this.config = opts.config + this.opts = CipmOpts(opts) // Stats this.startTime = Date.now() @@ -80,17 +115,17 @@ class Installer { prepare () { this.log.info('prepare', 'initializing installer') - this.log.level = this.config.get('loglevel') + this.log.level = this.opts.loglevel this.log.verbose('prepare', 'starting workers') extract.startWorkers() return ( - this.config.get('prefix') && this.config.get('global') - ? BB.resolve(this.config.get('prefix')) + this.opts.prefix && this.opts.global + ? BB.resolve(this.opts.prefix) // There's some Specialâ„¢ logic around the `--prefix` config when it // comes from a config file or env vs when it comes from the CLI : process.argv.some(arg => arg.match(/^\s*--prefix\s*/i)) - ? BB.resolve(this.config.get('prefix')) + ? BB.resolve(this.opts.prefix) : getPrefix(process.cwd()) ) .then(prefix => { @@ -218,15 +253,15 @@ class Installer { checkDepEnv (dep) { const includeDev = ( // Covers --dev and --development (from npm config itself) - this.config.get('dev') || + this.opts.dev || ( - !/^prod(uction)?$/.test(this.config.get('only')) && - !this.config.get('production') + !/^prod(uction)?$/.test(this.opts.only) && + !this.opts.production ) || - /^dev(elopment)?$/.test(this.config.get('only')) || - /^dev(elopment)?$/.test(this.config.get('also')) + /^dev(elopment)?$/.test(this.opts.only) || + /^dev(elopment)?$/.test(this.opts.also) ) - const includeProd = !/^dev(elopment)?$/.test(this.config.get('only')) + const includeProd = !/^dev(elopment)?$/.test(this.opts.only) return (dep.dev && includeDev) || (!dep.dev && includeProd) } @@ -274,14 +309,14 @@ class Installer { } return readPkgJson(path.join(depPath, 'package.json')) .then(pkg => binLink(pkg, depPath, false, { - force: this.config.get('force'), - ignoreScripts: this.config.get('ignore-scripts'), + force: this.opts.force, + ignoreScripts: this.opts['ignore-scripts'], log: Object.assign({}, this.log, { info: () => {} }), name: pkg.name, pkgId: pkg.name + '@' + pkg.version, prefix: this.prefix, prefixes: [this.prefix], - umask: this.config.get('umask') + umask: this.opts.umask }), e => { this.log.verbose('buildTree', `error linking ${spec}: ${e.message} ${e.stack}`) }) @@ -346,18 +381,21 @@ class Installer { runScript (stage, pkg, pkgPath) { const start = Date.now() - if (!this.config.get('ignore-scripts')) { + if (!this.opts['ignore-scripts']) { // TODO(mikesherov): remove pkg._id when npm-lifecycle no longer relies on it pkg._id = pkg.name + '@' + pkg.version - const opts = this.config.toLifecycle() - return BB.resolve(lifecycle(pkg, stage, pkgPath, opts)) - .tap(() => { this.timings.scripts += Date.now() - start }) + return BB.resolve(lifecycle( + pkg, stage, pkgPath, LifecycleOpts(this.opts).concat({ + // TODO: can be removed once npm-lifecycle is updated to modern + // config practices. + config: this.opts + })) + ).tap(() => { this.timings.scripts += Date.now() - start }) } return BB.resolve() } } module.exports = Installer -module.exports.CipmConfig = require('./lib/config/npm-config.js').CipmConfig function mark (tree, failed) { const liveDeps = new Set() diff --git a/lib/config/lifecycle-opts.js b/lib/config/lifecycle-opts.js deleted file mode 100644 index 7d57459..0000000 --- a/lib/config/lifecycle-opts.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict' - -const log = require('npmlog') - -module.exports = lifecycleOpts -function lifecycleOpts (opts) { - const objConfig = {} - for (const key of opts.keys()) { - const val = opts.get(key) - if (val != null) { - objConfig[key] = val - } - } - return { - config: objConfig, - scriptShell: opts.get('script-shell'), - force: opts.get('force'), - user: opts.get('user'), - group: opts.get('group'), - ignoreScripts: opts.get('ignore-scripts'), - ignorePrepublish: opts.get('ignore-prepublish'), - scriptsPrependNodePath: opts.get('scripts-prepend-node-path'), - unsafePerm: opts.get('unsafe-perm'), - log, - dir: opts.get('prefix'), - failOk: false, - production: opts.get('production') - } -} diff --git a/lib/config/npm-config.js b/lib/config/npm-config.js index 76b4054..a051190 100644 --- a/lib/config/npm-config.js +++ b/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) +} diff --git a/lib/config/pacote-opts.js b/lib/config/pacote-opts.js deleted file mode 100644 index 234ed13..0000000 --- a/lib/config/pacote-opts.js +++ /dev/null @@ -1,135 +0,0 @@ -'use strict' - -const Buffer = require('safe-buffer').Buffer - -const crypto = require('crypto') -const path = require('path') - -let effectiveOwner - -const npmSession = crypto.randomBytes(8).toString('hex') - -module.exports = pacoteOpts -function pacoteOpts (npmOpts, moreOpts) { - const ownerStats = calculateOwner() - const opts = { - cache: path.join(npmOpts.get('cache'), '_cacache'), - ca: npmOpts.get('ca'), - cert: npmOpts.get('cert'), - git: npmOpts.get('git'), - key: npmOpts.get('key'), - localAddress: npmOpts.get('local-address'), - loglevel: npmOpts.get('loglevel'), - maxSockets: +(npmOpts.get('maxsockets') || 15), - npmSession: npmSession, - offline: npmOpts.get('offline'), - projectScope: moreOpts.rootPkg && getProjectScope(moreOpts.rootPkg.name), - proxy: npmOpts.get('https-proxy') || npmOpts.get('proxy'), - refer: 'cipm', - registry: npmOpts.get('registry'), - retry: { - retries: npmOpts.get('fetch-retries'), - factor: npmOpts.get('fetch-retry-factor'), - minTimeout: npmOpts.get('fetch-retry-mintimeout'), - maxTimeout: npmOpts.get('fetch-retry-maxtimeout') - }, - strictSSL: npmOpts.get('strict-ssl'), - userAgent: npmOpts.get('user-agent'), - - dmode: parseInt('0777', 8) & (~npmOpts.get('umask')), - fmode: parseInt('0666', 8) & (~npmOpts.get('umask')), - umask: npmOpts.get('umask') - } - - if (ownerStats.uid != null || ownerStats.gid != null) { - Object.assign(opts, ownerStats) - } - - (npmOpts.forEach ? Array.from(npmOpts.keys()) : npmOpts.keys).forEach(k => { - const authMatchGlobal = k.match( - /^(_authToken|username|_password|password|email|always-auth|_auth)$/ - ) - const authMatchScoped = k[0] === '/' && k.match( - /(.*):(_authToken|username|_password|password|email|always-auth|_auth)$/ - ) - - // if it matches scoped it will also match global - if (authMatchGlobal || authMatchScoped) { - let nerfDart = null - let key = null - let val = null - - if (!opts.auth) { opts.auth = {} } - - if (authMatchScoped) { - nerfDart = authMatchScoped[1] - key = authMatchScoped[2] - val = npmOpts.get(k) - if (!opts.auth[nerfDart]) { - opts.auth[nerfDart] = { - alwaysAuth: !!npmOpts.get('always-auth') - } - } - } else { - key = authMatchGlobal[1] - val = npmOpts.get(k) - opts.auth.alwaysAuth = !!npmOpts.get('always-auth') - } - - const auth = authMatchScoped ? opts.auth[nerfDart] : opts.auth - if (key === '_authToken') { - auth.token = val - } else if (key.match(/password$/i)) { - auth.password = - // the config file stores password auth already-encoded. pacote expects - // the actual username/password pair. - Buffer.from(val, 'base64').toString('utf8') - } else if (key === 'always-auth') { - auth.alwaysAuth = val === 'false' ? false : !!val - } else { - auth[key] = val - } - } - - if (k[0] === '@') { - if (!opts.scopeTargets) { opts.scopeTargets = {} } - opts.scopeTargets[k.replace(/:registry$/, '')] = npmOpts.get(k) - } - }) - - Object.keys(moreOpts || {}).forEach((k) => { - opts[k] = moreOpts[k] - }) - - return opts -} - -function calculateOwner () { - if (!effectiveOwner) { - effectiveOwner = { uid: 0, gid: 0 } - - // Pretty much only on windows - if (!process.getuid) { - return effectiveOwner - } - - effectiveOwner.uid = +process.getuid() - effectiveOwner.gid = +process.getgid() - - if (effectiveOwner.uid === 0) { - if (process.env.SUDO_UID) effectiveOwner.uid = +process.env.SUDO_UID - if (process.env.SUDO_GID) effectiveOwner.gid = +process.env.SUDO_GID - } - } - - return effectiveOwner -} - -function getProjectScope (pkgName) { - const sep = pkgName.indexOf('/') - if (sep === -1) { - return '' - } else { - return pkgName.slice(0, sep) - } -} diff --git a/package-lock.json b/package-lock.json index d20edf8..f9481ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,17 +43,17 @@ } }, "agent-base": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.0.tgz", - "integrity": "sha512-c+R/U5X+2zz2+UCrCFv6odQzJdoqI+YecuhnAJLa1zYaMc13zPfwMwZrr91Pd1DYNo/yPRbiM4WVf9whgwFsIg==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.1.tgz", + "integrity": "sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg==", "requires": { "es6-promisify": "^5.0.0" } }, "agentkeepalive": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-3.4.1.tgz", - "integrity": "sha512-MPIwsZU9PP9kOrZpyu2042kYA8Fdt/AedQYkYXucHgF9QoD9dXVp0ypuGnHXSR0hTstBxdt85Xkh4JolYfK5wg==", + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-3.5.1.tgz", + "integrity": "sha512-Cte/sTY9/XcygXjJ0q58v//SnEQ7ViWExKyJpLJlLqomDbQyMLh6Is4KuWJ/wmxzhiwkGRple7Gqv1zf6Syz5w==", "requires": { "humanize-ms": "^1.2.1" } @@ -304,16 +304,16 @@ "integrity": "sha1-dBxSFkaOrcRXsDQQEYrXfejB3bE=" }, "cacache": { - "version": "11.0.2", - "resolved": "https://registry.npmjs.org/cacache/-/cacache-11.0.2.tgz", - "integrity": "sha512-hMiz7LN4w8sdfmKsvNs80ao/vf2JCGWWdpu95JyY90AJZRbZJmgE71dCefRiNf8OCqiZQDcUBfYiLlUNu4/j5A==", + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/cacache/-/cacache-11.2.0.tgz", + "integrity": "sha512-IFWl6lfK6wSeYCHUXh+N1lY72UDrpyrYQJNIVQf48paDuWbv5RbAtJYf/4gUQFObTCHZwdZ5sI8Iw7nqwP6nlQ==", "requires": { "bluebird": "^3.5.1", "chownr": "^1.0.1", "figgy-pudding": "^3.1.0", "glob": "^7.1.2", "graceful-fs": "^4.1.11", - "lru-cache": "^4.1.2", + "lru-cache": "^4.1.3", "mississippi": "^3.0.0", "mkdirp": "^0.5.1", "move-concurrently": "^1.0.1", @@ -324,15 +324,6 @@ "y18n": "^4.0.0" }, "dependencies": { - "lru-cache": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz", - "integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==", - "requires": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - }, "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", @@ -1052,7 +1043,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, "requires": { "ms": "2.0.0" } @@ -1652,9 +1642,9 @@ } }, "figgy-pudding": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.1.0.tgz", - "integrity": "sha512-Gi2vIue0ec6P/7LNpueGhLuvfF2ztuterl8YFBQn1yKgIS46noGxCbi+vviPdObNYtgUSh5FpHy5q0Cw9XhxKQ==" + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz", + "integrity": "sha512-vNKxJHTEKNThjfrdJwHc7brvM6eVevuO5nTj6ez8ZQ1qbXTvGthucRF7S4vf2cr71QVnT70V34v0S1DyQsti0w==" }, "figures": { "version": "2.0.0", @@ -2234,16 +2224,6 @@ "requires": { "agent-base": "4", "debug": "3.1.0" - }, - "dependencies": { - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "requires": { - "ms": "2.0.0" - } - } } }, "http-signature": { @@ -2263,16 +2243,6 @@ "requires": { "agent-base": "^4.1.0", "debug": "^3.1.0" - }, - "dependencies": { - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "requires": { - "ms": "2.0.0" - } - } } }, "humanize-ms": { @@ -2335,8 +2305,7 @@ "ini": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", - "dev": true + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" }, "inquirer": { "version": "3.3.0", @@ -2637,8 +2606,7 @@ "jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", - "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=", - "dev": true + "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=" }, "jsprim": { "version": "1.4.1", @@ -2813,7 +2781,6 @@ "version": "4.1.3", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz", "integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==", - "dev": true, "requires": { "pseudomap": "^1.0.2", "yallist": "^2.1.2" @@ -2835,17 +2802,6 @@ "promise-retry": "^1.1.1", "socks-proxy-agent": "^4.0.0", "ssri": "^6.0.0" - }, - "dependencies": { - "lru-cache": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz", - "integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==", - "requires": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - } } }, "map-obj": { @@ -3148,9 +3104,9 @@ } }, "npm-bundled": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.0.3.tgz", - "integrity": "sha512-ByQ3oJ/5ETLyglU2+8dBObvhfWXX8dtPZDMePCahptliFX2iIuhyEszyFk401PZUNQH20vvdW5MLjJxkwU80Ow==" + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.0.5.tgz", + "integrity": "sha512-m/e6jgWu8/v5niCUKQi9qQl8QdeEduFA96xHDDzFGqly0OOjI7c+60KM/2sppfnUU9JJagf+zs+yGhqSOFj71g==" }, "npm-lifecycle": { "version": "2.0.3", @@ -3211,9 +3167,9 @@ } }, "npm-packlist": { - "version": "1.1.10", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.1.10.tgz", - "integrity": "sha512-AQC0Dyhzn4EiYEfIUjCdMl0JJ61I2ER9ukf/sLxJUcZHfo+VyEfz2rMJgLZSS1v30OxPQe1cN0LZA1xbcaVfWA==", + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.1.11.tgz", + "integrity": "sha512-CxKlZ24urLkJk+9kCm48RTQ7L4hsmgSVzEk0TLGPzzyuFxD7VNgy5Sl24tOLMzQv773a/NeJ1ce1DKeacqffEA==", "requires": { "ignore-walk": "^3.0.1", "npm-bundled": "^1.0.1" @@ -3229,9 +3185,33 @@ }, "dependencies": { "semver": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + "version": "5.5.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz", + "integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==" + } + } + }, + "npm-registry-fetch": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/npm-registry-fetch/-/npm-registry-fetch-3.8.0.tgz", + "integrity": "sha512-hrw8UMD+Nob3Kl3h8Z/YjmKamb1gf7D1ZZch2otrIXM3uFLB5vjEY6DhMlq80z/zZet6eETLbOXcuQudCB3Zpw==", + "requires": { + "JSONStream": "^1.3.4", + "bluebird": "^3.5.1", + "figgy-pudding": "^3.4.1", + "lru-cache": "^4.1.3", + "make-fetch-happen": "^4.0.1", + "npm-package-arg": "^6.1.0" + }, + "dependencies": { + "JSONStream": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.4.tgz", + "integrity": "sha512-Y7vfi3I5oMOYIr+WxV8NZxDSwcbNgzdKYsTNInmycOq9bUYwGg9ryu57Wg5NLmCjqdFPNUmpMBo3kSJN9tCbXg==", + "requires": { + "jsonparse": "^1.2.0", + "through": ">=2.2.7 <3" + } } } }, @@ -6043,12 +6023,13 @@ "dev": true }, "pacote": { - "version": "8.1.6", - "resolved": "https://registry.npmjs.org/pacote/-/pacote-8.1.6.tgz", - "integrity": "sha512-wTOOfpaAQNEQNtPEx92x9Y9kRWVu45v583XT8x2oEV2xRB74+xdqMZIeGW4uFvAyZdmSBtye+wKdyyLaT8pcmw==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/pacote/-/pacote-9.1.0.tgz", + "integrity": "sha512-AFXaSWhOtQf3jHqEvg+ZYH/dfT8TKq6TKspJ4qEFwVVuh5aGvMIk6SNF8vqfzz+cBceDIs9drOcpBbrPai7i+g==", "requires": { "bluebird": "^3.5.1", "cacache": "^11.0.2", + "figgy-pudding": "^3.2.1", "get-stream": "^3.0.0", "glob": "^7.1.2", "lru-cache": "^4.1.3", @@ -6061,6 +6042,7 @@ "npm-package-arg": "^6.1.0", "npm-packlist": "^1.1.10", "npm-pick-manifest": "^2.1.0", + "npm-registry-fetch": "^3.0.0", "osenv": "^0.1.5", "promise-inflight": "^1.0.1", "promise-retry": "^1.1.1", @@ -6074,29 +6056,13 @@ "which": "^1.3.0" }, "dependencies": { - "lru-cache": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz", - "integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==", - "requires": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - }, "minipass": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.3.tgz", - "integrity": "sha512-/jAn9/tEX4gnpyRATxgHEOV6xbcyxgT7iUnxo9Y3+OB0zX00TgKIv/2FZCf5brBbICcwbLqVv2ImjvWWrQMSYw==", + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.4.tgz", + "integrity": "sha512-mlouk1OHlaUE8Odt1drMtG1bAJA4ZA6B/ehysgV0LUIrDHdKgo1KorZq3pK0b/7Z7LJIQ12MNM6aC+Tn6lUZ5w==", "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" - }, - "dependencies": { - "yallist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.2.tgz", - "integrity": "sha1-hFK0u36Dx8GI2AQcGoN8dz1ti7k=" - } } }, "normalize-package-data": { @@ -6116,14 +6082,14 @@ "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "semver": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" + "version": "5.5.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz", + "integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==" }, "tar": { - "version": "4.4.3", - "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.3.tgz", - "integrity": "sha512-LBw+tcY+/iCCTvF4i3SjqKWIgixSs/dB+Elg3BaY0MXh03D9jWclYskg3BiOkgg414NqpFI3nRgr2Qnw5jJs7Q==", + "version": "4.4.6", + "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.6.tgz", + "integrity": "sha512-tMkTnh9EdzxyfW+6GK6fCahagXsnYk6kE6S9Gr9pjVdys769+laCTbodXDhPAjzVtEBazRgP0gYqOjnk9dQzLg==", "requires": { "chownr": "^1.0.1", "fs-minipass": "^1.2.5", @@ -6132,22 +6098,20 @@ "mkdirp": "^0.5.0", "safe-buffer": "^5.1.2", "yallist": "^3.0.2" - }, - "dependencies": { - "yallist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.2.tgz", - "integrity": "sha1-hFK0u36Dx8GI2AQcGoN8dz1ti7k=" - } } }, "which": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz", - "integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "requires": { "isexe": "^2.0.0" } + }, + "yallist": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.2.tgz", + "integrity": "sha1-hFK0u36Dx8GI2AQcGoN8dz1ti7k=" } } }, @@ -6754,9 +6718,9 @@ "integrity": "sha512-RFqinRVJVcCAL9Uh1oVqE6FZkqsyLiVOYEZ20TqIOjuX7iFVJ+zsbs4RIghnw/pTs7mZvt8ZHhvm1ZUrR4fykg==" }, "socks": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/socks/-/socks-2.2.0.tgz", - "integrity": "sha512-uRKV9uXQ9ytMbGm2+DilS1jB7N3AC0mmusmW5TVWjNuBZjxS8+lX38fasKVY9I4opv/bY/iqTbcpFFaTwpfwRg==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.2.1.tgz", + "integrity": "sha512-0GabKw7n9mI46vcNrVfs0o6XzWzjVa3h6GaSo2UPxtWAROXUWavfJWh1M4PR5tnE0dcnQXZIDFP4yrAysLze/w==", "requires": { "ip": "^1.1.5", "smart-buffer": "^4.0.1" @@ -6856,9 +6820,12 @@ } }, "ssri": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.0.tgz", - "integrity": "sha512-zYOGfVHPhxyzwi8MdtdNyxv3IynWCIM4jYReR48lqu0VngxgH1c+C6CmipRdJ55eVByTJV/gboFEEI7TEQI8DA==" + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz", + "integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==", + "requires": { + "figgy-pudding": "^3.5.1" + } }, "stack-utils": { "version": "1.0.1", @@ -6932,9 +6899,9 @@ } }, "stream-each": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/stream-each/-/stream-each-1.2.2.tgz", - "integrity": "sha512-mc1dbFhGBxvTM3bIWmAAINbqiuAk9TATcfIQC8P+/+HJefgaiTlMn2dHvkX8qlI12KeYKSQ1Ua9RrIqrn1VPoA==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/stream-each/-/stream-each-1.2.3.tgz", + "integrity": "sha512-vlMC2f8I2u/bZGqkdfLQW/13Zihpej/7PmSiMQsbYddxuTsJp8vRe2x2FvVExZg7FaOds43ROAuFJwPR4MTZLw==", "requires": { "end-of-stream": "^1.1.0", "stream-shift": "^1.0.0" @@ -7266,8 +7233,7 @@ "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", - "dev": true + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" }, "through2": { "version": "2.0.3", diff --git a/package.json b/package.json index c089f0d..ff5be11 100644 --- a/package.json +++ b/package.json @@ -32,15 +32,16 @@ "dependencies": { "bin-links": "^1.1.2", "bluebird": "^3.5.1", + "figgy-pudding": "^3.5.1", "find-npm-prefix": "^1.0.2", "graceful-fs": "^4.1.11", + "ini": "^1.3.5", "lock-verify": "^2.0.2", "mkdirp": "^0.5.1", "npm-lifecycle": "^2.0.3", "npm-logical-tree": "^1.2.1", "npm-package-arg": "^6.1.0", - "pacote": "^8.1.6", - "protoduck": "^5.0.0", + "pacote": "^9.1.0", "read-package-json": "^2.0.13", "rimraf": "^2.6.2", "worker-farm": "^1.6.0" diff --git a/test/specs/index.js b/test/specs/index.js index 5c01473..17ccb0f 100644 --- a/test/specs/index.js +++ b/test/specs/index.js @@ -2,7 +2,6 @@ const BB = require('bluebird') -const npmConfig = require('../../lib/config/npm-config.js') const npmlog = require('npmlog') const fixtureHelper = require('../lib/fixtureHelper.js') const fs = BB.promisifyAll(require('fs')) @@ -37,15 +36,13 @@ const Installer = requireInject('../../index.js', { }) function run (moreOpts) { - return new Installer({ + return new Installer(Object.assign({ log: npmlog, - config: npmConfig.fromObject(Object.assign({}, { - global: true, - prefix, - 'unsafe-perm': true, // this is the default when running non-root - loglevel: process.env.LOGLEVEL || 'error' - }, moreOpts || {})) - }).run() + global: true, + prefix, + 'unsafe-perm': true, // this is the default when running non-root + loglevel: process.env.LOGLEVEL || 'error' + }, moreOpts || {})).run() } test('throws error when no package.json is found', t => { diff --git a/test/specs/lib/config.js b/test/specs/lib/config.js index bd1e144..564eece 100644 --- a/test/specs/lib/config.js +++ b/test/specs/lib/config.js @@ -56,19 +56,12 @@ test('config: errors if npm errors for any reason', t => { test('config: parses configs from npm', t => { cleanup() - const expectedConfig = { a: 1, b: 2 } - - config().then(config => { - const objConf = {} - for (const k of config.keys()) { - objConf[k] = config.get(k) - } - t.deepEqual(objConf, expectedConfig, 'configs match') - t.end() - }) - - child.stdout.emit('data', JSON.stringify(expectedConfig)) + const c = config() + child.stdout.emit('data', JSON.stringify({cache: 'foo'})) child.emit('close', 0) + return c.then(config => { + t.deepEqual(config.cache, 'foo/_cacache', 'configs match') + }) }) test('config: cleanup', t => { diff --git a/test/specs/lib/pacote-opts.js b/test/specs/lib/pacote-opts.js deleted file mode 100644 index 7479c7c..0000000 --- a/test/specs/lib/pacote-opts.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict' - -const test = require('tap').test - -const npmConfig = require('../../../lib/config/npm-config.js') -const pacoteOpts = require('../../../lib/config/pacote-opts.js') - -test('returns a config object usable by pacote', t => { - const opts = pacoteOpts(npmConfig.fromObject({ - ca: 'idk', - cache: '/foo', - 'maxsockets': '10', - 'fetch-retries': 23, - _authToken: 'deadbeef', - '//registry.npmjs.org:_authToken': 'c0ffee', - '@myscope:registry': 'https://my-other.registry.internet/' - }), { - rootPkg: require('../../../package.json') - }) - - t.equal(opts.ca, 'idk', 'ca passed through as-is') - t.equal(opts.cache.replace(/[\\]/g, '/'), '/foo/_cacache', 'cache path has _cacache appended') - t.equal(opts.maxSockets, 10, 'maxSockets converted to number') - t.equal(opts.retry.retries, 23, 'retries put into object') - t.similar(opts.auth, { - token: 'deadbeef', - '//registry.npmjs.org': { - token: 'c0ffee' - } - }) - t.deepEqual(opts.scopeTargets, { - '@myscope': 'https://my-other.registry.internet/' - }, 'scope target included') - t.done() -})