Skip to content

feat(env): add Nushell support via env.nu wrapper#1312

Open
naokihaba wants to merge 18 commits intovoidzero-dev:mainfrom
naokihaba:feat/nushell-support
Open

feat(env): add Nushell support via env.nu wrapper#1312
naokihaba wants to merge 18 commits intovoidzero-dev:mainfrom
naokihaba:feat/nushell-support

Conversation

@naokihaba
Copy link
Copy Markdown
Contributor

@naokihaba naokihaba commented Apr 5, 2026

resolves #1144

While comprehensive support for Nushell seems to be under development in #1305, that pull request has a large impact. Therefore, I have limited the scope of this change to env support to align with the existing issue.

# 1. Setup
vp env setup
source ~/.vite-plus/env.nu  # or restart Nushell

# 2. Set a specific version
vp env use 20
# Using Node.js v20.20.2 (resolved from 20)
$env.VP_NODE_VERSION
# 20.20.2

# 3. Resolve from .node-version
vp env use
# Using Node.js v22.18.0 (resolved from .node-version)
$env.VP_NODE_VERSION
# 22.18.0

# 4. Completion (requires Fish)
vp <Tab>
# add        Add packages to dependencies
# build      Build application
# cache      Manage the task cache
# check      Run format, lint, and type checks
# ... (all subcommands shown)

# 5. False detection regression (bash launched from Nushell)
# NU_VERSION is inherited by child processes, but VP_SHELL_NU is not set,
# so vp correctly uses POSIX eval mode inside bash.
bash -c 'vp env use 20 && echo $VP_NODE_VERSION'

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 5, 2026

Deploy Preview for viteplus-preview canceled.

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

@naokihaba naokihaba changed the title Feat/nushell support feat(env): add Nushell support via env.nu wrapper Apr 5, 2026
@naokihaba
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@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: d39efa0262

ℹ️ 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".

Comment on lines +539 to +542
load-env ($exports | reduce -f {} {|it, acc| $acc | insert $it.key $it.value})
}
let unsets = ($out | lines | where { $in =~ '^hide-env ' } | parse 'hide-env {key}' | get key)
for key in $unsets { hide-env $key }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Apply vp env use mutations in emitted order

When vp env use is run without a version argument, the command intentionally prints hide-env VP_NODE_VERSION first and then $env.VP_NODE_VERSION = "..." so the final state is the resolved version. This wrapper parses all exports and applies them before all unsets, which reverses that ordering and leaves VP_NODE_VERSION unset in Nushell for the common vp env use flow. That breaks the new Nushell env-wrapper behavior because the shell no longer retains the resolved version after the command succeeds.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@naokihaba
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@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: 08a8e9de56

ℹ️ 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".

Comment on lines +37 to +38
} else if config.nu_version.is_some() {
Shell::NuShell
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard Nu shell detection behind explicit wrapper marker

Checking only NU_VERSION here causes false NuShell detection in POSIX wrappers when a bash/zsh session is launched from Nushell, because NU_VERSION is inherited by child processes. In that scenario vp env use is run with VP_ENV_USE_EVAL_ENABLE=1 from env, but this branch emits Nu syntax ($env.VP_NODE_VERSION = ...) that POSIX eval cannot execute, so the shell session is not updated. Detect NuShell via an explicit wrapper signal (or additional shell validation) instead of any inherited NU_VERSION.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +520 to +524
// Nushell env file with vp wrapper function.
// Completions delegate to Fish via vp.fish because clap_complete_nushell generates
// multiple rest params (e.g. for `vp install`), which Nushell does not support.
let env_nu_content = r#"# Vite+ environment setup (https://viteplus.dev)
$env.PATH = ($env.PATH | where { $in != "__VP_BIN__" } | prepend "__VP_BIN__")
Copy link
Copy Markdown
Contributor Author

@naokihaba naokihaba Apr 5, 2026

Choose a reason for hiding this comment

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

ref: clap-rs/clap#5771

When a command has multiple Vec arguments (for example, when vp install has both packages and pass_through_args), clap_complete_nushell generates invalid syntax. This is because Nushell's extern only allows a single ...rest parameter

Error: nu::parser::multiple_rest_params
× Multiple rest params.
  ...packages: string
  ...pass_through_args: string  ← Nushell rejects this

As a workaround for this problem, completion processing is delegated to Fish. Running vp env setup generates vp.fish (which is shared with the Fish shell integration), so if Fish is installed, completions can be used without any additional configuration.

@naokihaba naokihaba marked this pull request as ready for review April 5, 2026 19:08
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.

nushell env wrapper

1 participant