跳到内容

用户态迁移

🌐 Userland Migrations

Node.js 为“用户代码”(即 node 可执行文件之外的任何内容)提供迁移工具,以帮助采用新功能并处理破坏性更改。这些工具是与 Codemod 合作开发的,Codemod 是一个专注于简化构建、共享和运行代码修改工具的平台。

🌐 Node.js offers migrations for "userland" code (anything outside the node executable) to help adopt new features and handle breaking changes. These are built in collaboration with Codemod, a platform focused on making it easy to build, share, and run codemods.

官方迁移版本会在 Codemod 注册表 中以 @nodejs 范围发布。这些迁移已经由 Node.js 成员审核和/或撰写。

🌐 Official migrations are published under the @nodejs scope within the Codemod registry. These have been reviewed and/or authored by Node.js members.

目标

🌐 Goal

Node.js 用户空间迁移团队致力于帮助开发者将其代码库迁移到最新的 Node.js 版本,从而更轻松地处理弃用、新功能和重大变更。

🌐 The Node.js Userland Migrations team seeks to help developers migrate their codebases to the latest Node.js versions, making it easier to handle deprecations, new features, and breaking changes.

如何使用代码修改器

🌐 How to use a codemod

要使用代码转换,你可以在终端中运行以下命令:

🌐 To use a codemod, you can run the following command in your terminal:

npx codemod <codemod-name>

<codemod-name> 替换为你想运行的 codemod 的名称。例如,如果你想在项目上运行 @nodejs/import-assertions-to-attributes codemod,你可以运行:

🌐 Replace <codemod-name> with the name of the codemod you want to run. For example, if you want to run the @nodejs/import-assertions-to-attributes codemod on your project, you would run:

npx codemod @nodejs/import-assertions-to-attributes

良好实践

🌐 Good Practices

  • 在单独的分支中运行迁移:如果你使用像 Git 这样的版本控制系统,最好在单独的分支中运行迁移。这可以让你在将更改合并到主分支之前进行审查。
  • 审查更改:在运行迁移后,检查对代码库所做的更改。确保迁移没有引入任何意外的副作用或问题。
  • 测试你的代码:在运行迁移之后,测试你的代码非常重要,以确保一切按预期工作。运行你的测试套件,并检查是否有任何错误或失败
  • 格式化或检查你的代码:在运行迁移之后,格式化和检查你的代码是一个好习惯。这可以确保你的代码符合项目的编码标准,并且更易于阅读和维护。

了解 Codemods 注册表

🌐 Understanding Codemods Registry

Codemod 注册表 提供了可用于 Node.js 的 codemod 列表。一些 codemod 可能未包含在以下资源中,但仍然可用,因为它们与具体的 Node.js 版本迁移无关。由于我们只列出了针对终止支持(EOL)弃用的 codemod,你可能需要浏览注册表以查找其他可能对你的迁移有用的 codemod。

🌐 The Codemod registry provides a list of available codemods for Node.js. Some codemods may not be included in the following resources but are still available because they are not related to a specific migration to a Node.js version. Since we only list codemods for End-Of-Life (EOL) deprecations, you may need to explore the registry for other codemods that could be useful for your migrations.

请注意,如果你已登录 Codemod 平台,你可以点赞这些帖子。这有助于我们了解用户认为哪些内容有价值。

反馈

🌐 Feedback

如果你有任何反馈或改进建议,请在 Node.js Userland Migrations 仓库 上开启讨论。

🌐 If you have any feedback or suggestions for improvements, please open a discussion on the Node.js Userland Migrations repository.

关注用户空间迁移进展

🌐 Follow the Userland Migrations Progression

你可以在我们的 GitHub 项目板 上跟踪用户空间迁移的进展。

🌐 You can follow the progress of userland migrations on our GitHub project board.

此看板跟踪:

🌐 This board tracks:

  • Codemod 类型(弃用、更改破坏、生态系统)
  • Node.js 版本
  • 状态(待办、todo、进行中、已完成、未计划) 如果你想贡献,请查看“todo”列

迁移指南

🌐 Migrations guides

你可以在 迁移指南部分 找到所有迁移指南。

🌐 You can find all migrations guide on the migration guides section.

请注意,重大版本的迁移指南仅包含生命周期结束的弃用和重大变更。

🌐 Please also note that migration guides for major-major releases only contain end-of-life deprecations and breaking changes.