fix(codemod): only count real module specifiers in project-type inference - #2765
Open
claude[bot] wants to merge 2 commits into
Open
fix(codemod): only count real module specifiers in project-type inference#2765claude[bot] wants to merge 2 commits into
claude[bot] wants to merge 2 commits into
Conversation
…ence
The v1→v2 source scanner matched any quoted @modelcontextprotocol/sdk/client|server
subpath anywhere in a scanned file, so an SDK path appearing in an ordinary string
literal (example text, a log message, a config value) counted as an import. A
client-only project carrying such a string was classified 'both': shared type
imports were rewritten to @modelcontextprotocol/server and a server dependency the
project never uses was added to package.json.
The client/server detection regexes are now anchored to genuine module-specifier
positions — after 'from' (static imports and re-exports), 'import' (side-effect and
dynamic imports), or 'require(' — so arbitrary string occurrences no longer affect
inference.
Fixes #2760.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KWwxVxEvDmfaFhr7EPAWpR
🦋 Changeset detectedLatest commit: 8652eee 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: |
…ecifiers in inference Review follow-up: the specifier-position anchor missed forms the codemod itself treats as SDK module specifiers — vi./jest. mock-method calls (the ones the mock-paths transform rewrites), dynamic import() carrying a webpack magic comment, and require.resolve() — so a project whose only signal for one SDK side used such a form degraded to 'unknown'/one-sided inference vs base. MOCK_CALLERS/MOCK_METHODS move to utils/importUtils as the single source of truth (projectAnalyzer cannot import them from the mock-paths transform without a cycle; mockPaths re-exports them for runner.ts) and the analyzer builds its specifier-position alternatives from them. Fail-first tests added for all three forms. Also narrows the changeset and inline-comment claims to what the lexical scan actually guarantees — bare SDK paths in string data no longer count — and adds a test documenting the known remaining case: a string whose text embeds a full import statement still matches, since only a real parser could tell the inner `from '` apart from a genuine specifier position. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KWwxVxEvDmfaFhr7EPAWpR
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.
Requested via Slack thread
Fixes #2760.
Before: the v1→v2 codemod's project-type inference regex-matched any quoted
@modelcontextprotocol/sdk/client|serversubpath anywhere in a scanned file, so an SDK path that only appears inside an ordinary string literal — example text, a log message, a config value — counted as an import. A client-only project carrying one server path as data was classified as using both packages: its shared type imports (e.g.types.js) were rewritten to@modelcontextprotocol/server, andpackage.jsongained both@modelcontextprotocol/clientand@modelcontextprotocol/server, including a server dependency the project never uses.After: only genuine module specifiers affect inference — static imports and re-exports (
from '...'), side-effect imports (import '...'), dynamicimport('...'), andrequire('...'). The reported fixture is now classifiedclient, its shared type import moves to@modelcontextprotocol/client, and no server dependency is added. String occurrences of SDK paths are ignored, matching how the imports transform itself (which is already specifier-aware and never rewrote the literal) treats them.How: the two detection regexes in
packages/codemod/src/utils/projectAnalyzer.tsnow require a module-specifier position — the quoted path must followfrom,import/import(, orrequire(— instead of matching any quoted occurrence. Three tests added topackages/codemod/test/projectAnalyzer.test.ts: the string-literal regression (fails onmainwithboth, passes withclientafter the fix) plus two guard tests pinning that dynamicimport()/require()and side-effect/export ... fromspecifiers still count. Full codemod suite: 632/632 passing;pnpm run check(tsgo typecheck + ESLint + Prettier) clean; patch changeset for@modelcontextprotocol/codemodincluded and Prettier-clean. Verified end-to-end with the issue's fixture viatsx src/cli.ts v1-to-v2 <fixture> --transforms imports --verbose.🤖 Generated with Claude Code
https://claude.ai/code/session_01KWwxVxEvDmfaFhr7EPAWpR
Generated by Claude Code