Socket
Socket
Sign inDemoInstall

@npmcli/map-workspaces

Package Overview
Dependencies
25
Maintainers
5
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @npmcli/map-workspaces

Retrieves a name:pathname Map for a given workspaces config


Version published
Weekly downloads
2.1M
decreased by-17.72%
Maintainers
5
Install size
2.98 MB
Created
Weekly downloads
 

Package description

What is @npmcli/map-workspaces?

The @npmcli/map-workspaces package is designed to assist with managing and interacting with npm workspaces. It provides functionality to map and iterate over workspaces in a project, allowing for operations such as executing scripts or installing dependencies in each workspace. This can be particularly useful in monorepo setups where multiple packages are managed within a single repository.

What are @npmcli/map-workspaces's main functionalities?

Mapping Workspaces

This feature allows you to map all the workspaces defined in your project. The code sample demonstrates how to use @npmcli/map-workspaces to retrieve a list of workspaces based on the configuration in your package.json. This is useful for scripts that need to perform actions on each workspace.

const mapWorkspaces = require('@npmcli/map-workspaces');
const { workspaces } = await mapWorkspaces({
  cwd: process.cwd(),
  pkg: {
    workspaces: [
      'packages/*'
    ]
  }
});
console.log(workspaces);

Other packages similar to @npmcli/map-workspaces

Changelog

Source

3.0.6 (2024-04-10)

Bug Fixes

  • e2a803b #145 allow for workspace patterns to start with ./ (#145) (@wraithgar)

Readme

Source

@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

Keywords

FAQs

Last updated on 10 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc