Skip to content

Commit 0d1a9d7

Browse files
committed
Add workspaces support to reify/rebuild commands
This adds `--workspace` support to: - audit (including audit fix) - ci - dedupe - find-dupes - install - install-ci-test - install-test - prune - rebuild - uninstall - update Also addresses missing error handling case, identified by @timoxley. #3227 (comment) PR-URL: #3227 Credit: @isaacs Close: #3227 Reviewed-by: @ruyadorno
1 parent 41099d3 commit 0d1a9d7

23 files changed

+375
-26
lines changed

docs/content/commands/npm-audit.md

+32
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,38 @@ it will be included.
271271
If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment
272272
variable will be set to `'production'` for all lifecycle scripts.
273273

274+
#### `workspace`
275+
276+
* Default:
277+
* Type: String (can be set multiple times)
278+
279+
Enable running a command in the context of the configured workspaces of the
280+
current project while filtering by running only the workspaces defined by
281+
this configuration option.
282+
283+
Valid values for the `workspace` config are either:
284+
285+
* Workspace names
286+
* Path to a workspace directory
287+
* Path to a parent workspace directory (will result to selecting all of the
288+
nested workspaces)
289+
290+
When set for the `npm init` command, this may be set to the folder of a
291+
workspace which does not yet exist, to create the folder and set it up as a
292+
brand new workspace within the project.
293+
294+
This value is not exported to the environment for child processes.
295+
296+
#### `workspaces`
297+
298+
* Default: false
299+
* Type: Boolean
300+
301+
Enable running a command in the context of **all** the configured
302+
workspaces.
303+
304+
This value is not exported to the environment for child processes.
305+
274306
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
275307

276308
### See Also

docs/content/commands/npm-dedupe.md

+32
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,38 @@ commands that modify your local installation, eg, `install`, `update`,
202202
Note: This is NOT honored by other network related commands, eg `dist-tags`,
203203
`owner`, etc.
204204
205+
#### `workspace`
206+
207+
* Default:
208+
* Type: String (can be set multiple times)
209+
210+
Enable running a command in the context of the configured workspaces of the
211+
current project while filtering by running only the workspaces defined by
212+
this configuration option.
213+
214+
Valid values for the `workspace` config are either:
215+
216+
* Workspace names
217+
* Path to a workspace directory
218+
* Path to a parent workspace directory (will result to selecting all of the
219+
nested workspaces)
220+
221+
When set for the `npm init` command, this may be set to the folder of a
222+
workspace which does not yet exist, to create the folder and set it up as a
223+
brand new workspace within the project.
224+
225+
This value is not exported to the environment for child processes.
226+
227+
#### `workspaces`
228+
229+
* Default: false
230+
* Type: Boolean
231+
232+
Enable running a command in the context of **all** the configured
233+
workspaces.
234+
235+
This value is not exported to the environment for child processes.
236+
205237
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
206238
207239
### See Also

docs/content/commands/npm-find-dupes.md

+32
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,38 @@ When "true" displays the message at the end of each `npm install`
132132
acknowledging the number of dependencies looking for funding. See [`npm
133133
fund`](/commands/npm-fund) for details.
134134

135+
#### `workspace`
136+
137+
* Default:
138+
* Type: String (can be set multiple times)
139+
140+
Enable running a command in the context of the configured workspaces of the
141+
current project while filtering by running only the workspaces defined by
142+
this configuration option.
143+
144+
Valid values for the `workspace` config are either:
145+
146+
* Workspace names
147+
* Path to a workspace directory
148+
* Path to a parent workspace directory (will result to selecting all of the
149+
nested workspaces)
150+
151+
When set for the `npm init` command, this may be set to the folder of a
152+
workspace which does not yet exist, to create the folder and set it up as a
153+
brand new workspace within the project.
154+
155+
This value is not exported to the environment for child processes.
156+
157+
#### `workspaces`
158+
159+
* Default: false
160+
* Type: Boolean
161+
162+
Enable running a command in the context of **all** the configured
163+
workspaces.
164+
165+
This value is not exported to the environment for child processes.
166+
135167
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
136168

137169
### See Also

docs/content/commands/npm-install-test.md

+32
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,38 @@ commands that modify your local installation, eg, `install`, `update`,
187187
Note: This is NOT honored by other network related commands, eg `dist-tags`,
188188
`owner`, etc.
189189

190+
#### `workspace`
191+
192+
* Default:
193+
* Type: String (can be set multiple times)
194+
195+
Enable running a command in the context of the configured workspaces of the
196+
current project while filtering by running only the workspaces defined by
197+
this configuration option.
198+
199+
Valid values for the `workspace` config are either:
200+
201+
* Workspace names
202+
* Path to a workspace directory
203+
* Path to a parent workspace directory (will result to selecting all of the
204+
nested workspaces)
205+
206+
When set for the `npm init` command, this may be set to the folder of a
207+
workspace which does not yet exist, to create the folder and set it up as a
208+
brand new workspace within the project.
209+
210+
This value is not exported to the environment for child processes.
211+
212+
#### `workspaces`
213+
214+
* Default: false
215+
* Type: Boolean
216+
217+
Enable running a command in the context of **all** the configured
218+
workspaces.
219+
220+
This value is not exported to the environment for child processes.
221+
190222
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
191223

192224
### See Also

docs/content/commands/npm-install.md

+32
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,38 @@ commands that modify your local installation, eg, `install`, `update`,
571571
Note: This is NOT honored by other network related commands, eg `dist-tags`,
572572
`owner`, etc.
573573
574+
#### `workspace`
575+
576+
* Default:
577+
* Type: String (can be set multiple times)
578+
579+
Enable running a command in the context of the configured workspaces of the
580+
current project while filtering by running only the workspaces defined by
581+
this configuration option.
582+
583+
Valid values for the `workspace` config are either:
584+
585+
* Workspace names
586+
* Path to a workspace directory
587+
* Path to a parent workspace directory (will result to selecting all of the
588+
nested workspaces)
589+
590+
When set for the `npm init` command, this may be set to the folder of a
591+
workspace which does not yet exist, to create the folder and set it up as a
592+
brand new workspace within the project.
593+
594+
This value is not exported to the environment for child processes.
595+
596+
#### `workspaces`
597+
598+
* Default: false
599+
* Type: Boolean
600+
601+
Enable running a command in the context of **all** the configured
602+
workspaces.
603+
604+
This value is not exported to the environment for child processes.
605+
574606
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
575607
576608
### Algorithm

docs/content/commands/npm-prune.md

+32
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,38 @@ Whether or not to output JSON data, rather than the normal output.
7777

7878
Not supported by all npm commands.
7979

80+
#### `workspace`
81+
82+
* Default:
83+
* Type: String (can be set multiple times)
84+
85+
Enable running a command in the context of the configured workspaces of the
86+
current project while filtering by running only the workspaces defined by
87+
this configuration option.
88+
89+
Valid values for the `workspace` config are either:
90+
91+
* Workspace names
92+
* Path to a workspace directory
93+
* Path to a parent workspace directory (will result to selecting all of the
94+
nested workspaces)
95+
96+
When set for the `npm init` command, this may be set to the folder of a
97+
workspace which does not yet exist, to create the folder and set it up as a
98+
brand new workspace within the project.
99+
100+
This value is not exported to the environment for child processes.
101+
102+
#### `workspaces`
103+
104+
* Default: false
105+
* Type: Boolean
106+
107+
Enable running a command in the context of **all** the configured
108+
workspaces.
109+
110+
This value is not exported to the environment for child processes.
111+
80112
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
81113

82114
### See Also

docs/content/commands/npm-rebuild.md

+32
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,38 @@ Note that commands explicitly intended to run a particular script, such as
6666
will still run their intended script if `ignore-scripts` is set, but they
6767
will *not* run any pre- or post-scripts.
6868

69+
#### `workspace`
70+
71+
* Default:
72+
* Type: String (can be set multiple times)
73+
74+
Enable running a command in the context of the configured workspaces of the
75+
current project while filtering by running only the workspaces defined by
76+
this configuration option.
77+
78+
Valid values for the `workspace` config are either:
79+
80+
* Workspace names
81+
* Path to a workspace directory
82+
* Path to a parent workspace directory (will result to selecting all of the
83+
nested workspaces)
84+
85+
When set for the `npm init` command, this may be set to the folder of a
86+
workspace which does not yet exist, to create the folder and set it up as a
87+
brand new workspace within the project.
88+
89+
This value is not exported to the environment for child processes.
90+
91+
#### `workspaces`
92+
93+
* Default: false
94+
* Type: Boolean
95+
96+
Enable running a command in the context of **all** the configured
97+
workspaces.
98+
99+
This value is not exported to the environment for child processes.
100+
69101
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
70102

71103
### See Also

docs/content/commands/npm-uninstall.md

+32
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,38 @@ Save installed packages to a package.json file as dependencies.
6868
When used with the `npm rm` command, removes the dependency from
6969
package.json.
7070

71+
#### `workspace`
72+
73+
* Default:
74+
* Type: String (can be set multiple times)
75+
76+
Enable running a command in the context of the configured workspaces of the
77+
current project while filtering by running only the workspaces defined by
78+
this configuration option.
79+
80+
Valid values for the `workspace` config are either:
81+
82+
* Workspace names
83+
* Path to a workspace directory
84+
* Path to a parent workspace directory (will result to selecting all of the
85+
nested workspaces)
86+
87+
When set for the `npm init` command, this may be set to the folder of a
88+
workspace which does not yet exist, to create the folder and set it up as a
89+
brand new workspace within the project.
90+
91+
This value is not exported to the environment for child processes.
92+
93+
#### `workspaces`
94+
95+
* Default: false
96+
* Type: Boolean
97+
98+
Enable running a command in the context of **all** the configured
99+
workspaces.
100+
101+
This value is not exported to the environment for child processes.
102+
71103
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
72104

73105
### See Also

docs/content/commands/npm-update.md

+32
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,38 @@ commands that modify your local installation, eg, `install`, `update`,
258258
Note: This is NOT honored by other network related commands, eg `dist-tags`,
259259
`owner`, etc.
260260

261+
#### `workspace`
262+
263+
* Default:
264+
* Type: String (can be set multiple times)
265+
266+
Enable running a command in the context of the configured workspaces of the
267+
current project while filtering by running only the workspaces defined by
268+
this configuration option.
269+
270+
Valid values for the `workspace` config are either:
271+
272+
* Workspace names
273+
* Path to a workspace directory
274+
* Path to a parent workspace directory (will result to selecting all of the
275+
nested workspaces)
276+
277+
When set for the `npm init` command, this may be set to the folder of a
278+
workspace which does not yet exist, to create the folder and set it up as a
279+
brand new workspace within the project.
280+
281+
This value is not exported to the environment for child processes.
282+
283+
#### `workspaces`
284+
285+
* Default: false
286+
* Type: Boolean
287+
288+
Enable running a command in the context of **all** the configured
289+
workspaces.
290+
291+
This value is not exported to the environment for child processes.
292+
261293
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
262294

263295
### See Also

lib/audit.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const Arborist = require('@npmcli/arborist')
22
const auditReport = require('npm-audit-report')
33
const reifyFinish = require('./utils/reify-finish.js')
44
const auditError = require('./utils/audit-error.js')
5-
const BaseCommand = require('./base-command.js')
5+
const ArboristWorkspaceCmd = require('./workspaces/arborist-cmd.js')
66

7-
class Audit extends BaseCommand {
7+
class Audit extends ArboristWorkspaceCmd {
88
/* istanbul ignore next - see test/lib/load-all-commands.js */
99
static get description () {
1010
return 'Run a security audit'
@@ -24,6 +24,7 @@ class Audit extends BaseCommand {
2424
'json',
2525
'package-lock-only',
2626
'omit',
27+
...super.params,
2728
]
2829
}
2930

@@ -57,7 +58,9 @@ class Audit extends BaseCommand {
5758
audit: true,
5859
path: this.npm.prefix,
5960
reporter,
61+
workspaces: this.workspaces,
6062
}
63+
6164
const arb = new Arborist(opts)
6265
const fix = args[0] === 'fix'
6366
await arb.audit({ fix })

lib/base-command.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class BaseCommand {
66
constructor (npm) {
77
this.wrapWidth = 80
88
this.npm = npm
9+
this.workspaces = null
910
}
1011

1112
get name () {

0 commit comments

Comments
 (0)