https://github.com/npm/map-workspaces
Retrieves a name:pathname Map for a given workspaces config
https://github.com/npm/map-workspaces
npm-cli
Last synced: about 1 year ago
JSON representation
Retrieves a name:pathname Map for a given workspaces config
- Host: GitHub
- URL: https://github.com/npm/map-workspaces
- Owner: npm
- License: other
- Created: 2020-03-06T23:57:14.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-04-28T18:53:52.000Z (about 1 year ago)
- Last Synced: 2025-05-10T03:04:41.815Z (about 1 year ago)
- Topics: npm-cli
- Language: JavaScript
- Homepage:
- Size: 415 KB
- Stars: 22
- Watchers: 3
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# @npmcli/map-workspaces
[](https://www.npmjs.com/package/@npmcli/map-workspaces)
[](https://github.com/npm/map-workspaces)
[](https://github.com/npm/map-workspaces/blob/main/LICENSE.md)
Retrieves a name:pathname Map for a given workspaces config.
Long version: Reads the `workspaces` property from a valid **workspaces configuration** object and traverses the paths and globs defined there in order to find valid nested packages and return a **Map** of all found packages where keys are package names and values are folder locations.
## Install
`npm install @npmcli/map-workspaces`
## Usage:
```js
const mapWorkspaces = require('@npmcli/map-workspaces')
await mapWorkspaces({
cwd,
pkg: {
workspaces: {
packages: [
"a",
"b"
]
}
}
})
// ->
// Map {
// 'a': '/a'
// 'b': '/b'
// }
```
## Examples:
### Glob usage:
Given a folder structure such as:
```
├── package.json
└── apps
├── a
│ └── package.json
├── b
│ └── package.json
└── c
└── package.json
```
```js
const mapWorkspaces = require('@npmcli/map-workspaces')
await mapWorkspaces({
cwd,
pkg: {
workspaces: [
"apps/*"
]
}
})
// ->
// Map {
// 'a': '/apps/a'
// 'b': '/apps/b'
// 'c': '/apps/c'
// }
```
## API:
### `mapWorkspaces(opts) -> Promise`
- `opts`:
- `pkg`: A valid `package.json` **Object**
- `cwd`: A **String** defining the base directory to use when reading globs and paths.
- `ignore`: An **Array** of paths to be ignored when using [globs](https://www.npmjs.com/package/glob) to look for nested package.
- ...[Also support all other glob options](https://www.npmjs.com/package/glob#options)
#### Returns
A **Map** in which keys are **package names** and values are the **pathnames** for each found **workspace**.
## LICENSE
[ISC](./LICENSE)