libnpmfund 1.0.1 → 2.0.1

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
 
package/index.js CHANGED
@@ -15,11 +15,11 @@ 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
19
20
 
20
- if (Array.isArray(funding)) {
21
+ if (Array.isArray(funding))
21
22
  return funding.every(f => !Array.isArray(f) && isValidFunding(f))
22
- }
23
23
 
24
24
  try {
25
25
  var parsed = new URL(funding.url || funding)
@@ -30,7 +30,8 @@ function isValidFunding (funding) {
30
30
  if (
31
31
  parsed.protocol !== 'https:' &&
32
32
  parsed.protocol !== 'http:'
33
- ) return false
33
+ )
34
+ return false
34
35
 
35
36
  return Boolean(parsed.host)
36
37
  }
@@ -43,11 +44,18 @@ function readTree (tree, opts) {
43
44
  const { countOnly } = opts || {}
44
45
  const _trailingDependencies = Symbol('trailingDependencies')
45
46
 
47
+ let filterSet
48
+
49
+ if (opts && opts.workspaces && opts.workspaces.length) {
50
+ const arb = new Arborist(opts)
51
+ filterSet = arb.workspaceDependencySet(tree, opts.workspaces)
52
+ }
53
+
46
54
  function tracked (name, version) {
47
55
  const key = String(name) + String(version)
48
- if (seen.has(key)) {
56
+ if (seen.has(key))
49
57
  return true
50
- }
58
+
51
59
  seen.add(key)
52
60
  }
53
61
 
@@ -81,30 +89,36 @@ function readTree (tree, opts) {
81
89
 
82
90
  function getFundingDependencies (tree) {
83
91
  const edges = tree && tree.edgesOut && tree.edgesOut.values()
84
- if (!edges) return empty()
92
+ if (!edges)
93
+ return empty()
85
94
 
86
95
  const directDepsWithFunding = Array.from(edges).map(edge => {
87
- if (!edge || !edge.to) return empty()
96
+ if (!edge || !edge.to)
97
+ return empty()
88
98
 
89
99
  const node = edge.to.target || edge.to
90
- if (!node.package) return empty()
100
+ if (!node.package)
101
+ return empty()
102
+
103
+ if (filterSet && filterSet.size > 0 && !filterSet.has(node))
104
+ return empty()
91
105
 
92
106
  const { name, funding, version } = node.package
93
107
 
94
108
  // avoids duplicated items within the funding tree
95
- if (tracked(name, version)) return empty()
109
+ if (tracked(name, version))
110
+ return empty()
96
111
 
97
112
  const fundingItem = {}
98
113
 
99
- if (version) {
114
+ if (version)
100
115
  fundingItem.version = version
101
- }
102
116
 
103
117
  attachFundingInfo(fundingItem, funding)
104
118
 
105
119
  return {
106
120
  node,
107
- fundingItem
121
+ fundingItem,
108
122
  }
109
123
  })
110
124
 
@@ -112,7 +126,8 @@ function readTree (tree, opts) {
112
126
  (res, { node, fundingItem }, i) => {
113
127
  if (!fundingItem ||
114
128
  fundingItem.length === 0 ||
115
- !node) return res
129
+ !node)
130
+ return res
116
131
 
117
132
  // recurse
118
133
  const transitiveDependencies = node.edgesOut &&
@@ -121,16 +136,17 @@ function readTree (tree, opts) {
121
136
 
122
137
  // if we're only counting items there's no need
123
138
  // to add all the data to the resulting object
124
- if (countOnly) return null
139
+ if (countOnly)
140
+ return null
125
141
 
126
142
  if (hasDependencies(transitiveDependencies)) {
127
143
  fundingItem.dependencies =
128
144
  retrieveDependencies(transitiveDependencies)
129
145
  }
130
146
 
131
- if (isValidFunding(fundingItem.funding)) {
147
+ if (isValidFunding(fundingItem.funding))
132
148
  res[node.package.name] = fundingItem
133
- } else if (hasDependencies(fundingItem.dependencies)) {
149
+ else if (hasDependencies(fundingItem.dependencies)) {
134
150
  res[_trailingDependencies] =
135
151
  Object.assign(
136
152
  empty(),
@@ -145,7 +161,7 @@ function readTree (tree, opts) {
145
161
 
146
162
  const treeDependencies = getFundingDependencies(tree)
147
163
  const result = {
148
- length: packageWithFundingCount
164
+ length: packageWithFundingCount,
149
165
  }
150
166
 
151
167
  if (!countOnly) {
@@ -154,13 +170,11 @@ function readTree (tree, opts) {
154
170
  (tree && tree.name)
155
171
  result.name = name || (tree && tree.path)
156
172
 
157
- if (tree && tree.package && tree.package.version) {
173
+ if (tree && tree.package && tree.package.version)
158
174
  result.version = tree.package.version
159
- }
160
175
 
161
- if (tree && tree.package && tree.package.funding) {
176
+ if (tree && tree.package && tree.package.funding)
162
177
  result.funding = normalizeFunding(tree.package.funding)
163
- }
164
178
 
165
179
  result.dependencies = retrieveDependencies(treeDependencies)
166
180
  }
@@ -170,8 +184,7 @@ function readTree (tree, opts) {
170
184
 
171
185
  async function read (opts) {
172
186
  const arb = new Arborist(opts)
173
- const tree = await arb.loadActual()
174
-
187
+ const tree = await arb.loadActual(opts)
175
188
  return readTree(tree, opts)
176
189
  }
177
190
 
@@ -179,5 +192,5 @@ module.exports = {
179
192
  read,
180
193
  readTree,
181
194
  normalizeFunding,
182
- isValidFunding
195
+ isValidFunding,
183
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libnpmfund",
3
- "version": "1.0.1",
3
+ "version": "2.0.1",
4
4
  "files": [
5
5
  "index.js"
6
6
  ],
@@ -25,8 +25,10 @@
25
25
  ],
26
26
  "license": "ISC",
27
27
  "scripts": {
28
- "lint": "standard",
29
- "pretest": "npm run lint",
28
+ "eslint": "eslint",
29
+ "lint": "npm run eslint -- index.js test.js",
30
+ "lintfix": "npm run lint -- --fix",
31
+ "posttest": "npm run lint",
30
32
  "test": "tap",
31
33
  "snap": "tap",
32
34
  "preversion": "npm test",
@@ -42,11 +44,17 @@
42
44
  ]
43
45
  },
44
46
  "devDependencies": {
45
- "require-inject": "^1.4.4",
46
- "standard": "^14.3.4",
47
- "tap": "^14.10.7"
47
+ "eslint": "^7.26.0",
48
+ "eslint-plugin-import": "^2.22.1",
49
+ "eslint-plugin-node": "^11.1.0",
50
+ "eslint-plugin-promise": "^5.1.0",
51
+ "eslint-plugin-standard": "^5.0.0",
52
+ "tap": "^15.0.9"
48
53
  },
49
54
  "dependencies": {
50
- "@npmcli/arborist": "^0.0.33 || ^1.x"
55
+ "@npmcli/arborist": "^4.0.0"
56
+ },
57
+ "engines": {
58
+ "node": "^12.13.0 || ^14.15.0 || >=16"
51
59
  }
52
60
  }
package/CHANGELOG.md DELETED
@@ -1,6 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.0.0-pre.0
4
-
5
- - Initial pre-release.
6
-