Repository navigation
fix(codemod): add test-only v2 packages to devDependencies - #3208
Open
costajohnt wants to merge 1 commit into
Open
costajohnt wants to merge 1 commit into
costajohnt wants to merge 1 commit into
Conversation
When the v1 SDK sat in dependencies, the v1-to-v2 codemod added every v2 package the code imports to dependencies, including packages only test files import. Track which files use each specifier through the hoisting roll-up and put packages only test files import in devDependencies, classified relative to the receiving manifest like the injected zod dependency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 930b419 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
When
@modelcontextprotocol/sdkis independencies, thev1-to-v2codemod adds every v2 package the code imports todependencies, including packages that only test files import. I hit this migrating a real MCP server:src/server.tsimports@modelcontextprotocol/sdk/server/mcp.jsand the tests import@modelcontextprotocol/sdk/client/index.js, and both@modelcontextprotocol/serverand@modelcontextprotocol/clientended up independencies. The upgrade guide puts test-only packages indevDependencies, and the codemod already does that for thezodit injects.What changed
packages/codemod/src/runner.ts: record which files import each specifier, next tousedByManifest, and pass it toupdatePackageJson.packages/codemod/src/utils/packageJsonUpdater.ts: roll that file map up through the existing workspace hoisting. A package goes todevDependenciesonly when every file that imports it is a test file, checked relative to the manifest that receives it with the sameTEST_PATH_REas the zod demotion (now a sharedisTestFilehelper). Anything a non-test file imports lands where it did before, and existing entries are never moved.How Has This Been Tested?
Four new runner-level cases in
test/v1-to-v2/packageJsonUpdater.test.ts: a test-only package, a package used by both test and source files, a hoisted workspace member, and atests/segment in an ancestor directory. The test-only and hoisted cases fail onmain(dependenciesgets both client and server) and pass with this change; the other two pass on both and guard against demoting too much. Inpackages/codemod: typecheck, lint and the full suite (649 tests) pass.Breaking Changes
None.