Manage Node.js version in a Foundry code repository(管理 Foundry 代码仓库中的 Node.js 版本)¶
Foundry code repositories support Node Version Manager (nvm) ↗ to manage the Node.js version used in your project and CI. By adding an .nvmrc file to the root of your repository, you can specify which Node.js version your project uses.
:::callout{theme="neutral"}
If you do not use nvm, the CI will use the Node.js version specified in .jemma/settings.sh and the Foundry development environment will use version 18.20.8.
:::
Add an .nvmrc file¶
To set a Node.js version for your repository, create a file named .nvmrc in the root of your project. This file should contain only the version number of Node.js you want to use, prefixed with v, for example:
v24.13.0
You can view available Node.js versions by running nvm ls-remote in a terminal within your code repository.
Use the specified version¶
After adding the .nvmrc file, run the following command in the terminal to switch to the version defined in the file:
nvm install
Configure CI to use the .nvmrc version¶
To ensure your CI builds use the same Node.js version specified in your .nvmrc file, update the .jemma/settings.sh file in your repository.
Replace the existing NODE_INSTALLATION_VERSION export with the following line, which reads the version directly from your .nvmrc file:
export NODE_INSTALLATION_VERSION=$(sed 's/^v//' "$(dirname "${BASH_SOURCE[0]}")/../.nvmrc")
With this change, you only need to update the .nvmrc file to change the Node.js version for both your Foundry development and CI environments.
中文翻译¶
管理 Foundry 代码仓库中的 Node.js 版本¶
Foundry 代码仓库支持使用 Node Version Manager (nvm)(版本管理器)↗(https://github.com/nvm-sh/nvm)来管理项目及 CI 中使用的 Node.js 版本。通过在仓库根目录添加 .nvmrc 文件,您可以指定项目所使用的 Node.js 版本。
:::callout{theme="neutral"}
如果您不使用 nvm,CI 将使用 .jemma/settings.sh 中指定的 Node.js 版本,而 Foundry 开发环境将使用版本 18.20.8。
:::
添加 .nvmrc 文件¶
要为您的仓库设置 Node.js 版本,请在项目根目录创建一个名为 .nvmrc 的文件。该文件应仅包含您要使用的 Node.js 版本号,并以 v 开头,例如:
v24.13.0
您可以通过在代码仓库的终端中运行 nvm ls-remote 命令来查看可用的 Node.js 版本。
使用指定版本¶
添加 .nvmrc 文件后,在终端中运行以下命令,即可切换到文件中定义的版本:
nvm install
配置 CI 使用 .nvmrc 版本¶
为确保您的 CI 构建使用 .nvmrc 文件中指定的 Node.js 版本,请更新仓库中的 .jemma/settings.sh 文件。
将现有的 NODE_INSTALLATION_VERSION 导出语句替换为以下内容,该命令会直接从您的 .nvmrc 文件中读取版本号:
export NODE_INSTALLATION_VERSION=$(sed 's/^v//' "$(dirname "${BASH_SOURCE[0]}")/../.nvmrc")
通过此更改,您只需更新 .nvmrc 文件,即可同时更改 Foundry 开发环境和 CI 环境中的 Node.js 版本。