1. @npmcli/map-workspaces
Retrieves a name:pathname Map for a given workspaces config
@npmcli/map-workspaces
Package: @npmcli/map-workspaces
Created by: npm
Last modified: Wed, 10 Apr 2024 18:20:03 GMT
Version: 3.0.6
License: ISC
Downloads: 10,726,736
Repository: https://github.com/npm/map-workspaces

Install

npm install @npmcli/map-workspaces
yarn add @npmcli/map-workspaces

@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

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin