Skip to content

fnm env --use-on-cd applying current directory version #200

Description

@Dargon789

Reviewer's Guide

Implements immediate application of the current directory Node version during fnm env --use-on-cd, improves shell hooks (especially zsh and Windows CMD), prefers explicit shell selection in installer-generated env setup, adds support for the x64-glibc-217 architecture, and updates tests, docs, CI, and versioning metadata for the 1.39.0 release.

Sequence diagram for fnm env --use-on-cd applying current directory version

sequenceDiagram
    actor User
    participant Shell
    participant FnmEnv as Env_command
    participant SetPath as set_path_for_multishell
    participant UseCmd as Use_command

    User->>Shell: runs startup script
    Shell->>FnmEnv: fnm env --use-on-cd --shell <shell>
    FnmEnv->>SetPath: set_path_for_multishell(multishell_path)
    SetPath-->>FnmEnv: PATH updated with multishell_path
    FnmEnv->>FnmEnv: config_with_multishell = config.clone().with_multishell_path(multishell_path)
    FnmEnv->>UseCmd: construct Use { version: None, install_if_missing: false, silent_if_unchanged: true, info_to_stderr: true }
    FnmEnv->>UseCmd: apply(config_with_multishell)
    UseCmd-->>FnmEnv: apply result (ignored on error)
    FnmEnv-->>Shell: shell.use_on_cd(config) script
    Shell-->>User: environment ready, current directory version already active
Loading

Class diagram for updated Use, FnmConfig, Arch, and Directories types

classDiagram
    class Use {
        +UserVersion~Option~ version
        +bool install_if_missing
        +bool silent_if_unchanged
        +bool info_to_stderr
        +apply(config: FnmConfig) Result
    }

    class FnmConfig {
        +Url node_dist_mirror
        +Url node_rc_mirror
        +Option~PathBuf~ base_dir
        +Option~PathBuf~ multishell_path
        +with_base_dir(base_dir: Option~PathBuf~) FnmConfig
        +with_multishell_path(multishell_path: PathBuf) FnmConfig
    }

    class Directories {
        <<struct>>
    }

    class Arch {
        <<enum>>
        X86
        X64
        X64Musl
        X64Glibc217
        Arm64
        Armv7l
        Ppc64le
        Aarch64AppleDarwin
        +as_str() &str
        +from_str(s: &str) Result~Arch~
    }

    FnmConfig --> Directories : uses
    FnmConfig --> Arch : configured_with
    Use --> FnmConfig : apply(config)

    class WindowsCmd {
        +use_on_cd(config: FnmConfig) Result~String~
    }

    class Zsh {
        +use_on_cd(config: FnmConfig) Result~String~
    }

    WindowsCmd ..> FnmConfig : generates cd macro
    Zsh ..> FnmConfig : generates chpwd hook
Loading

File-Level Changes

Change Details Files
Apply current directory version eagerly when running fnm env --use-on-cd and route its informational output to stderr when used internally.
  • Introduce set_path_for_multishell to prepend the multishell path (or its bin subdir) to PATH before running Use during env setup.
  • Clone and extend FnmConfig with a new with_multishell_path helper and use it to configure the internal Use command inside Env when use_on_cd is enabled.
  • Add an info_to_stderr flag to the Use command and route messages to stderr when invoked internally from fnm env, while keeping stdout clean for shell evaluation.
  • Update all internal Use invocations (install, install_new_version, etc.) to set info_to_stderr appropriately and tweak the interactive missing-version error prefix to include fnm.
  • Add end-to-end tests to verify that use-on-cd applies the version immediately after env setup and remains correct when env is sourced multiple times.
src/commands/env.rs
src/commands/use.rs
src/commands/install.rs
src/config.rs
src/directories.rs
e2e/use-on-cd.test.ts
Harden and test shell hooks for --use-on-cd, particularly for zsh and Windows CMD, and slightly simplify other shell hooks.
  • Change the zsh use_on_cd hook to remove any existing _fnm_autoload_hook before adding it again via add-zsh-hook -D chpwd _fnm_autoload_hook, and add a unit test asserting this behavior.
  • Wrap the Windows CMD doskey macro path in quotes to safely handle paths with spaces and add a test that exercises a base directory containing spaces.
  • Update cd.cmd to call cd /d so drive changes work correctly on Windows, while still running the fnm use logic based on FNM_VERSION_FILE_STRATEGY.
  • Remove redundant initial autoload invocations from the Fish, Bash, and PowerShell use_on_cd hooks so that version switching is driven purely by the cd alias or hook logic.
src/shell/zsh.rs
src/shell/windows_cmd/mod.rs
src/shell/windows_cmd/cd.cmd
src/shell/fish.rs
src/shell/bash.rs
src/shell/powershell.rs
Prefer explicit shell flags in installer-generated setup, document this guidance, and tweak CLI/docs examples.
  • Update .ci/install.sh to call fnm env with explicit --shell flags for zsh, fish, and bash in the generated shell configuration blocks.
  • Adjust CLI help text and docs (README.md, docs/commands.md) to show examples that pass explicit --shell values instead of relying on runtime shell inference.
  • Add a tip to the README recommending explicit shell selection to reduce startup overhead and avoid process tree detection.
.ci/install.sh
src/cli.rs
README.md
docs/commands.md
Extend architecture support with x64-glibc-217 and wire it through parsing, display, and release notes.
  • Add a new X64Glibc217 variant to the Arch enum plus corresponding display string mapping and FromStr parsing for x64-glibc-217.
  • Introduce a changeset entry documenting --arch x64-glibc-217 support for fnm env.
  • Ensure new arch participation by including it in the release metadata (version bump and changelog).
src/arch.rs
.changeset/brave-timers-move.md
CHANGELOG.md
Cargo.toml
package.json
Refine CI for the installer script and clean up YAML/style issues.
  • Update the installation_script workflow to use a matrix with docker_platform so ARM Docker runs specify the correct --platform flag per image.
  • Normalize YAML formatting (quotes, spacing) and tweak job steps to use the new matrix fields while keeping behavior equivalent for non-ARM cases.
  • Add a changeset entry describing the installer CI platform selection fix and explicit shell preference.
  • Remove obsolete changeset files that have been folded into the 1.39.0 release.
.github/workflows/installation_script.yml
.changeset/cuddly-cars-ring.md
.changeset/fair-carrots-greet.md
.changeset/grumpy-dingos-turn.md
.changeset/odd-mayflies-poke.md
.changeset/twelve-badgers-happen.md
Prepare and document the 1.39.0 release, including behavior tweaks already implemented in code.
  • Bump crate and package versions from 1.38.1 to 1.39.0 in Rust and npm metadata.
  • Add a 1.39.0 section to the changelog describing the new env --use-on-cd behavior, use flag on install, zsh/CMD hook robustness, default-version behavior, and Rust toolchain bump.
  • Perform minor doc and SVG touchups associated with the release branding.
CHANGELOG.md
Cargo.toml
package.json
docs/fnm.svg

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Originally posted by @sourcery-ai[bot] in #199 (comment)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdependenciesPull requests that update a dependency filedocumentationImprovements or additions to documentationduplicateThis issue or pull request already existsenhancementNew feature or requestgithub_actionsPull requests that update GitHub Actions codegood first issueGood for newcomershelp wantedExtra attention is neededinvalidThis doesn't seem rightjavascriptPull requests that update javascript codequestionFurther information is requestedrustPull requests that update Rust codewontfixThis will not be worked on

Projects

Status
Done
Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions