Skip to content

Read codemod target versions from workspace manifests at build time - #2419

Merged
felixweinberger merged 2 commits into
mainfrom
fweinberger/codemod-versions-from-package-json
Jul 2, 2026
Merged

felixweinberger merged 2 commits into
mainfrom
fweinberger/codemod-versions-from-package-json

Conversation

@felixweinberger

@felixweinberger felixweinberger commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Running pnpm install && pnpm build on a fresh clone leaves the repo dirty: the build regenerates packages/codemod/src/generated/versions.ts with contents that differ from what's committed.

Motivation and Context

The file is generated from the workspace package.json versions, but the changesets "Version Packages" PR bumps those manifests without regenerating it (most recently #2416, beta.1 → beta.2). So after every release the committed copy is stale — every local build produces the diff, and source builds of the codemod write the stale versions into migrated projects (^2.0.0-beta.1 instead of ^2.0.0-beta.2). Published artifacts were unaffected since publishing rebuilds.

Fix: stop committing derived state. src/versions.ts is now a normal source file that imports the six workspace package.jsons; the bundler inlines the version fields at build time. The generator script, prebuild hook, and generated/ directory are deleted. Version bumps flow through automatically; the only hand-maintained part is the name→path list the generator already hardcoded, now as imports that fail typecheck if a package moves. No tsconfig changes needed (resolveJsonModule and moduleResolution: bundler are already set).

How Has This Been Tested?

  • pnpm build no longer modifies the tree.
  • dist/ has all six versions inlined; no runtime reads of sibling manifests.
  • Ran the built CLI on fixture projects: writes ^2.0.0-beta.2 (was stale ^2.0.0-beta.1), devDependencies placement kept, --dry-run writes nothing, re-run is idempotent.
  • 623 package tests pass; workspace-wide typecheck/lint/build green.

Breaking Changes

None. V2_PACKAGE_VERSIONS is internal to the codemod.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Alternatives considered: gitignoring the generated file (CI typechecks before building, so fresh clones would need extra generate hooks) and regenerating inside the changesets version command (fixes the release writer but keeps the duplicated state in sync by process rather than by construction).

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants