Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2021-05-13 01:21:14 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2021-05-13 22:29:11 +0300
commit370b36a36ca226840761e4214cbccaf2a1a90e3c (patch)
tree04529949473c9da0f7eb98e9b3a46a18f4562d9d /lib
parent076420c149d097056f687e44e21744b743b86e4e (diff)
feat: add fund workspaces
Add workspaces support to `npm fund` - Add lib/workspaces/arborist-cmd.js base class - Add ability to filter fund results to a specific set of workspaces - Added tests and docs Fixes: https://github.com/npm/statusboard/issues/301 PR-URL: https://github.com/npm/cli/pull/3241 Credit: @ruyadorno Close: #3241 Reviewed-by: @isaacs
Diffstat (limited to 'lib')
-rw-r--r--lib/fund.js16
-rw-r--r--lib/workspaces/arborist-cmd.js24
2 files changed, 35 insertions, 5 deletions
diff --git a/lib/fund.js b/lib/fund.js
index 25d3462f6..55d2f65dc 100644
--- a/lib/fund.js
+++ b/lib/fund.js
@@ -13,15 +13,14 @@ const {
const completion = require('./utils/completion/installed-deep.js')
const openUrl = require('./utils/open-url.js')
+const ArboristWorkspaceCmd = require('./workspaces/arborist-cmd.js')
const getPrintableName = ({ name, version }) => {
const printableVersion = version ? `@${version}` : ''
return `${name}${printableVersion}`
}
-const BaseCommand = require('./base-command.js')
-
-class Fund extends BaseCommand {
+class Fund extends ArboristWorkspaceCmd {
/* istanbul ignore next - see test/lib/load-all-commands.js */
static get description () {
return 'Retrieve funding information'
@@ -38,6 +37,7 @@ class Fund extends BaseCommand {
'json',
'browser',
'unicode',
+ 'workspace',
'which',
]
}
@@ -92,10 +92,16 @@ class Fund extends BaseCommand {
return
}
+ const fundingInfo = getFundingInfo(tree, {
+ ...this.flatOptions,
+ log: this.npm.log,
+ workspaces: this.workspaces,
+ })
+
if (this.npm.config.get('json'))
- this.npm.output(this.printJSON(getFundingInfo(tree)))
+ this.npm.output(this.printJSON(fundingInfo))
else
- this.npm.output(this.printHuman(getFundingInfo(tree)))
+ this.npm.output(this.printHuman(fundingInfo))
}
printJSON (fundingInfo) {
diff --git a/lib/workspaces/arborist-cmd.js b/lib/workspaces/arborist-cmd.js
new file mode 100644
index 000000000..f08843bd9
--- /dev/null
+++ b/lib/workspaces/arborist-cmd.js
@@ -0,0 +1,24 @@
+// This is the base for all commands whose execWorkspaces just gets
+// a list of workspace names and passes it on to new Arborist() to
+// be able to run a filtered Arborist.reify() at some point.
+
+const BaseCommand = require('../base-command.js')
+const getWorkspaces = require('../workspaces/get-workspaces.js')
+class ArboristCmd extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get params () {
+ return [
+ 'workspace',
+ ]
+ }
+
+ execWorkspaces (args, filters, cb) {
+ getWorkspaces(filters, { path: this.npm.localPrefix })
+ .then(workspaces => {
+ this.workspaces = [...workspaces.keys()]
+ this.exec(args, cb)
+ })
+ }
+}
+
+module.exports = ArboristCmd