yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.37k stars 1.1k forks source link

[Bug?]: Yarn needlessly reformats package.json, even on CI #6282

Closed wojtekmaj closed 4 months ago

wojtekmaj commented 4 months ago

Self-service

Describe the bug

Given a package.json formatted differently than to Yarn's liking, Yarn will reformat it, even on CI, even with --immutable option passed.

To reproduce

Note https://yarnpkg.com/advanced/sherlock 404s.

Note CodeSandbox link on https://v3.yarnpkg.com/advanced/sherlock is also dead.

Environment

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M2
  Binaries:
    Node: 22.0.0 - /private/var/folders/3y/swkjq1x101b76mzjgt4pm2d80000gp/T/xfs-40ef5ce1/node
    Yarn: 4.2.1 - /private/var/folders/3y/swkjq1x101b76mzjgt4pm2d80000gp/T/xfs-40ef5ce1/yarn
    npm: 10.5.1 - /usr/local/bin/npm
    bun: 1.1.6 - ~/.bun/bin/bun

Additional context

It appears like package.json auto-formatting is undocumented and there is no way to turn it off. This causes hard to debug issues when working with Yarn & other tools, and possibly hurts the performance, too.

arcanis commented 4 months ago

Duplicate of https://github.com/yarnpkg/berry/issues/6184

wojtekmaj commented 4 months ago

Doesn't seem to be the same kind of issue to me.

{
  "name": "test-yarn",
  "packageManager": "yarn@4.1.1",
  "bin": {
    "test-yarn": "./path/to/file"
  }
}

⬇️

{
  "name": "test-yarn",
  "packageManager": "yarn@4.1.1",
  "bin": "./path/to/file"
}

vs.

{
  "name": "test-yarn",
  "packageManager": "yarn@4.1.1",
  "files": ["./path/to/file", "./another/path"]
}

⬇️

{
  "name": "test-yarn",
  "packageManager": "yarn@4.1.1",
  "files": [
    "./path/to/file",
    "./another/path"
  ]
}

are very different. The former changes the structure, while the latter is formatting only.

arcanis commented 4 months ago

Depends.

If you want to make this issue specifically about the --immutable flag taking the formatting into account, then it's not a bug.

The --immutable flag ensures that someone cloning your branch and running an install won't see spurious changes; whether those changes are semantic or syntactic doesn't matter: it'd be confusing either way ("should I commit those changes?").