JamieMason / syncpack

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

How are customTypes created? #201

Closed atrofimov-sc closed 4 months ago

atrofimov-sc commented 4 months ago

Description

syncpack.js

/** @type {import('syncpack').RcFile} */
const config = {
  customTypes: {
    optional: {
      path: 'optionalDependencies',
      strategy: 'versionsByName',
    },
  },
  semverGroups: [
    {
      label: 'Use caret (^) ranges for optional dependencies',
      range: '^',
      dependencyTypes: ['optional' ],
      dependencies: ['**'], 
      packages: ['**'], 
    },
  ],
};

module.exports = config;

And then I have a package.json

{
  /* snip */
  "optionalDependencies": {
    "@sentry/utils": "*",
  }
}

and I'm expecting it to complain that * doesn't match the required range of ^.

But it says everything is fine.

= Use caret (^) ranges for optional dependencies ===============================
✓ 1 valid

Suggested Solution

:shrug:

Help Needed

:shrug:

JamieMason commented 4 months ago

Hey @atrofimov-sc, please see the first example on the customTypes docs, points 2 and 3.

mctrafik commented 4 months ago

I see. For others who're finding this confusing in the documentation, the solution is to specify the dependencyTypes twice, in the root and in the semver. I.e.

/** @type {import('syncpack').RcFile} */
const config = {
  customTypes: {
    optional: {
      path: 'optionalDependencies',
      strategy: 'versionsByName',
    },
  },
  dependencyTypes: ['optional'], // <=== This was missing.
  semverGroups: [
    {
      label: 'Use caret (^) ranges for optional dependencies',
      range: '^',
      dependencyTypes: ['optional'],
      dependencies: ['**'], 
      packages: ['**'], 
    },
  ],
};

module.exports = config;
JamieMason commented 4 months ago

Thanks @mctrafik, if you have time please submit some edits to the Docs – with my being so close to the implementation maybe I'll gloss over some things, it can happen.

mctrafik commented 4 months ago

Sure: https://github.com/JamieMason/syncpack/pull/202