Skip to content

Commit 79dc162

Browse files
Read codemod target versions from workspace manifests at build time (#2419)
1 parent ddf6cc1 commit 79dc162

7 files changed

Lines changed: 27 additions & 49 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/codemod': patch
3+
---
4+
5+
Read the v2 package versions the codemod writes into migrated `package.json` files directly from the workspace manifests at build time, replacing the committed generated `versions.ts` (which went stale after every release and made source builds write outdated versions).

packages/codemod/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
],
4242
"scripts": {
4343
"typecheck": "tsgo -p tsconfig.json --noEmit",
44-
"generate:versions": "tsx scripts/generateVersions.ts",
45-
"prebuild": "pnpm run generate:versions",
4644
"build": "tsdown",
4745
"build:watch": "tsdown --watch",
4846
"prepack": "pnpm run build",

packages/codemod/scripts/generateVersions.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

packages/codemod/src/bin/batchTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { tmpdir } from 'node:os';
66
import path from 'node:path';
77
import { fileURLToPath, pathToFileURL } from 'node:url';
88

9-
import { V2_PACKAGE_VERSIONS } from '../generated/versions';
109
import { getMigration } from '../migrations/index';
1110
import { run } from '../runner';
1211
import type { Diagnostic, Migration } from '../types';
12+
import { V2_PACKAGE_VERSIONS } from '../versions';
1313

1414
// ---------------------------------------------------------------------------
1515
// Types

packages/codemod/src/generated/versions.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/codemod/src/utils/packageJsonUpdater.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import path from 'node:path';
33

44
import fg from 'fast-glob';
55

6-
import { V2_PACKAGE_VERSIONS } from '../generated/versions';
76
import type { PackageJsonChange } from '../types';
7+
import { V2_PACKAGE_VERSIONS } from '../versions';
88
import { findPackageJson } from './projectAnalyzer';
99

1010
const V1_PACKAGE = '@modelcontextprotocol/sdk';

packages/codemod/src/versions.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import clientPkg from '../../client/package.json';
2+
import corePkg from '../../core/package.json';
3+
import expressPkg from '../../middleware/express/package.json';
4+
import nodePkg from '../../middleware/node/package.json';
5+
import serverPkg from '../../server/package.json';
6+
import serverLegacyPkg from '../../server-legacy/package.json';
7+
8+
/**
9+
* Caret ranges for the v2 packages the codemod writes into migrated package.json
10+
* files. Versions come straight from the workspace manifests — the bundler inlines
11+
* them at build time — so a release bump can never leave this map stale.
12+
*/
13+
export const V2_PACKAGE_VERSIONS: Record<string, string> = {
14+
'@modelcontextprotocol/client': `^${clientPkg.version}`,
15+
'@modelcontextprotocol/server': `^${serverPkg.version}`,
16+
'@modelcontextprotocol/node': `^${nodePkg.version}`,
17+
'@modelcontextprotocol/express': `^${expressPkg.version}`,
18+
'@modelcontextprotocol/server-legacy': `^${serverLegacyPkg.version}`,
19+
'@modelcontextprotocol/core': `^${corePkg.version}`
20+
};

0 commit comments

Comments
 (0)