JamieMason / syncpack

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

fix(local): allow missing .version if not depended on #183

Closed keyz closed 6 months ago

keyz commented 6 months ago

Description

According to the npm spec, it's fine to omit the version field in package.json:

If you don't plan to publish your package, the name and version fields are optional

Omitting the version field is common for leaf packages that won't ever be published, such as "apps" in a monorepo. IMO this change (introduced by v12) feels like a regression.

Here's a simple repro. The following package.json declares a private package ("app"):

{
  "name": "my-express-app",
  "private": true,
  "scripts": {
    "repro": "syncpack list-mismatches"
  },
  "devDependencies": {
    "syncpack": "^12.0.1"
  }
}
$ npm run repro

> repro
> syncpack list-mismatches

= Default Version Group ========================================================
✘ my-express-app PACKAGE_JSON_HAS_NO_VERSION → ??? package.json > version [MissingLocalVersion]
  package.json does not have a .version property which is exact semver
     1 ✓ already valid
     1 ! can be fixed manually using syncpack prompt

Suggested Solution

Relax the policy such that leaf packages (that no one depends on) can omit the version field

Help Needed

JamieMason commented 6 months ago

Thanks I'll check it over, it should only happen if it is depended on.

https://jamiemason.github.io/syncpack/guide/status-codes/#missinglocalversion

dbrxnds commented 6 months ago

Running into this same issue now as well.

JamieMason commented 6 months ago

I would stay on v11 for now if this is an issue – or add "version": "0.0.0" to the package.

JamieMason commented 6 months ago

Released in 12.1.0.

👋 If anyone reading this finds syncpack useful, please tell people about it.