CLI documentation update from CI

CI User committed Jun 11, 2021 at 02:32 UTC 16d0fe31cb80d615966677e07823f40838c1ca63
3 files changed +78 -2
cli/v7
+1 -1
@@ -1 +1 @@
1 -Subproject commit 33a31a97eb3f14d8a4b6b681e51d44056fd9a3c1
1 +Subproject commit 3f202cd777897d2213820fb00a4e85f440f69701
content/cli/v7/commands/npm-diff.md
+32
@@ -252,6 +252,38 @@ command, if no explicit tag is given.
252 When used by the `npm diff` command, this is the tag used to fetch the
253 tarball that will be compared with the local files by default.
254
255 +#### `workspace`
256 +
257 +* Default:
258 +* Type: String (can be set multiple times)
259 +
260 +Enable running a command in the context of the configured workspaces of the
261 +current project while filtering by running only the workspaces defined by
262 +this configuration option.
263 +
264 +Valid values for the `workspace` config are either:
265 +
266 +* Workspace names
267 +* Path to a workspace directory
268 +* Path to a parent workspace directory (will result to selecting all of the
269 + nested workspaces)
270 +
271 +When set for the `npm init` command, this may be set to the folder of a
272 +workspace which does not yet exist, to create the folder and set it up as a
273 +brand new workspace within the project.
274 +
275 +This value is not exported to the environment for child processes.
276 +
277 +#### `workspaces`
278 +
279 +* Default: false
280 +* Type: Boolean
281 +
282 +Enable running a command in the context of **all** the configured
283 +workspaces.
284 +
285 +This value is not exported to the environment for child processes.
286 +
287 <!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
288 ## See Also
289
content/cli/v7/using-npm/workspaces.md
+45 -1
@@ -29,7 +29,7 @@ single **workspace**, meaning it's a nested package within the current local
29 file system that is explicitly defined in the [`package.json`](/cli/v7/configuring-npm/package-json#workspaces)
30 `workspaces` configuration.
31
32 -### Installing workspaces
32 +### Defining workspaces
33
34 Workspaces are usually defined via the `workspaces` property of the
35 [`package.json`](/cli/v7/configuring-npm/package-json#workspaces) file, e.g:
@@ -71,6 +71,49 @@ structure of files and folders:
71 `-- package.json
72 ```
73
74 +### Getting started with workspaces
75 +
76 +You may automate the required steps to define a new workspace using
77 +[npm init](/cli/v7/commands/npm-init). For example in a project that already has a
78 +`package.json` defined you can run:
79 +
80 +```
81 +npm init -w ./packages/a
82 +```
83 +
84 +This command will create the missing folders and a new `package.json`
85 +file (if needed) while also making sure to properly configure the
86 +`"workspaces"` property of your root project `package.json`.
87 +
88 +### Adding dependencies to a workspace
89 +
90 +It's possible to directly add/remove/update dependencies of your workspaces
91 +using the [`workspace` config](/cli/v7/using-npm/config#workspace).
92 +
93 +For example, assuming the following structure:
94 +
95 +```
96 +.
97 ++-- package.json
98 +`-- packages
99 + +-- a
100 + | `-- package.json
101 + `-- b
102 + `-- package.json
103 +```
104 +
105 +If you want to add a dependency named `abbrev` from the registry as a
106 +dependency of your workspace **a**, you may use the workspace config to tell
107 +the npm installer that package should be added as a dependency of the provided
108 +workspace:
109 +
110 +```
111 +npm install abbrev -w a
112 +```
113 +
114 +Note: other installing commands such as `uninstall`, `ci`, etc will also
115 +respect the provided `workspace` configuration.
116 +
117 ### Using workspaces
118
119 Given the [specifities of how Node.js handles module resolution](https://nodejs.org/dist/latest-v14.x/docs/api/modules.html#modules_all_together) it's possible to consume any defined workspace
@@ -146,4 +189,5 @@ Will run the `test` script in both `./packages/a` and `./packages/b`.
189 * [npm install](/cli/v7/commands/npm-install)
190 * [npm publish](/cli/v7/commands/npm-publish)
191 * [npm run-script](/cli/v7/commands/npm-run-script)
192 +* [config](/cli/v7/using-npm/config)
193