syncpack icon indicating copy to clipboard operation
syncpack copied to clipboard

feat(config): disallow redefining dependencies already defined in the root

Open midzdotdev opened this issue 1 year ago • 2 comments

Description

I'd really like the ability to prevent having a dependency in a monorepo package that's already defined at the root.

Say I have jest defined in ./package.json, syncpack could be configured to disallow ./apps/my-app/package.json having that dependency too.

Suggested Solution

Honestly I have no idea how you'd want to configure this. I'm happy with something as simple as the above, but I'm sure others would love to customise it further for their own needs.

Help Needed

The ability to produce a sweet ass config interface.

midzdotdev avatar Jan 20 '24 18:01 midzdotdev

I missed this one @midzdotdev, slowwww reply here. It's a good idea, I'm not sure yet on what the config should be but I'll have a think.

EDIT: Maybe for something like this it's some kind of general lint rule rather than being a form of version group or something, not sure.

JamieMason avatar Feb 10 '25 11:02 JamieMason

It's very bespoke but one thing you could do today is this in a JS config file:

const rootPackage = require("./package.json");

module.exports = {
  versionGroups: [
    {
      // 1. whenever these dependencies from the root package are found
      dependencies: Object.keys({
        ...rootPackage.dependencies,
        ...rootPackage.devDependencies,
        // add more if you need to
      }),
      // 2. ...but they are NOT in the root package
      packages: [`!${rootPackage.name}`],
      // 3. ban them
      isBanned: true,
    },
  ],
};

JamieMason avatar Feb 10 '25 11:02 JamieMason