node/deps/npm/node_modules/@npmcli/map-workspaces
Myles Borins 58280ff24f
deps: upgrade npm to 7.0.8
PR-URL: https://github.com/nodejs/node/pull/35953
Reviewed-By: Ruy Adorno <ruyadorno@github.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2020-11-03 23:19:41 -05:00
..
CHANGELOG.md deps: upgrade npm to 7.0.8 2020-11-03 23:19:41 -05:00
index.js deps: update npm to 7.0.0-rc.3 2020-10-07 09:59:49 -04:00
LICENSE deps: update npm to 7.0.0-rc.3 2020-10-07 09:59:49 -04:00
package.json deps: update npm to 7.0.0-rc.3 2020-10-07 09:59:49 -04:00
README.md deps: upgrade npm to 7.0.8 2020-11-03 23:19:41 -05:00

@npmcli/map-workspaces

NPM version Build Status License

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 map-workspaces

Usage:

const mapWorkspaces = require('@npmcli/map-workspaces')
await mapWorkspaces({
  workspaces: {
    packages: [
      "a",
      "b"
    ]
  }
}, { cwd })
// ->
// Map {
//   'a': '<cwd>/a'
//   'b': '<cwd>/b'
// }

Examples:

Glob usage:

Given a folder structure such as:

├── package.json
└── apps
   ├── a
   │   └── package.json
   ├── b
   │   └── package.json
   └── c
       └── package.json
const mapWorkspaces = require('@npmcli/map-workspaces')
await mapWorkspaces({
  workspaces: [
    "apps/*"
  ]
}, { cwd })
// ->
// Map {
//   'a': '<cwd>/apps/a'
//   'b': '<cwd>/apps/b'
//   'c': '<cwd>/apps/c'
// }

API:

mapWorkspaces(pkg, opts = {}) -> Promise<Map>

  • pkg: A valid package.json Object
  • opts:
    • 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 to look for nested package.
    • ...Also support all other glob options

Returns

A Map in which keys are package names and values are the pathnames for each found workspace.

LICENSE

ISC