M1-version-mismatch.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ISSUE: Version mismatch between root package and CLI sub-package
  2. SEVERITY: Minor
  3. FILE(S): package.json (root), packages/cli/package.json, packages/cli/src/lib/version.ts
  4. CURRENT STATE:
  5. Root package.json (line 3):
  6. "version": "0.7.1"
  7. packages/cli/package.json (line 3):
  8. "version": "1.0.0"
  9. packages/cli/src/lib/version.ts (lines 1-6):
  10. import pkgJson from '../../package.json' with { type: 'json' }
  11. /** Returns the CLI version from package.json. Synchronous — no I/O. */
  12. export function readCliVersion(): string {
  13. return pkgJson.version ?? '0.0.0'
  14. }
  15. `readCliVersion()` reads from `packages/cli/package.json` (the relative import
  16. `../../package.json` from `packages/cli/src/lib/` resolves to
  17. `packages/cli/package.json`). So `readCliVersion()` returns `"1.0.0"`.
  18. doctor.ts `checkOacVersion()` (line 55) calls:
  19. const latest = await fetchLatestNpmVersion('@nextsystems/oac');
  20. This fetches the latest version of `@nextsystems/oac` (the root package, version
  21. `0.7.1`). It then compares `current` (from `readCliVersion()` = `"1.0.0"`) with
  22. `latest` (from npm registry, which would be `"0.7.1"` or whatever was last
  23. published).
  24. Result: `semver.lt("1.0.0", "0.7.1")` = false, so doctor always reports
  25. "OAC version: 1.0.0 (latest)" even when the root package is outdated. The
  26. version check is broken.
  27. ROOT CAUSE:
  28. The two packages have diverged in version numbers. The CLI sub-package was
  29. bumped to 1.0.0 independently of the root package. There is no synchronization
  30. mechanism.
  31. FIX:
  32. Decision: The ROOT package.json is the canonical version source. It is the
  33. package users install (`@nextsystems/oac`). The CLI sub-package version should
  34. always match the root.
  35. --- Option A (recommended): Single source of truth via root package.json ---
  36. 1. Synchronize versions: set `packages/cli/package.json` version to match root:
  37. BEFORE (packages/cli/package.json line 3):
  38. "version": "1.0.0"
  39. AFTER:
  40. "version": "0.7.1"
  41. 2. Update `readCliVersion()` to read from the ROOT package.json instead of the
  42. sub-package's package.json:
  43. BEFORE (packages/cli/src/lib/version.ts):
  44. import pkgJson from '../../package.json' with { type: 'json' }
  45. export function readCliVersion(): string {
  46. return pkgJson.version ?? '0.0.0'
  47. }
  48. AFTER:
  49. import pkgJson from '../../../../package.json' with { type: 'json' }
  50. /** Returns the CLI version from the root @nextsystems/oac package.json. */
  51. export function readCliVersion(): string {
  52. return pkgJson.version ?? '0.0.0'
  53. }
  54. The path `../../../../package.json` from `packages/cli/src/lib/` resolves to
  55. the repo root `package.json`. Verify: packages/cli/src/lib/ → ../../.. = packages/cli/
  56. → ../../.. = repo root. Count: src/lib → src → packages/cli → packages → root.
  57. That is 4 levels up: `../../../../package.json`. ✓
  58. 3. Add a version sync script to root package.json scripts to keep them in sync
  59. during version bumps:
  60. BEFORE (root package.json scripts, version bump scripts lines 75-80):
  61. "version:bump:patch": "npm version patch --no-git-tag-version && node -p \"require('./package.json').version\" > VERSION",
  62. "version:bump:minor": "npm version minor --no-git-tag-version && node -p \"require('./package.json').version\" > VERSION",
  63. "version:bump:major": "npm version major --no-git-tag-version && node -p \"require('./package.json').version\" > VERSION",
  64. AFTER — add a sync step after each bump:
  65. "version:bump:patch": "npm version patch --no-git-tag-version && node scripts/sync-version.js && node -p \"require('./package.json').version\" > VERSION",
  66. "version:bump:minor": "npm version minor --no-git-tag-version && node scripts/sync-version.js && node -p \"require('./package.json').version\" > VERSION",
  67. "version:bump:major": "npm version major --no-git-tag-version && node scripts/sync-version.js && node -p \"require('./package.json').version\" > VERSION",
  68. Where `scripts/sync-version.js` is a small Node.js script:
  69. const fs = require('fs');
  70. const root = require('./package.json');
  71. const cliPkg = require('./packages/cli/package.json');
  72. cliPkg.version = root.version;
  73. fs.writeFileSync('./packages/cli/package.json', JSON.stringify(cliPkg, null, 2) + '\n');
  74. console.log(`Synced packages/cli version to ${root.version}`);
  75. --- Option B (alternative): Keep sub-package version independent ---
  76. If the sub-package intentionally has a different version lifecycle, update
  77. `readCliVersion()` to read from the root package.json (step 2 above) but leave
  78. the sub-package version as-is. The doctor check will then correctly compare
  79. the root package version against npm.
  80. VALIDATION:
  81. 1. Run: oac --version
  82. Should print "0.7.1" (matching root package.json)
  83. 2. Run: oac doctor
  84. The "OAC version" check should compare "0.7.1" against npm registry
  85. 3. Run: node -e "const p = require('./packages/cli/package.json'); console.log(p.version)"
  86. Should print "0.7.1"
  87. 4. Bump the root version: npm version patch --no-git-tag-version
  88. 5. Run: node scripts/sync-version.js
  89. 6. Verify packages/cli/package.json version matches the new root version
  90. DEPENDENCIES: none