"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "docs/content/using-npm/workspaces.md" between
npm-cli-7.16.0.tar.gz and npm-cli-7.17.0.tar.gz

About: npm is a JavaScript package manager (requires node v6 or higher).

workspaces.md  (npm-cli-7.16.0):workspaces.md  (npm-cli-7.17.0)
skipping to change at line 24 skipping to change at line 24
linked packages from the local file system. Automating the linking process linked packages from the local file system. Automating the linking process
as part of `npm install` and avoiding manually having to use `npm link` in as part of `npm install` and avoiding manually having to use `npm link` in
order to add references to packages that should be symlinked into the current order to add references to packages that should be symlinked into the current
`node_modules` folder. `node_modules` folder.
We also refer to these packages being auto-symlinked during `npm install` as a We also refer to these packages being auto-symlinked during `npm install` as a
single **workspace**, meaning it's a nested package within the current local single **workspace**, meaning it's a nested package within the current local
file system that is explicitly defined in the [`package.json`](/configuring-npm/ package-json#workspaces) file system that is explicitly defined in the [`package.json`](/configuring-npm/ package-json#workspaces)
`workspaces` configuration. `workspaces` configuration.
### Installing workspaces ### Defining workspaces
Workspaces are usually defined via the `workspaces` property of the Workspaces are usually defined via the `workspaces` property of the
[`package.json`](/configuring-npm/package-json#workspaces) file, e.g: [`package.json`](/configuring-npm/package-json#workspaces) file, e.g:
```json ```json
{ {
"name": "my-workspaces-powered-project", "name": "my-workspaces-powered-project",
"workspaces": [ "workspaces": [
"workspace-a" "workspace-a"
] ]
skipping to change at line 66 skipping to change at line 66
``` ```
. .
+-- node_modules +-- node_modules
| `-- workspace-a -> ../workspace-a | `-- workspace-a -> ../workspace-a
+-- package-lock.json +-- package-lock.json
+-- package.json +-- package.json
`-- workspace-a `-- workspace-a
`-- package.json `-- package.json
``` ```
### Getting started with workspaces
You may automate the required steps to define a new workspace using
[npm init](/commands/npm-init). For example in a project that already has a
`package.json` defined you can run:
```
npm init -w ./packages/a
```
This command will create the missing folders and a new `package.json`
file (if needed) while also making sure to properly configure the
`"workspaces"` property of your root project `package.json`.
### Adding dependencies to a workspace
It's possible to directly add/remove/update dependencies of your workspaces
using the [`workspace` config](/using-npm/config#workspace).
For example, assuming the following structure:
```
.
+-- package.json
`-- packages
+-- a
| `-- package.json
`-- b
`-- package.json
```
If you want to add a dependency named `abbrev` from the registry as a
dependency of your workspace **a**, you may use the workspace config to tell
the npm installer that package should be added as a dependency of the provided
workspace:
```
npm install abbrev -w a
```
Note: other installing commands such as `uninstall`, `ci`, etc will also
respect the provided `workspace` configuration.
### Using workspaces ### Using workspaces
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 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
by it's declared `package.json` `name`. Continuing from the example defined by it's declared `package.json` `name`. Continuing from the example defined
above, let's also create a Node.js script that will require the `workspace-a` above, let's also create a Node.js script that will require the `workspace-a`
example module, e.g: example module, e.g:
``` ```
// ./workspace-a/index.js // ./workspace-a/index.js
module.exports = 'a' module.exports = 'a'
skipping to change at line 141 skipping to change at line 184
npm run test --workspaces npm run test --workspaces
``` ```
Will run the `test` script in both `./packages/a` and `./packages/b`. Will run the `test` script in both `./packages/a` and `./packages/b`.
### See also ### See also
* [npm install](/commands/npm-install) * [npm install](/commands/npm-install)
* [npm publish](/commands/npm-publish) * [npm publish](/commands/npm-publish)
* [npm run-script](/commands/npm-run-script) * [npm run-script](/commands/npm-run-script)
* [config](/using-npm/config)
 End of changes. 3 change blocks. 
1 lines changed or deleted 44 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)