diff options
author | Nathan Fritz <fritzy@github.com> | 2021-12-16 21:01:56 +0300 |
---|---|---|
committer | Nathan Fritz <fritzy@github.com> | 2021-12-16 21:05:19 +0300 |
commit | d7265045730555c03b3142c004c7438e9577028c (patch) | |
tree | 035d81b3124bdaa09c21854934bf2b2b50e52e44 /node_modules/libnpmfund | |
parent | d8aac8448e983692cacb427e03f4688cd1b62e30 (diff) |
Bring in all libnpm modules + arborist as workspaces (#4166)
Added libnpm workspaces and arborist
Diffstat (limited to 'node_modules/libnpmfund')
l--------- | node_modules/libnpmfund | 1 | ||||
-rw-r--r-- | node_modules/libnpmfund/LICENSE | 15 | ||||
-rw-r--r-- | node_modules/libnpmfund/index.js | 196 | ||||
-rw-r--r-- | node_modules/libnpmfund/package.json | 60 |
4 files changed, 1 insertions, 271 deletions
diff --git a/node_modules/libnpmfund b/node_modules/libnpmfund new file mode 120000 index 000000000..d82688b40 --- /dev/null +++ b/node_modules/libnpmfund @@ -0,0 +1 @@ +../workspaces/libnpmfund
\ No newline at end of file diff --git a/node_modules/libnpmfund/LICENSE b/node_modules/libnpmfund/LICENSE deleted file mode 100644 index dedcd7d2f..000000000 --- a/node_modules/libnpmfund/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -The ISC License - -Copyright (c) npm Inc. - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/node_modules/libnpmfund/index.js b/node_modules/libnpmfund/index.js deleted file mode 100644 index 37bc1dd0b..000000000 --- a/node_modules/libnpmfund/index.js +++ /dev/null @@ -1,196 +0,0 @@ -'use strict' - -const URL = require('url').URL -const Arborist = require('@npmcli/arborist') - -// supports object funding and string shorthand, or an array of these -// if original was an array, returns an array; else returns the lone item -function normalizeFunding (funding) { - const normalizeItem = item => - typeof item === 'string' ? { url: item } : item - const sources = [].concat(funding || []).map(normalizeItem) - return Array.isArray(funding) ? sources : sources[0] -} - -// Is the value of a `funding` property of a `package.json` -// a valid type+url for `npm fund` to display? -function isValidFunding (funding) { - if (!funding) - return false - - if (Array.isArray(funding)) - return funding.every(f => !Array.isArray(f) && isValidFunding(f)) - - 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) -} - -const empty = () => Object.create(null) - -function readTree (tree, opts) { - let packageWithFundingCount = 0 - const seen = new Set() - const { countOnly } = opts || {} - const _trailingDependencies = Symbol('trailingDependencies') - - let filterSet - - if (opts && opts.workspaces && opts.workspaces.length) { - const arb = new Arborist(opts) - filterSet = arb.workspaceDependencySet(tree, opts.workspaces) - } - - 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 attachFundingInfo (target, funding) { - if (funding && isValidFunding(funding)) { - target.funding = normalizeFunding(funding) - packageWithFundingCount++ - } - } - - function getFundingDependencies (tree) { - const edges = tree && tree.edgesOut && tree.edgesOut.values() - if (!edges) - return empty() - - const directDepsWithFunding = Array.from(edges).map(edge => { - if (!edge || !edge.to) - return empty() - - const node = edge.to.target || edge.to - if (!node.package) - return empty() - - if (filterSet && filterSet.size > 0 && !filterSet.has(node)) - return empty() - - const { name, funding, version } = node.package - - // avoids duplicated items within the funding tree - if (tracked(name, version)) - return empty() - - const fundingItem = {} - - if (version) - fundingItem.version = version - - attachFundingInfo(fundingItem, funding) - - return { - node, - fundingItem, - } - }) - - return directDepsWithFunding.reduce( - (res, { node, fundingItem }, i) => { - if (!fundingItem || - fundingItem.length === 0 || - !node) - return res - - // recurse - const transitiveDependencies = node.edgesOut && - node.edgesOut.size > 0 && - getFundingDependencies(node) - - // 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(transitiveDependencies)) { - fundingItem.dependencies = - retrieveDependencies(transitiveDependencies) - } - - if (isValidFunding(fundingItem.funding)) - res[node.package.name] = fundingItem - else if (hasDependencies(fundingItem.dependencies)) { - res[_trailingDependencies] = - Object.assign( - empty(), - res[_trailingDependencies], - fundingItem.dependencies - ) - } - - return res - }, countOnly ? null : empty()) - } - - const treeDependencies = getFundingDependencies(tree) - const result = { - length: packageWithFundingCount, - } - - if (!countOnly) { - const name = - (tree && tree.package && tree.package.name) || - (tree && tree.name) - result.name = name || (tree && tree.path) - - if (tree && tree.package && tree.package.version) - result.version = tree.package.version - - if (tree && tree.package && tree.package.funding) - result.funding = normalizeFunding(tree.package.funding) - - result.dependencies = retrieveDependencies(treeDependencies) - } - - return result -} - -async function read (opts) { - const arb = new Arborist(opts) - const tree = await arb.loadActual(opts) - return readTree(tree, opts) -} - -module.exports = { - read, - readTree, - normalizeFunding, - isValidFunding, -} diff --git a/node_modules/libnpmfund/package.json b/node_modules/libnpmfund/package.json deleted file mode 100644 index 2bd474199..000000000 --- a/node_modules/libnpmfund/package.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "name": "libnpmfund", - "version": "2.0.1", - "files": [ - "index.js" - ], - "description": "Programmatic API for npm fund", - "repository": "https://github.com/npm/libnpmfund", - "keywords": [ - "npm", - "npmcli", - "libnpm", - "cli", - "git", - "fund", - "gitfund" - ], - "author": "npm Inc. <support@npmjs.com>", - "contributors": [ - { - "name": "Ruy Adorno", - "url": "https://ruyadorno.com", - "twitter": "ruyadorno" - } - ], - "license": "ISC", - "scripts": { - "eslint": "eslint", - "lint": "npm run eslint -- index.js test.js", - "lintfix": "npm run lint -- --fix", - "posttest": "npm run lint", - "test": "tap", - "snap": "tap", - "preversion": "npm test", - "postversion": "npm publish", - "prepublishOnly": "git push origin --follow-tags" - }, - "tap": { - "check-coverage": true - }, - "standard": { - "ignore": [ - "/tap-snapshots/" - ] - }, - "devDependencies": { - "eslint": "^7.26.0", - "eslint-plugin-import": "^2.22.1", - "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^5.1.0", - "eslint-plugin-standard": "^5.0.0", - "tap": "^15.0.9" - }, - "dependencies": { - "@npmcli/arborist": "^4.0.0" - }, - "engines": { - "node": "^12.13.0 || ^14.15.0 || >=16" - } -} |