globlerna

using glob with lerna --scope filtering by package name or directory name


When using lerna, I'm having trouble creating a glob pattern to find multiple packages with a common naming convention. Am I supposed to be searching against the directory path or the name field in the package.json?

Directory Structure

packages/
    prefix-module-identifier1
    prefix-module-identifier2
    prefix-module-identifier3
    prefix-platform-identifier1
    prefix-platform-identifier2

Package Naming convention

@nameSpaceScope/prefix-module-identifier1
@nameSpaceScope/prefix-module-identifier2
@nameSpaceScope/prefix-module-identifier3
@nameSpaceScope/prefix-platform-identifier1
@nameSpaceScope/prefix-platform-identifier2

I'd like to run a command for just the module packages or just the platform packages. In these examples I'm looking for just the module packages I've tried globs for:

--scope *module*
--scope **/*module*
--scope packages/*module*
--scope @nameSpaceScope/*module*
--scope @nameSpaceScope/+(*module*)

The closest glob that gets anything is --scope packages/*module*, but it only finds the first module.

My lerna config

{
  "packages": [
      "packages/*"
  ],
  "version": "0.0.1"
}

Solution

  • hexagon,

    I just checked in my own lerna monorepo and found that using the --scope flag in a lerna command definitely refers to names as defined in package.json.

    See here for details on how the --scope flag works in lerna.

    So, looking at how you have named packages above, to get just your module packages, the following glob patterns that you have tried should work...

    --scope @nameSpaceScope/*module*

    --scope @nameSpaceScope/+(*module*)

    I even went so far as to try them out using https://globster.xyz/

    enter image description here enter image description here