diff options
Diffstat (limited to 'deps/npm/lib/config')
-rw-r--r-- | deps/npm/lib/config/bin-links.js | 32 | ||||
-rw-r--r-- | deps/npm/lib/config/core.js | 1 | ||||
-rw-r--r-- | deps/npm/lib/config/defaults.js | 4 | ||||
-rw-r--r-- | deps/npm/lib/config/fetch-opts.js | 77 | ||||
-rw-r--r-- | deps/npm/lib/config/find-prefix.js | 56 | ||||
-rw-r--r-- | deps/npm/lib/config/gentle-fs.js | 32 | ||||
-rw-r--r-- | deps/npm/lib/config/lifecycle.js | 1 | ||||
-rw-r--r-- | deps/npm/lib/config/load-prefix.js | 8 |
8 files changed, 150 insertions, 61 deletions
diff --git a/deps/npm/lib/config/bin-links.js b/deps/npm/lib/config/bin-links.js new file mode 100644 index 0000000000..1ee90cc35e --- /dev/null +++ b/deps/npm/lib/config/bin-links.js @@ -0,0 +1,32 @@ +'use strict' + +const npm = require('../npm.js') +var packageId = require('../utils/package-id.js') +const log = require('npmlog') + +module.exports = binLinksOpts + +function binLinksOpts (pkg) { + return { + ignoreScripts: npm.config.get('ignore-scripts'), + force: npm.config.get('force'), + globalBin: npm.globalBin, + globalDir: npm.globalDir, + json: npm.config.get('json'), + log: log, + name: 'npm', + parseable: npm.config.get('parseable'), + pkgId: packageId(pkg), + prefix: npm.config.get('prefix'), + prefixes: [ + npm.prefix, + npm.globalPrefix, + npm.dir, + npm.root, + npm.globalDir, + npm.bin, + npm.globalBin + ], + umask: npm.config.get('umask') + } +} diff --git a/deps/npm/lib/config/core.js b/deps/npm/lib/config/core.js index 15a1674b3d..50cf4772e7 100644 --- a/deps/npm/lib/config/core.js +++ b/deps/npm/lib/config/core.js @@ -225,7 +225,6 @@ Conf.prototype.loadPrefix = require('./load-prefix.js') Conf.prototype.loadCAFile = require('./load-cafile.js') Conf.prototype.loadUid = require('./load-uid.js') Conf.prototype.setUser = require('./set-user.js') -Conf.prototype.findPrefix = require('./find-prefix.js') Conf.prototype.getCredentialsByURI = require('./get-credentials-by-uri.js') Conf.prototype.setCredentialsByURI = require('./set-credentials-by-uri.js') Conf.prototype.clearCredentialsByURI = require('./clear-credentials-by-uri.js') diff --git a/deps/npm/lib/config/defaults.js b/deps/npm/lib/config/defaults.js index 35617fd638..c049f213fa 100644 --- a/deps/npm/lib/config/defaults.js +++ b/deps/npm/lib/config/defaults.js @@ -176,6 +176,7 @@ Object.defineProperty(exports, 'defaults', {get: function () { maxsockets: 50, message: '%s', 'metrics-registry': null, + 'node-options': null, 'node-version': process.version, 'offline': false, 'onload-script': false, @@ -183,6 +184,7 @@ Object.defineProperty(exports, 'defaults', {get: function () { optional: true, otp: null, 'package-lock': true, + 'package-lock-only': false, parseable: false, 'prefer-offline': false, 'prefer-online': false, @@ -308,6 +310,7 @@ exports.types = { maxsockets: Number, message: String, 'metrics-registry': [null, String], + 'node-options': [null, String], 'node-version': [null, semver], offline: Boolean, 'onload-script': [null, String], @@ -315,6 +318,7 @@ exports.types = { optional: Boolean, 'package-lock': Boolean, otp: Number, + 'package-lock-only': Boolean, parseable: Boolean, 'prefer-offline': Boolean, 'prefer-online': Boolean, diff --git a/deps/npm/lib/config/fetch-opts.js b/deps/npm/lib/config/fetch-opts.js new file mode 100644 index 0000000000..1a030c378e --- /dev/null +++ b/deps/npm/lib/config/fetch-opts.js @@ -0,0 +1,77 @@ +'use strict' + +const url = require('url') + +module.exports.fromPacote = fromPacote + +function fromPacote (opts) { + return { + cache: getCacheMode(opts), + cacheManager: opts.cache, + ca: opts.ca, + cert: opts.cert, + headers: getHeaders('', opts.registry, opts), + key: opts.key, + localAddress: opts.localAddress, + maxSockets: opts.maxSockets, + proxy: opts.proxy, + referer: opts.refer, + retry: opts.retry, + strictSSL: !!opts.strictSSL, + timeout: opts.timeout, + uid: opts.uid, + gid: opts.gid + } +} + +function getCacheMode (opts) { + return opts.offline + ? 'only-if-cached' + : opts.preferOffline + ? 'force-cache' + : opts.preferOnline + ? 'no-cache' + : 'default' +} + +function getHeaders (uri, registry, opts) { + const headers = Object.assign({ + 'npm-in-ci': opts.isFromCI, + 'npm-scope': opts.projectScope, + 'npm-session': opts.npmSession, + 'user-agent': opts.userAgent, + 'referer': opts.refer + }, opts.headers) + // check for auth settings specific to this registry + let auth = ( + opts.auth && + opts.auth[registryKey(registry)] + ) || opts.auth + // If a tarball is hosted on a different place than the manifest, only send + // credentials on `alwaysAuth` + const shouldAuth = auth && ( + auth.alwaysAuth || + url.parse(uri).host === url.parse(registry).host + ) + if (shouldAuth && auth.token) { + headers.authorization = `Bearer ${auth.token}` + } else if (shouldAuth && auth.username && auth.password) { + const encoded = Buffer.from( + `${auth.username}:${auth.password}`, 'utf8' + ).toString('base64') + headers.authorization = `Basic ${encoded}` + } else if (shouldAuth && auth._auth) { + headers.authorization = `Basic ${auth._auth}` + } + return headers +} + +function registryKey (registry) { + const parsed = url.parse(registry) + const formatted = url.format({ + host: parsed.host, + pathname: parsed.pathname, + slashes: parsed.slashes + }) + return url.resolve(formatted, '.') +} diff --git a/deps/npm/lib/config/find-prefix.js b/deps/npm/lib/config/find-prefix.js deleted file mode 100644 index 58f5cc8040..0000000000 --- a/deps/npm/lib/config/find-prefix.js +++ /dev/null @@ -1,56 +0,0 @@ -// try to find the most reasonable prefix to use - -module.exports = findPrefix - -var fs = require('fs') -var path = require('path') - -function findPrefix (p, cb_) { - function cb (er, p) { - process.nextTick(function () { - cb_(er, p) - }) - } - - p = path.resolve(p) - // if there's no node_modules folder, then - // walk up until we hopefully find one. - // if none anywhere, then use cwd. - var walkedUp = false - while (path.basename(p) === 'node_modules') { - p = path.dirname(p) - walkedUp = true - } - if (walkedUp) return cb(null, p) - - findPrefix_(p, p, cb) -} - -function findPrefix_ (p, original, cb) { - if (p === '/' || - (process.platform === 'win32' && p.match(/^[a-zA-Z]:(\\|\/)?$/))) { - return cb(null, original) - } - fs.readdir(p, function (er, files) { - // an error right away is a bad sign. - // unless the prefix was simply a non - // existent directory. - if (er && p === original) { - if (er.code === 'ENOENT') return cb(null, original) - return cb(er) - } - - // walked up too high or something. - if (er) return cb(null, original) - - if (files.indexOf('node_modules') !== -1 || - files.indexOf('package.json') !== -1) { - return cb(null, p) - } - - var d = path.dirname(p) - if (d === p) return cb(null, original) - - return findPrefix_(d, original, cb) - }) -} diff --git a/deps/npm/lib/config/gentle-fs.js b/deps/npm/lib/config/gentle-fs.js new file mode 100644 index 0000000000..c4a1f9fa22 --- /dev/null +++ b/deps/npm/lib/config/gentle-fs.js @@ -0,0 +1,32 @@ +'use strict' + +const npm = require('../npm.js') +const log = require('npmlog') + +module.exports = gentleFSOpts + +function gentleFSOpts (gently, base, abs) { + return { + // never rm the root, prefix, or bin dirs + // + // globals included because of `npm link` -- as far as the package + // requesting the link is concerned, the linked package is always + // installed globally + prefixes: [ + npm.prefix, + npm.globalPrefix, + npm.dir, + npm.root, + npm.globalDir, + npm.bin, + npm.globalBin + ], + absolute: abs, + log: log, + prefix: npm.prefix, + force: npm.config.get('force'), + gently: gently, + base: base, + name: 'npm' + } +} diff --git a/deps/npm/lib/config/lifecycle.js b/deps/npm/lib/config/lifecycle.js index 5fca93939d..86941edcd8 100644 --- a/deps/npm/lib/config/lifecycle.js +++ b/deps/npm/lib/config/lifecycle.js @@ -18,6 +18,7 @@ function lifecycleOpts (moreOpts) { ignorePrepublish: npm.config.get('ignore-prepublish'), ignoreScripts: npm.config.get('ignore-scripts'), log: log, + nodeOptions: npm.config.get('node-options'), production: npm.config.get('production'), scriptShell: npm.config.get('script-shell'), scriptsPrependNodePath: npm.config.get('scripts-prepend-node-path'), diff --git a/deps/npm/lib/config/load-prefix.js b/deps/npm/lib/config/load-prefix.js index bb5d9f3be5..c2af00c7f6 100644 --- a/deps/npm/lib/config/load-prefix.js +++ b/deps/npm/lib/config/load-prefix.js @@ -1,6 +1,6 @@ module.exports = loadPrefix -var findPrefix = require('./find-prefix.js') +var findPrefix = require('find-npm-prefix') var path = require('path') function loadPrefix (cb) { @@ -43,9 +43,9 @@ function loadPrefix (cb) { p = path.resolve(cli.prefix) process.nextTick(cb) } else { - findPrefix(process.cwd(), function (er, found) { + findPrefix(process.cwd()).then((found) => { p = found - cb(er) - }) + cb() + }, cb) } } |