libnpmfund 1.0.2 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -73,7 +73,10 @@ Options:
73
73
  - `countOnly`: Uses the tree-traversal logic from **npm fund** but skips over
74
74
  any obj definition and just returns an obj containing `{ length }` - useful for
75
75
  things such as printing a `6 packages are looking for funding` msg.
76
- - `path`: Location to current working directory
76
+ - `workspaces`: `Array<String>` List of workspaces names to filter for,
77
+ the result will only include a subset of the resulting tree that includes
78
+ only the nodes that are children of the listed workspaces names.
79
+ - `path`, `registry` and more [Arborist](https://github.com/npm/arborist/) options.
77
80
 
78
81
  ##### <a name="fund.readTree"></a> `> fund.readTree(tree, [opts]) -> Promise<Object>`
79
82
 
@@ -15,7 +15,9 @@ function normalizeFunding (funding) {
15
15
  // Is the value of a `funding` property of a `package.json`
16
16
  // a valid type+url for `npm fund` to display?
17
17
  function isValidFunding (funding) {
18
- if (!funding) return false
18
+ if (!funding) {
19
+ return false
20
+ }
19
21
 
20
22
  if (Array.isArray(funding)) {
21
23
  return funding.every(f => !Array.isArray(f) && isValidFunding(f))
@@ -30,7 +32,9 @@ function isValidFunding (funding) {
30
32
  if (
31
33
  parsed.protocol !== 'https:' &&
32
34
  parsed.protocol !== 'http:'
33
- ) return false
35
+ ) {
36
+ return false
37
+ }
34
38
 
35
39
  return Boolean(parsed.host)
36
40
  }
@@ -43,11 +47,19 @@ function readTree (tree, opts) {
43
47
  const { countOnly } = opts || {}
44
48
  const _trailingDependencies = Symbol('trailingDependencies')
45
49
 
50
+ let filterSet
51
+
52
+ if (opts && opts.workspaces && opts.workspaces.length) {
53
+ const arb = new Arborist(opts)
54
+ filterSet = arb.workspaceDependencySet(tree, opts.workspaces)
55
+ }
56
+
46
57
  function tracked (name, version) {
47
58
  const key = String(name) + String(version)
48
59
  if (seen.has(key)) {
49
60
  return true
50
61
  }
62
+
51
63
  seen.add(key)
52
64
  }
53
65
 
@@ -81,18 +93,30 @@ function readTree (tree, opts) {
81
93
 
82
94
  function getFundingDependencies (tree) {
83
95
  const edges = tree && tree.edgesOut && tree.edgesOut.values()
84
- if (!edges) return empty()
96
+ if (!edges) {
97
+ return empty()
98
+ }
85
99
 
86
100
  const directDepsWithFunding = Array.from(edges).map(edge => {
87
- if (!edge || !edge.to) return empty()
101
+ if (!edge || !edge.to) {
102
+ return empty()
103
+ }
88
104
 
89
105
  const node = edge.to.target || edge.to
90
- if (!node.package) return empty()
106
+ if (!node.package) {
107
+ return empty()
108
+ }
109
+
110
+ if (filterSet && filterSet.size > 0 && !filterSet.has(node)) {
111
+ return empty()
112
+ }
91
113
 
92
114
  const { name, funding, version } = node.package
93
115
 
94
116
  // avoids duplicated items within the funding tree
95
- if (tracked(name, version)) return empty()
117
+ if (tracked(name, version)) {
118
+ return empty()
119
+ }
96
120
 
97
121
  const fundingItem = {}
98
122
 
@@ -104,7 +128,7 @@ function readTree (tree, opts) {
104
128
 
105
129
  return {
106
130
  node,
107
- fundingItem
131
+ fundingItem,
108
132
  }
109
133
  })
110
134
 
@@ -112,7 +136,9 @@ function readTree (tree, opts) {
112
136
  (res, { node, fundingItem }, i) => {
113
137
  if (!fundingItem ||
114
138
  fundingItem.length === 0 ||
115
- !node) return res
139
+ !node) {
140
+ return res
141
+ }
116
142
 
117
143
  // recurse
118
144
  const transitiveDependencies = node.edgesOut &&
@@ -121,7 +147,9 @@ function readTree (tree, opts) {
121
147
 
122
148
  // if we're only counting items there's no need
123
149
  // to add all the data to the resulting object
124
- if (countOnly) return null
150
+ if (countOnly) {
151
+ return null
152
+ }
125
153
 
126
154
  if (hasDependencies(transitiveDependencies)) {
127
155
  fundingItem.dependencies =
@@ -145,7 +173,7 @@ function readTree (tree, opts) {
145
173
 
146
174
  const treeDependencies = getFundingDependencies(tree)
147
175
  const result = {
148
- length: packageWithFundingCount
176
+ length: packageWithFundingCount,
149
177
  }
150
178
 
151
179
  if (!countOnly) {
@@ -170,8 +198,7 @@ function readTree (tree, opts) {
170
198
 
171
199
  async function read (opts) {
172
200
  const arb = new Arborist(opts)
173
- const tree = await arb.loadActual()
174
-
201
+ const tree = await arb.loadActual(opts)
175
202
  return readTree(tree, opts)
176
203
  }
177
204
 
@@ -179,5 +206,5 @@ module.exports = {
179
206
  read,
180
207
  readTree,
181
208
  normalizeFunding,
182
- isValidFunding
209
+ isValidFunding,
183
210
  }
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "libnpmfund",
3
- "version": "1.0.2",
3
+ "version": "2.0.2",
4
+ "main": "lib/index.js",
4
5
  "files": [
5
- "index.js"
6
+ "bin",
7
+ "lib"
6
8
  ],
7
9
  "description": "Programmatic API for npm fund",
8
10
  "repository": "https://github.com/npm/libnpmfund",
@@ -15,7 +17,7 @@
15
17
  "fund",
16
18
  "gitfund"
17
19
  ],
18
- "author": "npm Inc. <support@npmjs.com>",
20
+ "author": "GitHub Inc.",
19
21
  "contributors": [
20
22
  {
21
23
  "name": "Ruy Adorno",
@@ -25,28 +27,30 @@
25
27
  ],
26
28
  "license": "ISC",
27
29
  "scripts": {
28
- "lint": "standard",
29
- "pretest": "npm run lint",
30
+ "eslint": "eslint",
31
+ "lint": "eslint '**/*.js'",
32
+ "lintfix": "npm run lint -- --fix",
33
+ "posttest": "npm run lint",
30
34
  "test": "tap",
31
35
  "snap": "tap",
32
36
  "preversion": "npm test",
33
37
  "postversion": "npm publish",
34
- "prepublishOnly": "git push origin --follow-tags"
38
+ "prepublishOnly": "git push origin --follow-tags",
39
+ "postlint": "npm-template-check"
35
40
  },
36
41
  "tap": {
37
42
  "check-coverage": true
38
43
  },
39
- "standard": {
40
- "ignore": [
41
- "/tap-snapshots/"
42
- ]
43
- },
44
44
  "devDependencies": {
45
- "require-inject": "^1.4.4",
46
- "standard": "^14.3.4",
47
- "tap": "^14.10.7"
45
+ "tap": "^15.0.9"
48
46
  },
49
47
  "dependencies": {
50
- "@npmcli/arborist": "^2.0.0"
48
+ "@npmcli/arborist": "^4.0.0"
49
+ },
50
+ "engines": {
51
+ "node": "^12.13.0 || ^14.15.0 || >=16"
52
+ },
53
+ "templateOSS": {
54
+ "version": "2.4.1"
51
55
  }
52
56
  }
package/CHANGELOG.md DELETED
@@ -1,6 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.0.0-pre.0
4
-
5
- - Initial pre-release.
6
-