From b551c6811251dbc901f47fea3c137f93e205a9e4 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Thu, 13 May 2021 12:26:04 -0400 Subject: [PATCH] libnpmfund@1.1.0 --- node_modules/libnpmfund/CHANGELOG.md | 6 --- node_modules/libnpmfund/README.md | 5 ++- node_modules/libnpmfund/index.js | 63 +++++++++++++++++----------- node_modules/libnpmfund/package.json | 19 +++++---- package-lock.json | 18 ++++---- package.json | 2 +- 6 files changed, 64 insertions(+), 49 deletions(-) delete mode 100644 node_modules/libnpmfund/CHANGELOG.md diff --git a/node_modules/libnpmfund/CHANGELOG.md b/node_modules/libnpmfund/CHANGELOG.md deleted file mode 100644 index b890b58e1405a..0000000000000 --- a/node_modules/libnpmfund/CHANGELOG.md +++ /dev/null @@ -1,6 +0,0 @@ -# Changelog - -## 0.0.0-pre.0 - -- Initial pre-release. - diff --git a/node_modules/libnpmfund/README.md b/node_modules/libnpmfund/README.md index c373a9ceb7dd5..8ab663f634d6f 100644 --- a/node_modules/libnpmfund/README.md +++ b/node_modules/libnpmfund/README.md @@ -73,7 +73,10 @@ Options: - `countOnly`: Uses the tree-traversal logic from **npm fund** but skips over any obj definition and just returns an obj containing `{ length }` - useful for things such as printing a `6 packages are looking for funding` msg. -- `path`: Location to current working directory +- `workspaces`: `Array` List of workspaces names to filter for, +the result will only include a subset of the resulting tree that includes +only the nodes that are children of the listed workspaces names. +- `path`, `registry` and more [Arborist](https://github.com/npm/arborist/) options. ##### `> fund.readTree(tree, [opts]) -> Promise` diff --git a/node_modules/libnpmfund/index.js b/node_modules/libnpmfund/index.js index 58aba028e3622..37bc1dd0b7916 100644 --- a/node_modules/libnpmfund/index.js +++ b/node_modules/libnpmfund/index.js @@ -15,11 +15,11 @@ function normalizeFunding (funding) { // 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 (!funding) + return false - if (Array.isArray(funding)) { + if (Array.isArray(funding)) return funding.every(f => !Array.isArray(f) && isValidFunding(f)) - } try { var parsed = new URL(funding.url || funding) @@ -30,7 +30,8 @@ function isValidFunding (funding) { if ( parsed.protocol !== 'https:' && parsed.protocol !== 'http:' - ) return false + ) + return false return Boolean(parsed.host) } @@ -43,11 +44,18 @@ function readTree (tree, opts) { 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)) { + if (seen.has(key)) return true - } + seen.add(key) } @@ -81,30 +89,36 @@ function readTree (tree, opts) { function getFundingDependencies (tree) { const edges = tree && tree.edgesOut && tree.edgesOut.values() - if (!edges) return empty() + if (!edges) + return empty() const directDepsWithFunding = Array.from(edges).map(edge => { - if (!edge || !edge.to) return empty() + if (!edge || !edge.to) + return empty() const node = edge.to.target || edge.to - if (!node.package) return empty() + 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() + if (tracked(name, version)) + return empty() const fundingItem = {} - if (version) { + if (version) fundingItem.version = version - } attachFundingInfo(fundingItem, funding) return { node, - fundingItem + fundingItem, } }) @@ -112,7 +126,8 @@ function readTree (tree, opts) { (res, { node, fundingItem }, i) => { if (!fundingItem || fundingItem.length === 0 || - !node) return res + !node) + return res // recurse const transitiveDependencies = node.edgesOut && @@ -121,16 +136,17 @@ function readTree (tree, opts) { // if we're only counting items there's no need // to add all the data to the resulting object - if (countOnly) return null + if (countOnly) + return null if (hasDependencies(transitiveDependencies)) { fundingItem.dependencies = retrieveDependencies(transitiveDependencies) } - if (isValidFunding(fundingItem.funding)) { + if (isValidFunding(fundingItem.funding)) res[node.package.name] = fundingItem - } else if (hasDependencies(fundingItem.dependencies)) { + else if (hasDependencies(fundingItem.dependencies)) { res[_trailingDependencies] = Object.assign( empty(), @@ -145,7 +161,7 @@ function readTree (tree, opts) { const treeDependencies = getFundingDependencies(tree) const result = { - length: packageWithFundingCount + length: packageWithFundingCount, } if (!countOnly) { @@ -154,13 +170,11 @@ function readTree (tree, opts) { (tree && tree.name) result.name = name || (tree && tree.path) - if (tree && tree.package && tree.package.version) { + if (tree && tree.package && tree.package.version) result.version = tree.package.version - } - if (tree && tree.package && tree.package.funding) { + if (tree && tree.package && tree.package.funding) result.funding = normalizeFunding(tree.package.funding) - } result.dependencies = retrieveDependencies(treeDependencies) } @@ -170,8 +184,7 @@ function readTree (tree, opts) { async function read (opts) { const arb = new Arborist(opts) - const tree = await arb.loadActual() - + const tree = await arb.loadActual(opts) return readTree(tree, opts) } @@ -179,5 +192,5 @@ module.exports = { read, readTree, normalizeFunding, - isValidFunding + isValidFunding, } diff --git a/node_modules/libnpmfund/package.json b/node_modules/libnpmfund/package.json index b25d3aa6b520e..7f4acad383bb8 100644 --- a/node_modules/libnpmfund/package.json +++ b/node_modules/libnpmfund/package.json @@ -1,6 +1,6 @@ { "name": "libnpmfund", - "version": "1.0.2", + "version": "1.1.0", "files": [ "index.js" ], @@ -25,8 +25,10 @@ ], "license": "ISC", "scripts": { - "lint": "standard", - "pretest": "npm run lint", + "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", @@ -42,11 +44,14 @@ ] }, "devDependencies": { - "require-inject": "^1.4.4", - "standard": "^14.3.4", - "tap": "^14.10.7" + "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": "^2.0.0" + "@npmcli/arborist": "^2.5.0" } } diff --git a/package-lock.json b/package-lock.json index 8b03fb6e2cf71..7ddad043e0835 100644 --- a/package-lock.json +++ b/package-lock.json @@ -104,7 +104,7 @@ "libnpmaccess": "^4.0.2", "libnpmdiff": "^2.0.4", "libnpmexec": "^1.1.1", - "libnpmfund": "^1.0.2", + "libnpmfund": "^1.1.0", "libnpmhook": "^6.0.2", "libnpmorg": "^2.0.2", "libnpmpack": "^2.0.1", @@ -4648,12 +4648,12 @@ } }, "node_modules/libnpmfund": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/libnpmfund/-/libnpmfund-1.0.2.tgz", - "integrity": "sha512-Scw2JiLxfT7wqW/VbxIXV8u3FaFT/ZlR8YLFgTdCPsL1Hhli0554ZXyP8JTu1sLeDpHsoqtgLb4mgYVQnqigjA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/libnpmfund/-/libnpmfund-1.1.0.tgz", + "integrity": "sha512-Kfmh3pLS5/RGKG5WXEig8mjahPVOxkik6lsbH4iX0si1xxNi6eeUh/+nF1MD+2cgalsQif3O5qyr6mNz2ryJrQ==", "inBundle": true, "dependencies": { - "@npmcli/arborist": "^2.0.0" + "@npmcli/arborist": "^2.5.0" } }, "node_modules/libnpmhook": { @@ -13705,11 +13705,11 @@ } }, "libnpmfund": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/libnpmfund/-/libnpmfund-1.0.2.tgz", - "integrity": "sha512-Scw2JiLxfT7wqW/VbxIXV8u3FaFT/ZlR8YLFgTdCPsL1Hhli0554ZXyP8JTu1sLeDpHsoqtgLb4mgYVQnqigjA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/libnpmfund/-/libnpmfund-1.1.0.tgz", + "integrity": "sha512-Kfmh3pLS5/RGKG5WXEig8mjahPVOxkik6lsbH4iX0si1xxNi6eeUh/+nF1MD+2cgalsQif3O5qyr6mNz2ryJrQ==", "requires": { - "@npmcli/arborist": "^2.0.0" + "@npmcli/arborist": "^2.5.0" } }, "libnpmhook": { diff --git a/package.json b/package.json index 9ac34d43b9bca..03ca369e4c899 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "libnpmaccess": "^4.0.2", "libnpmdiff": "^2.0.4", "libnpmexec": "^1.1.1", - "libnpmfund": "^1.0.2", + "libnpmfund": "^1.1.0", "libnpmhook": "^6.0.2", "libnpmorg": "^2.0.2", "libnpmpack": "^2.0.1",