node-link-parent-bin icon indicating copy to clipboard operation
node-link-parent-bin copied to clipboard

Get list of child packages from lerna.json

Open billba opened this issue 5 years ago • 2 comments

Our project uses Lerna in what appears to be a nonstandard but accepted way. Instead of putting all the child packages under a root/packages folder, they are all directly under root, e.g. root/client, root/server. Lerna handles this by listing them in lerna.json in a packages array, e.g.:

{
  ...
  "packages": [
    "./client",
    "./server"
  ]
  ...
}

It appears that, in a more traditional Lerna setup, the child packages are listed there as follows:

{
  ...
  "packages": ["packages/*"]
  ...
}

I propose that, instead of reading the command-line option --child-directory-root (with default packages), the list of packages instead be read from the lerna.json.

For backwards compatibility you could still allow the option as an override, however I would recommend instead bumping up the major version number to keep the code simple, since this approach seems to be more in line with how Lerna is intended to be used, and therefore should obviate the need for anyone to use --child-directory-root.

If you approve I'd be happy to submit a PR.

billba avatar Jun 01 '20 14:06 billba

It would be great to see this - after seeing lerna mentioned in the README, it was a bit of a gotcha for it to not just work out of the box.

I'd recommend that support is kept for non-lerna Yarn workspaces, too. Perhaps the order of precedence should be:

  • "workspaces" from package.json (first since lerna and yarn can coexist)
  • "packages" from lerna.json
  • literal default "packages"

With the existing command line option as an override?

macksal avatar Dec 09 '21 06:12 macksal

Sounds good. I'd be happy to accept a PR for this.

I personally use packages/* always for my projects, which is why I didn't see this as a problem.

Let's use the fallback mechanism @macksal mentioned. Resources:

  • package.json workspaces: https://docs.npmjs.com/cli/v7/using-npm/workspaces
  • lerna.json packages; https://github.com/lerna/lerna#lernajson

nicojs avatar Dec 09 '21 09:12 nicojs