code-migration
它能做什么
它提供一种方法,将应用或库迁移到另一种语言,并在过程中检查每个函数。适用于重写软件的开发者,例如将 Java 应用迁移到 Kotlin。
适用场景
- ✓当团队想把一个库从一种编程语言移植到另一种语言时。
- ✓当开发者需要查看哪些函数已经移植、哪些还未移植时。
- ✓当团队想检查同一应用的两个版本在行为上是否仍然一致时。
技能链接
https://github.com/kucherenko/jscpd/blob/master/skills/code-migration/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我把这个 Python 库逐个函数地移植到 TypeScript,并跟踪还剩下什么。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能使用比较工具,将每个源函数与其对应的函数配对。它要求 AI 先移植测试,再移植被测试的代码,并用结果跟踪进度。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
code-migration
jscpd --compare SOURCE TARGET pairs every function of one folder with the function of the other folder that does the same job, in any pair of languages, and lists the functions that have no counterpart. This skill uses it to measure a port: what is ported, what is left, and whether the port you just wrote was recognized.
A port runs in two phases: the tests first, then the code they check. A coverage report of the source's tests tells which tests exercise which function, so each function is ported together with the tests that prove it works. See Plan: tests first, then code.
Two words are used throughout:
- source: the implementation you port from, such as the iOS app, the Python library, or the JavaScript package;
- target: the implementation you port to, such as the Android app, the Rust crate, or the TypeScript rewrite.
Neither has to be old or new. The source may stay in production and keep changing, and the target may already hold features the source lacks. For two implementations that both live on (ios/ and android/), the same report shows parity; see Parity.
jscpd finds functions in JavaScript, TypeScript, JSX, TSX, Vue, Svelte, Astro, Python, Rust, Go, Java, Kotlin, C#, C, C++, PHP, Ruby, Scala and Swift. The compare-codebases skill explains how the comparison pairs functions and how to check its result; the jscpd skill covers the rest of the tool.
Setup
--compare pairs functions with a code embedding model that runs inside jscpd. Download it once (548 MB, CodeRankEmbed). Ask the user before you start the download:
npx jscpd --semantic-download
jscpd caches the vectors, so a repeat run embeds only the functions whose code changed and takes seconds.
Pick the two paths and keep them fixed for the whole port: the source first, the target second. Two paths are required, and they must not overlap (app/ and app/android/ is refused). The target may be empty at the start.
One run measures both phases: the report has a Code block and a Tests block (a code and a tests section in JSON), and a test pairs only with a test. jscpd tells a test by the conventions of its language: test files such as *_test.go, test_*.py, *.test.ts or *Test.java, folders such as tests/, __tests__/ or src/test/, Rust tests in #[cfg(test)] modules, and JavaScript test cases such as it('rounds cents', () => …). Phase 1 reads the Tests block, phase 2 the Code block.
Keep vendored and generated code out
--compare counts and embeds every function in both paths. Vendored dependencies (vendor/ from cargo vendor or go mod vendor, third_party/), installed packages (node_modules/, .venv/), build output (target/, build/, dist/) and generated code are not part of the port, yet a vendored crate tree alone holds thousands of functions. With them in a path, the first run embeds all of them and takes tens of minutes instead of seconds, and the percentages describe the dependencies instead of the port.
jscpd skips what .gitignore excludes, but only inside a git repository. Before the first run:
Check both paths for such folders. A target you create for the port gets them as soon as you build it or vendor its dependencies, so check again after the first build.
Suggest a
.gitignoreto the user that lists the folders the target's language and tools produce, plus the report folder. For a Rust addon built with napi-rs:/target/ /vendor/ node_modules/ *.node .jscpd-compare/If the target is not in a git repository, tell the user that jscpd reads the
.gitignoreonly aftergit init.Until the
.gitignoreworks, pass the same folders with--ignore, and keep the globs the same for every run:npx jscpd --compare node-lib/ rust-lib/ --ignore "**/vendor/**,**/target/**,**/node_modules/**"
The totals line shows when something slipped through. Suspect vendored or generated code in a path when the target has far more functions than the source, or when a run embeds hundreds of functions after a small change.
Measure
Run the console report for yourself and for the user. Here a Python billing library is being ported to TypeScript:
npx jscpd --compare billing-py/ billing-ts/
71% 5 of 7 functions in billing-py/ have a counterpar
常见问题
它如何跟踪进度?
它使用比较报告,显示哪些函数在另一个代码库中有对应项,哪些没有。
为什么要先写测试?
每个函数都与证明其可用的测试一起移植,因此新版本可以在成长过程中被检查。
它能比较两个都仍在使用的应用吗?
可以。同一份报告可以显示两个仍在运行的实现之间的相似程度。
详情
作者的原始描述
Move code from one implementation to another function by function, tests first and code second, and check two implementations of one app for parity, with jscpd --compare as the progress measure and a coverage map binding each function to its tests. Use when porting a library or app to another language or framework (Java to Kotlin, JavaScript to Rust, a Python library to TypeScript, an iOS app to Android), when asked what is left to port, or when comparing the Android and iOS versions of an app.
repo: kucherenko/jscpd
热度
- GitHub 星标
- 6.5k
- 排名
- #14187
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
codebase-refactoring
6.5k帮你的智能体改善代码库的健康状况:按顺序修复重复代码、删除无用代码,并简化最复杂的文件。
compare-codebases
6.5k帮你的智能体逐个函数地比较两个代码文件夹,即使跨越不同语言,也能看出哪些函数相互对应,哪些缺失。
dry-refactoring
6.5k帮你的智能体通过将重复的代码块合并为共享函数来删除项目中复制粘贴的代码,并从重复最多的部分开始处理。
jscpd
6.5k帮你的智能体在项目中查找复制粘贴的代码,包括完全相同、重命名或近似的副本,并衡量有多少代码是重复的。