Skip to content

feat(migrate): migrate .nvmrc to .node-version during vp migrate#1159

Open
naokihaba wants to merge 7 commits intovoidzero-dev:mainfrom
naokihaba:feat/migrate-nvmrc
Open

feat(migrate): migrate .nvmrc to .node-version during vp migrate#1159
naokihaba wants to merge 7 commits intovoidzero-dev:mainfrom
naokihaba:feat/migrate-nvmrc

Conversation

@naokihaba
Copy link
Contributor

@naokihaba naokihaba commented Mar 26, 2026

🔗 Related Issues

Resolves: #1158

📚 Description

Vite+ previously retrieved the Node.js version from .node-version, but projects using nvm typically use .nvmrc.

With this change, automatic detection of .nvmrc and a migration feature to .node-version have been added as part of the vp migrate command execution process.

During migration, if a v prefix is present at the beginning, it is removed, while aliases such as lts/* are carried over as is.

Unit tests have confirmed that it works correctly regardless of the presence of the v prefix.

On the other hand, if unsupported aliases like node or stable are included, the system is designed to display a warning and skip the migration rather than failing.

Manual Test: .nvmrc Migration

$ mkdir /tmp/vp-migrate-test
$ echo '{ "name": "test-migrate", "version": "1.0.0" }' > package.json
$ echo 'v20.5.0' > .nvmrc

Command

$ cd /tmp/vp-migrate-test && vp migrate --no-interactive

Output (Excerpt)

.nvmrc detected. Auto-migrating to .node-version...
...
• Node version manager file migrated to .node-version

Final State

$ cat /tmp/vp-migrate-test/.node-version
20.5.0
  • .nvmrc (v20.5.0) -> Deleted
  • .node-version -> 20.5.0 (With the v prefix removed)

@netlify
Copy link

netlify bot commented Mar 26, 2026

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit db3da18
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/69c57dfdcbb26900080afd60

async function confirmNodeVersionFileMigration(interactive: boolean): Promise<boolean> {
if (interactive) {
const confirmed = await prompts.confirm({
message: 'Migrate .nvmrc to .node-version?',
Copy link
Contributor Author

@naokihaba naokihaba Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Vite+, the Node.js version is determined based on the following priority order:

The sequence is ".node-version", followed by "engines.node" in package.json, and then "devEngines.runtime" in package.json.
For this reason, we are treating the migration of the ".node-version" file as the highest priority in this migration process.

/// Resolve Node.js version for a directory.
///
/// Resolution order:
/// 0. `VITE_PLUS_NODE_VERSION` env var (session override from `vp env use`)
/// 1. `.session-node-version` file (session override written by `vp env use` for shell-wrapper-less environments)
/// 2. `.node-version` file in current or parent directories
/// 3. `package.json#engines.node` in current or parent directories
/// 4. `package.json#devEngines.runtime` in current or parent directories
/// 5. User default from config.json
/// 6. Latest LTS version
pub async fn resolve_version(cwd: &AbsolutePath) -> Result<VersionResolution, Error> {

@naokihaba
Copy link
Contributor Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2e4dfd821

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@naokihaba
Copy link
Contributor Author

naokihaba commented Mar 26, 2026

Hmm... The snapshot diff is failing.

Error: Snapshot diff detected. Run 'pnpm -F vite-plus snap-test' locally and commit the updated snap.txt files.
packages/cli/snap-tests-global/create-next-command-library/snap.txt | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/packages/cli/snap-tests-global/create-next-command-library/snap.txt b/packages/cli/snap-tests-global/create-next-command-library/snap.txt
index 6ef3275..d4fb700 100644
--- a/packages/cli/snap-tests-global/create-next-command-library/snap.txt
+++ b/packages/cli/snap-tests-global/create-next-command-library/snap.txt
@@ -1,6 +1,3 @@
-> vp create vite:library --no-interactive # verify next command suggests vp run
+[1]> vp create vite:library --no-interactive # verify next command suggests vp run

@naokihaba
Copy link
Contributor Author

@codex review

@naokihaba naokihaba marked this pull request as ready for review March 26, 2026 18:47
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db3da182a1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

* Returns null for unsupported aliases like "node", "stable", "system".
*/
export function parseNvmrcVersion(content: string): string | null {
const version = content.split('\n')[0]?.trim();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse .nvmrc using full nvm syntax before migration

parseNvmrcVersion only inspects the first line (content.split('\n')[0]), so valid .nvmrc files that start with a comment/blank line or include inline comments/key-value lines are treated as unsupported and migration is skipped with a warning. Per nvm’s .nvmrc docs, comments and blank lines should be ignored during parsing (see https://github.com/nvm-sh/nvm#nvmrc), so this can silently miss real-world projects and fail the new auto-migration path even when a valid version is present later in the file.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing process for reading .node-version (parse_node_version_content) is also designed to read only the first line without excluding comments.

Therefore, this implementation follows the same limitations to maintain consistency across the codebase.
If necessary, I can revisit this and make further adjustments.

@fengmk2 fengmk2 self-assigned this Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vp migrate handles migration from .nvmrc

2 participants