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

update sets all packages to the same version in syncpack 12.3.1 #210

Open
jckw opened this issue Apr 24, 2024 · 7 comments
Open

update sets all packages to the same version in syncpack 12.3.1 #210

jckw opened this issue Apr 24, 2024 · 7 comments

Comments

@jckw
Copy link

jckw commented Apr 24, 2024

Description

When using syncpack 12.3.1, running yarn syncpack update results in every package being given the version number of the last checked package.

e.g.

if some-package has a new version 1.2.3, and other-package has no update and the original package.json looks like:

{ 
  "dependencies": {
    "other-package": "2.3.4",
    "some-package: "1.2.1"
  }
}

then running yarn syncpack update will result in the package.json getting updated to:

{ 
  "dependencies": {
    "other-package": "1.2.3",
    "some-package: "1.2.3"
  }
}

Example screenshot here where all packages (in all package.jsons in a monorepo) are set to "0.20.17":

CleanShot from Jack Weatherilt 2024-04-24 at 09 50 27@2x

I originally thought this might be cache related, but nuking everything doesn't help.

Suggested Solution

Using syncpack 12.3.0 does not have this issue, suggesting the bug was introduced in the latest release.

Help Needed

@JamieMason
Copy link
Owner

Agh, thanks @jckw – that is not good! 😅

As you mentioned, I'd stay on 12.3.0 for now. Something in a1c7270 must have caused this.

update and prompt are the only commands without tests, so these kinds of mistakes happen.

JamieMason added a commit that referenced this issue Apr 24, 2024
@JamieMason
Copy link
Owner

I've reverted that commit in 12.3.2, I'll leave this issue open for looking at the original problem.

@yacosta738

This comment was marked as off-topic.

@JamieMason

This comment was marked as off-topic.

@yacosta738

This comment was marked as off-topic.

@RachelScodes
Copy link

RachelScodes commented May 14, 2024

we don't use pnpm at all and are seeing this issue on 12.3.2. and 12.3.0.

running prompt where multiple dependencies need to be updated is the issue.

prompt suggests the correct versions, I selected them:

Screenshot

Screenshot 2024-05-14 at 4 12 34 PM

but then this is what writes to my package.jsons:

Screenshot

Screenshot 2024-05-14 at 4 20 31 PM

if I go one by one, and filter prompt to one package at a time (npx syncpack prompt --filter "one-package-at-a-time"), it updates correctly.

this is my syncpack.rc
// @ts-check
const fs = require('fs');

const rootPackageJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));

const flattenedDependencies = {
  ...(rootPackageJson.dependencies || {}),
  ...(rootPackageJson.devDependencies || {}),
  ...(rootPackageJson.resolutions || {}),
  ...(rootPackageJson.overrides || {})
};

const rootDependencies = Object.keys(flattenedDependencies)

// formatting rules (do not affect dependency version checks)
/** @type {import("syncpack").RcFile} */
const formattingRules = {
  "formatRepository": false,
  "sortAz": [
    "contributors",
    "dependencies",
    "devDependencies",
    "keywords",
    "peerDependencies",
    "overrides",
    "scripts",
    "exports"
  ],
  "sortFirst": [
    "name",
    "version",
    "private",
    "description",
    "main",
    "module",
    "types",
    "typings",
    "exports",
    "repository",
    "license",
    "author",
    "publishConfig",
    "workspaces",
    "scripts",
    "peerDependencies",
    "dependencies",
    "devDependencies"
  ],
  "lintFormatting": true,
  "lintSemverRanges": true,
};

/** @type {import("syncpack").RcFile} */
const config = {
  "source": [
    "package.json",
    "packages/*/package.json",
    "apps/*/package.json",
    "types/package.json"
  ],
  // dependency enforcement!
  // rules go from least -> most specific.
  // docs: https://jamiemason.github.io/syncpack/
  "versionGroups": [
    // legacy/conflicting dependencies can be pinned
    // {
    //   label: '@myrepo/legacy-lib is pinned to an earlier version of the sample package',
    //   packages: ["@myrepo/legacy-lib"],
    //   dependencies: ['sample'],
    //   dependencyTypes: ['prod'],
    //   pinVersion: "1.2.1",
    // },
    {
      label: '@my-monorepo/types package should not be a dependency. check the tsconfig file instead',
      packages: ["@my-monorepo/*"],
      dependencies: ['@my-monorepo/types'],
      dependencyTypes: ['!local'],
      isBanned: true,
    },
    // {
    //   doesn't work as expected
    //   label: 'Use latest version range of local packages for peer dependencies',
    //   dependencies: ['@my-monorepo/*'],
    //   dependencyTypes: ['peer'],
    //   "policy": "sameRange"
    // },
    {
      label: 'Use exact, latest version of local packages within the monorepo',
      dependencies: ['@my-monorepo/*'],
      dependencyTypes: ['!local'],
      "policy": "sameRange"
    },
    {
      label: 'All prod dependencies use exact versions the root package.json is using',
      dependencyTypes: ['!peer'],
      dependencies: rootDependencies,
      snapTo: ['my-monorepo'],
    },
    {
      label: 'All peer dependencies use version ranges that match the root package.json is using',
      dependencyTypes: ['peer'],
      dependencies: rootDependencies,
      specifierTypes: ['^'],
      snapTo: ['my-monorepo'],
    },
  ],
  // these are evaluated after the versionGroups above
  "semverGroups": [
    {
      label: 'Use ranges for peer dependencies for published libs',
      range: '^',
      dependencyTypes: ['peer'],
      packages: ["packages/*"],
    },
    {
      label: 'Use exact version for prod and dev dependencies for published libs',
      range: '',
      packages: ["packages/*"],
      dependencyTypes: ['!peer'],
    }
  ],
  ...formattingRules
}

module.exports = config;

@JamieMason
Copy link
Owner

Thanks a lot for all this detail @RachelScodes, that matches and confirms what we've been seeing. As I mentioned, the update command is new and currently quite buggy. Every other command has lots of tests and good confidence they are working, but update and prompt do not.

In the meantime I would wait before using this command. A rewrite of syncpack is coming in the next month or so and the situation should improve then.

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

No branches or pull requests

4 participants