Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync version in custom package.json properties #112

Closed
LudovicSterlin opened this issue Feb 6, 2023 · 2 comments
Closed

Sync version in custom package.json properties #112

LudovicSterlin opened this issue Feb 6, 2023 · 2 comments

Comments

@LudovicSterlin
Copy link
Contributor

LudovicSterlin commented Feb 6, 2023

Description

Sync version in custom package.json properties to match the version in (dev/peer/optional)dependencies.
The custom properties can be nested propertyies of package.json.

For example, directus has a utility that creates a package.json with a directus:extension property like the below:

{
  [...]
  "directus:extension": {
    "type": "endpoint",
    "path": "index.js",
    "source": "src/index.ts",
    "host": "9.22.2"
  },
  [...]

Where the value at directus:extension.host is actually a directus version

Suggested Solution

Add a dependenciesCustomPaths option in the form of an array of custom dependencies paths each defined by the name of the dependencies it should be associated with and its path in the package.json file.

In TypeScript this would result in something like:

dependenciesCustomPaths: { name: string; path: string }[];

This option could be given through the config file, if we take the example from above this would result in a .syncpackrc.yaml like below:

dependenciesCustomPaths:
  - name: 'directus'
    path: 'directus:extension.host'

Help Needed

A bit of help on testing other syncpack features than list/fix-mismatches which are the ones I am familiar with.

Review of the associated MR -> #113

@JamieMason
Copy link
Owner

JamieMason commented Feb 10, 2023

Thanks for this @LudovicSterlin, I've had an idea and am just leaving some notes here while I still have it.

The internals could be refactored to use this data structure internally, which can't be changed but can be added to:

const dependencyTypesByName = {
  dependencies: {
    strategy: 'versionsByName',
    path: 'dependencies',
  },
  devDependencies: {
    strategy: 'versionsByName',
    path: 'devDependencies',
  },
  overrides: {
    strategy: 'versionsByName',
    path: 'overrides',
  },
  peerDependencies: {
    strategy: 'versionsByName',
    path: 'peerDependencies',
  },
  pnpmOverrides: {
    strategy: 'versionsByName',
    path: 'pnpm.overrides',
  },
  resolutions: {
    strategy: 'versionsByName',
    path: 'resolutions',
  },
  workspace: {
    strategy: 'name~version',
    namePath: 'name',
    versionPath: 'version',
  },
};

Users could add their own in .syncpackrc which would be merged with the internal ones above to direct syncpack where to find and fix other versions.

{
  "dependencyTypesByName": {
    "packageManager": {
      "strategy": "name@version",
      "path": "packageManager"
    },
    "engines": {
      "strategy": "versionsByName",
      "path": "engines"
    },
    // this is a more granular alternative to the above
    "enginesNodeOnly": {
      "strategy": "version",
      "path": "engines.node"
    },
    "directusHost": {
      "strategy": "version",
      "path": "directus:extension.host"
    }
  }
}

Possible types of strategy:

  • versionsByName A typical list of dependencies
    {
      "dependencies": {
        "foo": "1.2.3"
      }
    }
    
  • name~version A name and version which are siblings, like local packages:
    {
      "name": "foo",
      "version": "1.2.3"
    }
    
  • name@version A name/version pair found in a single value
    {
      "packageManager": "pnpm@1.2.3"
    }
    
  • version An anonymous version found in a single value
    {
      "directus:extension": {
        "host": "9.22.2"
      },
      // OR
      "engines": {
        "node": "1.2.3"
      }
    }
    

This data could be referenced in version and semver groups etc.

JamieMason added a commit that referenced this issue Feb 14, 2023
BREAKING CHANGE:

1. The following options were replaced in syncpack@9.0.0:

  -p, --prod              include dependencies
  -d, --dev               include devDependencies
  -P, --peer              include peerDependencies
  -R, --resolutions       include resolutions (yarn)
  -o, --overrides         include overrides (npm)
  -O, --pnpmOverrides     include overrides (pnpm)
  -w, --workspace         include locally developed package versions

  Instead use the new --types option like so:

    --types dev,prod,peer

2. In .syncpackrc, the following options were replaced:

  "dev": true,
  "overrides": true,
  "peer": true,
  "pnpmOverrides": true,
  "prod": true,
  "resolutions": true,
  "workspace": true,

  Instead use the new dependencyTypes array like so:

    "dependencyTypes": ["dev", "prod", "peer"]

Closes #112
Closes #113

Co-authored-by: Ludovic Sterlin <ludovic.sterlin@hinfact.com>
JamieMason added a commit that referenced this issue Feb 14, 2023
BREAKING CHANGE:

1. The following options were replaced in syncpack@9.0.0:

  -p, --prod              include dependencies
  -d, --dev               include devDependencies
  -P, --peer              include peerDependencies
  -R, --resolutions       include resolutions (yarn)
  -o, --overrides         include overrides (npm)
  -O, --pnpmOverrides     include overrides (pnpm)
  -w, --workspace         include locally developed package versions

  Instead use the new --types option like so:

    --types dev,prod,peer

2. In .syncpackrc, the following options were replaced:

  "dev": true,
  "overrides": true,
  "peer": true,
  "pnpmOverrides": true,
  "prod": true,
  "resolutions": true,
  "workspace": true,

  Instead use the new dependencyTypes array like so:

    "dependencyTypes": ["dev", "prod", "peer"]

Closes #112
Closes #113

Co-authored-by: Ludovic Sterlin <ludovic.sterlin@hinfact.com>
@JamieMason
Copy link
Owner

This is now available as of 9.0.0, please let me know if you run into any problems – thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants