JamieMason / syncpack

Consistent dependency versions in large JavaScript Monorepos.
https://jamiemason.github.io/syncpack/
MIT License
1.34k stars 44 forks source link

feat(core): add a way to add additional package.json files to the sources read from the monorepo #205

Open dominics opened 3 months ago

dominics commented 3 months ago

Description

In the monorepo I work in, there are a large number of package.json files configured using (yarn, soon pnpm) workspaces, and then some few additional package.json files that don't participate in the monorepo for one reason or another. It'd be nice to have a way to include these additional package.json files in the source configuration, without losing the ability to include automatically discovered package.json files from the workspaces configuration.

In other words, where the documentation says:

package.json files are resolved in this order of precedence:

  1. If --source glob patterns are provided, use those.
  2. If using Yarn Workspaces, read workspaces from ./package.json.
  3. If using Lerna, read packages from ./lerna.json.
  4. If using Pnpm, read packages from ./pnpm-workspace.yaml.
  5. Default to 'package.json' and 'packages/*/package.json'.

I'd like a way to use 2-4, while adding some additional package.json files to the sources.

Suggested Solution

Maybe there could be some pre-defined values that can be provided when using globs (1 in the above list), to also merge in the values from 2, 3, 4? MIght cause conflicts with real directories though... I don't know exactly what configuration format to use here

Thanks for the amazing tool!

JamieMason commented 3 months ago

Thanks @dominics.

As you rightly said, it is currently either:

  1. Define no sources and syncpack will discover them from known package manager configs (first one wins).
  2. Define sources and syncpack will only use those.

This issue can track adding some way to combine both.

In the meantime you'd need to manually duplicate the sources.

In some cases you could import './package.json' into a JS syncpack config file to reference the workspace config from there, but for pnpm projects that wouldn't be a straightforward option since its config is yaml.