Skip to content

Retrieves a name:pathname Map for a given workspaces config

License

Notifications You must be signed in to change notification settings

npm/map-workspaces

Folders and files

NameName
Last commit message
Last commit date

Latest commit

743a128 · Nov 20, 2024
Sep 25, 2024
Nov 20, 2024
Nov 20, 2024
Nov 20, 2024
Sep 25, 2024
Dec 4, 2023
Sep 25, 2024
Mar 28, 2022
Nov 20, 2024
Nov 20, 2024
Jun 29, 2022
May 31, 2023
Oct 13, 2021
Mar 20, 2024
Sep 25, 2024
Nov 20, 2024
May 3, 2024

Repository files navigation

@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 @npmcli/map-workspaces

Usage:

const mapWorkspaces = require('@npmcli/map-workspaces')
await mapWorkspaces({
  cwd,
  pkg: {
    workspaces: {
      packages: [
        "a",
        "b"
      ]
    }
  }
})
// ->
// 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({
  cwd,
  pkg: {
    workspaces: [
      "apps/*"
    ]
  }
})
// ->
// Map {
//   'a': '<cwd>/apps/a'
//   'b': '<cwd>/apps/b'
//   'c': '<cwd>/apps/c'
// }

API:

mapWorkspaces(opts) -> Promise<Map>

  • 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 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