Code Monkey home page Code Monkey logo

map-workspaces's Introduction

@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

map-workspaces's People

Contributors

commanderroot avatar dependabot[bot] avatar github-actions[bot] avatar joeleinbinder avatar louis-bompart avatar lukekarrys avatar paradoxinfinite avatar ruyadorno avatar wraithgar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

map-workspaces's Issues

globs that share files cause error `must not have multiple workspaces with the same name`

With a package json like this

"workspaces": {
        "packages": [
            "packages/**",
            "packages/folder/**"
        ]
    },

Will get error

command exited with an error { Error: must not have multiple workspaces with the same name
    at getError (/Users/morse/Documents/GitHub/typescript-monorepo-toolkit/node_modules/@npmcli/map-workspaces/index.js:72:24)
    at Object.mapWorkspaces [as default] (/Users/morse/Documents/GitHub/typescript-monorepo-toolkit/node_modules/@npmcli/map-workspaces/index.js:130:17) code: 'EDUPLICATEWORKSPACE' }˙

[BUG] TypeError: workspaces config expects an Array (not compatible with nohoist syntax)

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Cf

TypeError: workspaces config expects an Array
    at getError (/var/lang/lib/node_modules/npm/node_modules/@npmcli/map-workspaces/lib/index.js:66:24)
    at getPatterns (/var/lang/lib/node_modules/npm/node_modules/@npmcli/map-workspaces/lib/index.js:36:11)
    at mapWorkspaces (/var/lang/lib/node_modules/npm/node_modules/@npmcli/map-workspaces/lib/index.js:82:20)
    at Config.loadLocalPrefix (/var/lang/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:603:34)
    at async Config.loadProjectConfig (/var/lang/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:541:5)
    at async Config.load (/var/lang/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:272:5)
    at async Npm.[_load] (/var/lang/lib/node_modules/npm/lib/npm.js:243:5)
    at async /var/lang/lib/node_modules/npm/lib/npm.js:178:9
    at async module.exports (/var/lang/lib/node_modules/npm/lib/cli.js:59:5)

Expected Behavior

  • Don't throw an error when workspaces isn't an array.
  • When it's an objects, parse well "workspaces" entry in packages.json

Steps To Reproduce

No response

Environment

No response

[DOCS] Documentation is wrong/out of date

Description

The README says to use mapWorkspaces like this:

await mapWorkspaces({
  workspaces: {
    packages: [
      "a",
      "b"
    ]
  }
}, { cwd })

However this fails and reading the code suggests that mapWorkspaces expects a single object with a pkg property with the package information.

Globbing my whole project folder is very slow

My project has a lot of files inside a .gitignore. Specifically entire checkouts of Firefox and WebKit. This package is globbing my entire project directory for node_modules folders, which takes upwards of 30 seconds for every npm operation.

Feature: update the `CHANGELOG.md`

Thank you for making this lovely package public ❤️

Do you mind keeping the changelog file up to date?

A major version was published recently and it's not clear what are the breaking changes:
v1.0.4...v2.0.0

Also, can you confirm the breaking change was dropping Node.js 10?

Thank you 🙏

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.