code-migration

code-migration:用于在框架、语言和 API 版本之间迁移代码库。适用于将 JavaScript 转为 TypeScript、将 React 类组件迁移为 Hooks、将 Vue 2 升级到 Vue 3、将 Python 2 迁移到 Python 3、更新弃用 API、切换 ORM、或将 Express 转为 Fastify 等现代化和增量迁移场景,支持保持向后兼容性。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
7

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "code-migration":https://skillpi.com/zh/skills/deepskill-abf49965fec919f869d7fa62415a65b577e18d0e6fdfde78a077f5f610bcb7bc。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

code-migration:用于在框架、语言和 API 版本之间迁移代码库。适用于将 JavaScript 转为 TypeScript、将 React 类组件迁移为 Hooks、将 Vue 2 升级到 Vue 3、将 Python 2 迁移到 Python 3、更新弃用 API、切换 ORM、或将 Express 转为 Fastify 等现代化和增量迁移场景,支持保持向后兼容性。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

软件、账号及付费要求
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: code-migration
description: >-
  Migrate codebases between frameworks, languages, and API versions. Use when
  a user asks to convert JavaScript to TypeScript, migrate React class
  components to hooks, upgrade Vue 2 to Vue 3, migrate Python 2 to 3, update
  deprecated APIs, switch ORMs, convert Express to Fastify, or modernize
  legacy code. Handles incremental migration with backward compatibility.
license: Apache-2.0
compatibility: "Any modern development environment"
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: development
  tags: ["migration", "typescript", "modernization", "refactoring", "upgrade"]

Code Migration

Overview

Migrate codebases between frameworks, languages, and API versions with automated, incremental transformations. This skill handles JavaScript-to-TypeScript conversions, framework upgrades, deprecated API replacements, and ORM migrations while preserving functionality and maintaining backward compatibility.

Instructions

When a user asks to migrate or modernize their code, follow these steps:

Step 1: Assess the migration scope

Analyze the codebase to understand:

  • Source: Current framework/language version
  • Target: Desired framework/language version
  • Size: Number of files and lines affected
  • Dependencies: Libraries that need updating or replacing
  • Risk areas: Custom patches, monkey-patches, or framework internals usage
# Count affected files
find src -name "*.js" | wc -l       # JS→TS migration
grep -rl "React.Component" src/     # Class→hooks migration
grep -rl "Vue.component" src/       # Vue 2 patterns

Step 2: Create a migration plan

Before changing code, produce a migration plan:

## Migration Plan: JS → TypeScript

**Files to migrate:** 47
**Estimated effort:** ~2 hours with AI assistance

### Phase 1: Setup (non-breaking)
- Add tsconfig.json with allowJs: true
- Install TypeScript and type packages
- Rename entry point to .ts

### Phase 2: Incremental conversion (file by file)
- Rename .js → .ts/.tsx
- Add type annotations to function signatures
- Replace `any` with proper types
- Fix type errors

### Phase 3: Strict mode
- Enable strict: true in tsconfig
- Resolve remaining `any` types
- Add return type annotations

Step 3: Execute the migration file by file

Process files incrementally, verifying each change:

JavaScript → TypeScript:

// BEFORE: src/utils/api.js
const fetchUser = async (id) => {
  const response = await fetch(`/api/users/${id}`);
  if (!response.ok) throw new Error('User not found');
  return response.json();
};
module.exports = { fetchUser };

// AFTER: src/utils/api.ts
interface User {
  id: string;
  email: string;
  name: string;
  createdAt: string;
}

export const fetchUser = async (id: string): Promise<User> => {
  const response = await fetch(`/api/users/${id}`);
  if (!response.ok) throw new Error('User not found');
  return response.json() as Promise<User>;
};

React class → hooks:

// BEFORE
class UserProfile extends React.Component {
  state = { user: null, loading: true };

  componentDidMount() {
    fetchUser(this.props.id).then(user =>
      this.setState({ user, loading: false })
    );
  }

  componentDidUpdate(prevProps) {
    if (prevProps.id !== this.props.id) {
      this.setState({ loading: true });
      fetchUser(this.props.id).then(user =>
        this.setState({ user, loading: false })
      );
    }
  }

  render() {
    if (this.state.loading) return <Spinner />;
    return <div>{this.state.user.name}</div>;
  }
}

// AFTER
function UserProfile({ id }: { id: string }) {
  const [user, setUser] = useState<User | null>(null);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    setLoading(true);
    fetchUser(id).then(user => {
      setUser(user);
      setLoading(false);
    });
  }, [id]);

  if (loading) return <Spinner />;
  return <div>{user?.name}</div>;
}

Vue 2 → Vue 3 (Options → Composition API):

<!-- BEFORE: Vue 2 Options API -->
<script>
export default {
  data() {
    return { count: 0, items: [] };
  },
  computed: {
    total() { return this.items.reduce((s, i) => s + i.price, 0); }
  },
  mounted() { this.fetchItems(); },
  methods: {
    async fetchItems() {
      this.items = await api.getItems();
    }
  }
};
</script>

<!-- AFTER: Vue 3 Composition API -->
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';

const count = ref(0);
const items = ref<Item[]>([]);
const total = computed(() => items.value.reduce((s, i) => s + i.price, 0));

async function fetchItems() {
  items.value = await api.getItems();
}

onMounted(fetchItems);
</script>

Step 4: Update dependencies and configuration

# For JS→TS
npm install -D typescript @types/node @types/react
npx tsc --init

# For Vue 2→3
npm install vue@3 @vue/compiler-sfc
npm uninstall vue-template-compiler

# Update import paths, build config (vite/webpack), and aliases

Step 5: Verify after migration

After each file or batch:

  1. Run the type checker: npx tsc --noEmit
  2. Run existing tests: npm test
  3. Run the linter: npx eslint src/
  4. Build the project: npm run build

Report any errors and fix them before proceeding.

Examples

Example 1: Migrate an Express.js project from JavaScript to TypeScript

User request: "Convert my Express app from JS to TS"

Actions taken:

  1. Analyzed project: 23 JS files, Express 4.18, no existing types
  2. Installed TypeScript, @types/express, @types/node, ts-node
  3. Created tsconfig.json with allowJs: true for incremental migration
  4. Renamed files .js → .ts starting from leaf modules (utils, models)
  5. Added interfaces for request/response bodies
  6. Converted require → import, module.exports → export
  7. Added type annotations to route handlers

Result:

Files migrated: 23/23
Type errors fixed: 41
New interfaces created: 8 (User, Product, Order, ApiError, etc.)
Build: ✅ passing
Tests: ✅ 34/34 passing

Example 2: Update deprecated React Router v5 to v6

User request: "Upgrade our app from React Router 5 to 6"

Actions taken:

  1. Identified 12 files using React Router v5 APIs
  2. Applied transformations:
    • <Switch> → <Routes>
    • <Route component={X}> → <Route element={<X />}>
    • useHistory() → useNavigate()
    • <Redirect to="/"> → <Navigate to="/" replace>
    • Nested routes restructured with <Outlet />
  3. Updated react-router-dom to v6.20

Before/After:

// v5
<Switch>
  <Route exact path="/" component={Home} />
  <Route path="/users/:id" component={UserProfile} />
  <Redirect to="/" />
</Switch>

// v6
<Routes>
  <Route path="/" element={<Home />} />
  <Route path="/users/:id" element={<UserProfile />} />
  <Route path="*" element={<Navigate to="/" replace />} />
</Routes>

Result: 12 files updated, 0 type errors, all 28 tests passing.

Guidelines

  • Always migrate incrementally — one file or module at a time. Never attempt a big-bang rewrite.
  • Create the migration plan before writing any code. Share it with the user for approval on large projects.
  • For JS→TS, start with strict: false and allowJs: true, then tighten after all files are converted.
  • Preserve existing behavior exactly. Migration should not change functionality.
  • Run tests after every file migration. If tests break, fix before proceeding.
  • When migrating frameworks, check the official migration guide first (e.g., Vue 2→3, Angular upgrade guide).
  • Handle deprecated APIs by checking the library's changelog for the recommended replacement.
  • For large codebases (100+ files), suggest migrating in phases across multiple PRs.
  • Keep require/import style consistent within each file during migration — don't mix.
  • Add type annotations starting with function signatures, then variables, then generics. Don't over-type.

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 支持多种主流框架和语言的迁移场景,如 JS→TS、React 类→Hooks、Vue 2→3、Python 2→3 等
  • 提供增量迁移策略,保持向后兼容性,适合实际生产环境使用
触发精准95/100

亮点

  • 触发描述覆盖全面,边界清晰,用户可准确识别适用场景
结构规范95/100

亮点

  • 步骤划分清晰,包含端到端示例和迁移计划模板
  • frontmatter 完整,文档结构规范,易于理解和执行
执行可靠90/100

亮点

  • 工具来源明确,参数正确,覆盖主要异常处理
  • 强调测试验证和用户确认,确保迁移过程安全可靠
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

翻译待完成,请参阅来源文档。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。