diff options
author | isaacs <i@izs.me> | 2019-10-08 08:57:31 -0700 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2019-12-13 11:51:53 -0500 |
commit | f9b31edb25fcdf6602fbf8233affb791e2f849a5 (patch) | |
tree | 5e6c1818de1b32158c7f3c491bf2f87392e79ccb /deps/npm/lib/utils | |
parent | 0621e25f90c4b3bbea5b2e4f63b3ea919e47440c (diff) | |
download | node-new-f9b31edb25fcdf6602fbf8233affb791e2f849a5.tar.gz |
deps: update npm to 6.13.4
PR-URL: https://github.com/nodejs/node/pull/30904
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Diffstat (limited to 'deps/npm/lib/utils')
-rw-r--r-- | deps/npm/lib/utils/error-message.js | 5 | ||||
-rw-r--r-- | deps/npm/lib/utils/funding.js | 153 | ||||
-rw-r--r-- | deps/npm/lib/utils/open-url.js | 23 | ||||
-rw-r--r-- | deps/npm/lib/utils/unsupported.js | 5 |
4 files changed, 180 insertions, 6 deletions
diff --git a/deps/npm/lib/utils/error-message.js b/deps/npm/lib/utils/error-message.js index 5ddfb37682..12f304d1e8 100644 --- a/deps/npm/lib/utils/error-message.js +++ b/deps/npm/lib/utils/error-message.js @@ -280,8 +280,9 @@ function errorMessage (er) { case 'EEXIST': short.push(['', er.message]) - short.push(['', 'File exists: ' + er.path]) - detail.push(['', 'Move it away, and try again.']) + short.push(['', 'File exists: ' + (er.dest || er.path)]) + detail.push(['', 'Remove the existing file and try again, or run npm']) + detail.push(['', 'with --force to overwrite files recklessly.']) break case 'ENEEDAUTH': diff --git a/deps/npm/lib/utils/funding.js b/deps/npm/lib/utils/funding.js new file mode 100644 index 0000000000..c3d06b1089 --- /dev/null +++ b/deps/npm/lib/utils/funding.js @@ -0,0 +1,153 @@ +'use strict' + +const URL = require('url').URL + +exports.getFundingInfo = getFundingInfo +exports.retrieveFunding = retrieveFunding +exports.validFundingUrl = validFundingUrl + +// supports both object funding and string shorthand +function retrieveFunding (funding) { + return typeof funding === 'string' + ? { + url: funding + } + : funding +} + +// Is the value of a `funding` property of a `package.json` +// a valid type+url for `npm fund` to display? +function validFundingUrl (funding) { + if (!funding) return false + + try { + var parsed = new URL(funding.url || funding) + } catch (error) { + return false + } + + if ( + parsed.protocol !== 'https:' && + parsed.protocol !== 'http:' + ) return false + + return Boolean(parsed.host) +} + +function getFundingInfo (idealTree, opts) { + let length = 0 + const seen = new Set() + const { countOnly } = opts || {} + const empty = () => Object.create(null) + const _trailingDependencies = Symbol('trailingDependencies') + + function tracked (name, version) { + const key = String(name) + String(version) + if (seen.has(key)) { + return true + } + seen.add(key) + } + + function retrieveDependencies (dependencies) { + const trailing = dependencies[_trailingDependencies] + + if (trailing) { + return Object.assign( + empty(), + dependencies, + trailing + ) + } + + return dependencies + } + + function hasDependencies (dependencies) { + return dependencies && ( + Object.keys(dependencies).length || + dependencies[_trailingDependencies] + ) + } + + function getFundingDependencies (tree) { + const deps = tree && tree.dependencies + if (!deps) return empty() + + // broken into two steps to make sure items appearance + // within top levels takes precedence over nested ones + return (Object.keys(deps)).map((key) => { + const dep = deps[key] + const { name, funding, version } = dep + + const fundingItem = {} + + // avoids duplicated items within the funding tree + if (tracked(name, version)) return empty() + + if (version) { + fundingItem.version = version + } + + if (funding && validFundingUrl(funding)) { + fundingItem.funding = retrieveFunding(funding) + length++ + } + + return { + dep, + fundingItem + } + }).reduce((res, { dep, fundingItem }, i) => { + if (!fundingItem) return res + + // recurse + const dependencies = dep.dependencies && + Object.keys(dep.dependencies).length > 0 && + getFundingDependencies(dep) + + // if we're only counting items there's no need + // to add all the data to the resulting object + if (countOnly) return null + + if (hasDependencies(dependencies)) { + fundingItem.dependencies = retrieveDependencies(dependencies) + } + + if (fundingItem.funding) { + res[dep.name] = fundingItem + } else if (fundingItem.dependencies) { + res[_trailingDependencies] = + Object.assign( + empty(), + res[_trailingDependencies], + fundingItem.dependencies + ) + } + + return res + }, empty()) + } + + const idealTreeDependencies = getFundingDependencies(idealTree) + const result = { + length + } + + if (!countOnly) { + result.name = idealTree.name || idealTree.path + + if (idealTree && idealTree.version) { + result.version = idealTree.version + } + + if (idealTree && idealTree.funding) { + result.funding = retrieveFunding(idealTree.funding) + } + + result.dependencies = + retrieveDependencies(idealTreeDependencies) + } + + return result +} diff --git a/deps/npm/lib/utils/open-url.js b/deps/npm/lib/utils/open-url.js index 7a48d2e868..e1ed2b3fab 100644 --- a/deps/npm/lib/utils/open-url.js +++ b/deps/npm/lib/utils/open-url.js @@ -5,9 +5,28 @@ const opener = require('opener') // attempt to open URL in web-browser, print address otherwise: module.exports = function open (url, errMsg, cb, browser = npm.config.get('browser')) { - opener(url, { command: npm.config.get('browser') }, (er) => { + function printAlternateMsg () { + const json = npm.config.get('json') + const alternateMsg = json + ? JSON.stringify({ + title: errMsg, + url + }, null, 2) + : `${errMsg}:\n\n${url}` + + output(alternateMsg) + } + + const skipBrowser = process.argv.indexOf('--no-browser') > -1 + + if (skipBrowser) { + printAlternateMsg() + return cb() + } + + opener(url, { command: browser }, (er) => { if (er && er.code === 'ENOENT') { - output(`${errMsg}:\n\n${url}`) + printAlternateMsg() return cb() } else { return cb(er) diff --git a/deps/npm/lib/utils/unsupported.js b/deps/npm/lib/utils/unsupported.js index 20cee157ee..71a304030e 100644 --- a/deps/npm/lib/utils/unsupported.js +++ b/deps/npm/lib/utils/unsupported.js @@ -6,9 +6,10 @@ var supportedNode = [ {ver: '9', min: '9.0.0'}, {ver: '10', min: '10.0.0'}, {ver: '11', min: '11.0.0'}, - {ver: '12', min: '12.0.0'} + {ver: '12', min: '12.0.0'}, + {ver: '13', min: '13.0.0'} ] -var knownBroken = '<6.0.0' +var knownBroken = '<6.2.0 || 9.0 - 9.2' var checkVersion = exports.checkVersion = function (version) { var versionNoPrerelease = version.replace(/-.*$/, '') |