升级工具
¥Upgrade tool
升级工具帮助 Strapi 用户将其 Strapi 应用依赖和代码升级到特定版本 。
¥The upgrade tool assists Strapi users in upgrading their Strapi application dependencies and code to a specific version.
运行升级工具会触发应用依赖的更新、它们的安装以及一系列代码修改 的执行,这些代码修改会根据目标版本之前引入的重大更改自动编辑应用代码库。
¥Running the upgrade tool triggers the update of the application dependencies, their installation, and the execution of a series of codemods that automatically edit the application codebase according to the breaking changes introduced up until the targeted version.
升级工具是一个 Strapi 包,可以从 CLI 运行。
¥The upgrade tool is a Strapi package and can be run from the CLI.
范围
¥Scope
虽然升级工具有助于升级应用和插件,但它并未涵盖其各个方面。
¥While the upgrade tool helps upgrade applications and plugins, it doesn't cover every aspect of it.
✅升级工具支持:
¥✅ The upgrade tool supports:
-
更新项目的依赖
¥Updating the project's dependencies
-
将自动代码转换应用于现有文件
¥Applying automatic code transformation to existing files
-
为项目安装或重新安装正确的依赖
¥Installing or re-installing the correct dependencies for the project
❌升级工具不支持:
¥❌ The upgrade tool doesn't support:
-
通过添加、删除或移动文件和目录来修改文件树
¥Modifying the file tree by adding, removing or moving files and directories
-
迁移应用的数据。这由 Strapi 数据库迁移处理
¥Migrating the application's data. This is handled by Strapi database migrations
升级工具完成执行后,强烈建议在重新运行应用或插件之前检查所做的修改。
¥After the upgrade tool completes its execution, it is strongly recommended to review the modifications made before re-running the app or plugin.
版本类型
¥Version types
Strapi 版本号遵守 语义版本控制 约定:
¥Strapi version numbers respect the semantic versioning conventions:


-
第一个数字是主版本号。
¥The first number is the major version number.
-
第二个数字是次要版本号。
¥The second number is the minor version number.
-
第三个数字是补丁版本号。
¥The third number is the patch version number.
升级工具允许升级到主要版本、次要版本或补丁版本。
¥The upgrade tool allows upgrading to a major, minor, or patch version.
升级工具的作用取决于最新的现有版本和你运行的命令。
¥What the upgrade tool does depends on the latest existing version and the command you run.
例如,如果最新的 Strapi v4 版本是 v4.25.9:
¥For instance, if the latest Strapi v4 version is v4.25.9:
我的 Strapi 应用目前正在…… | 如果我运行... | 我的 Strapi 应用将升级到…… |
---|---|---|
v4.25.1 | npx @strapi/upgrade patch | v4.25.9 (因为 v4.25.9 是 v4.25 次要版本的最新补丁版本) |
v4.14.1 | npx @strapi/upgrade minor | v4.25.9 |
v4.14.1 | npx @strapi/upgrade major | 没什么。 我首先需要运行 npx @strapi/upgrade minor 才能升级到 v4.25.9。 |
v4.25.9 | npx @strapi/upgrade major | v5.0.0 |
v4.14.1 | npx @strapi/upgrade latest | v5.1.2 出现确认提示,以确保主要版本升级是有意为之。 |
升级到新版本
¥Upgrade to a new version
在运行升级过程之前,请确保你已经创建了代码库和数据库的备份。
¥Before running the upgrade process, make sure you've created a backup of your codebase and database.
升级到主要版本版本
¥Upgrade to a major version
使用 major
参数运行升级工具,将项目升级到 Strapi 的下一个主要版本:
¥Run the upgrade tool with the major
parameter to upgrade the project to the next major version of Strapi:
npx @strapi/upgrade major
在升级过程中,将更新和安装应用依赖,并执行相关的代码修改。
¥During the upgrade process, the application dependencies are updated and installed, and the related codemods are executed.
如果你的应用尚未运行当前主要版本中的最新次要版本和补丁版本,则会阻止 major
升级,并且你首先需要升级到当前主要版本中的最新 minor.patch 版本。这意味着从 v4.14.4 迁移到 v5.0.0 是一个两步过程,因为最新的 v4 版本是 v4.16.2。
¥If your application is not already running the latest minor and patch version in the current major, the major
upgrade is prevented, and you will first need to upgrade to the latest minor.patch version in the current major version. This means that moving from v4.14.4 to v5.0.0 is a 2-step process because the latest v4 version is v4.16.2.