Skip to content

feat: Update setup Nu for future versions of Nu - #157

Merged
hustcer merged 3 commits into
mainfrom
develop
Jul 15, 2025
Merged

feat: Update setup Nu for future versions of Nu#157
hustcer merged 3 commits into
mainfrom
develop

Conversation

@hustcer

@hustcer hustcer commented Jul 15, 2025

Copy link
Copy Markdown
Owner

feat: Update setup Nu for future versions of Nu

Summary by CodeRabbit

  • Refactor

    • Updated the method for determining the Nu executable directory across workflows, documentation, and scripts for improved consistency.
    • Replaced plugin filtering logic with a more explicit approach, maintaining the same matching behavior.
    • Removed an unused script for setting up module directories.
  • Documentation

    • Updated workflow command examples in README files to reflect the new method for locating the Nu executable.

@coderabbitai

coderabbitai Bot commented Jul 15, 2025

Copy link
Copy Markdown

Walkthrough

The updates replace all usages of shell-based methods for locating the Nu executable's directory (using which nu) with direct references to the $nu.current-exe variable in workflows, scripts, documentation, and source code. Additionally, plugin filtering logic is refactored from filter to reduce in relevant scripts, and an obsolete Nu shell script is removed.

Changes

File(s) Change Summary
.github/workflows/basic.yaml, build.yaml, full-matrix.yaml, latest-matrix.yaml, main-matrix.yaml, release-matrix.yaml, use-nightly.yaml Updated workflow steps to use `$nu.current-exe
Justfile Changed NU_DIR variable assignment to use parent_directory($nu.current-exe) instead of parent_directory((which nu).path.0).
README.md, README.zh-CN.md Updated example commands to use `$nu.current-exe
nu/prepare.nu Deleted script that configured module directory paths for the Nu environment.
nu/register-plugins.nu, src/plugins.ts Replaced which nu logic with $nu.current-exe; refactored plugin filtering from filter to explicit reduce.

Sequence Diagram(s)

sequenceDiagram
    participant Workflow/Script
    participant NuShell

    Workflow/Script->>NuShell: Request $nu.current-exe
    NuShell-->>Workflow/Script: Return path to current Nu executable
    Workflow/Script->>NuShell: Use path dirname to locate directory
    Workflow/Script->>NuShell: List directory contents or register plugins
Loading
sequenceDiagram
    participant Script
    participant Plugins List

    Script->>Plugins List: Iterate plugins with reduce
    Plugins List-->>Script: For each plugin, check if enabled
    Script->>Plugins List: Accumulate matching plugins
    Script-->>Script: Use accumulated plugin list
Loading

Poem

A hop and a skip, the code’s now anew,
No more “which nu”—just $nu.current-exe will do!
Plugins sorted with care, by reduce not by filter,
Old scripts retired, the workflows won’t falter.
The rabbit applauds with a wiggle and cheer—
Cleaner, simpler, and ready this year!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hustcer
hustcer requested a review from Copilot July 15, 2025 06:38
@github-actions

Copy link
Copy Markdown

Based on the provided code changes, I'll analyze the frontend-related aspects of the GitHub Actions workflows and Nu shell scripts:

Code Analysis

  • Key observations:
    • The changes primarily update path resolution from (which nu).path.0 to $nu.current-exe across multiple workflow files and scripts
    • The register-plugins.nu script has been enhanced with better plugin filtering logic using reduce instead of simple filter
    • The prepare.nu script was removed entirely, suggesting a simplification of the module directory setup process
    • Added more robust handling of plugin names with file extensions (like .exe)

Security Review

  • Vulnerability findings:
    • No direct frontend security vulnerabilities found in these changes
    • The removal of prepare.nu reduces potential attack surface for environment variable manipulation
    • The plugin registration changes improve security by:
      • More explicit plugin filtering
      • Better handling of binary extensions
      • Reduced reliance on external which command

Optimization Suggestions

  • Performance improvements:
    • Using $nu.current-exe is more efficient than which nu as it avoids shell command execution
    • The new plugin filtering with reduce is more performant for large plugin sets
    • Removal of unused prepare.nu script reduces startup overhead
    • Consider adding caching for plugin discovery in future iterations

Overall Quality: 4

The changes show good attention to:

  1. Modern shell scripting practices
  2. Performance optimization
  3. Security hardening
  4. Code maintainability

One point deducted because the changes could benefit from:

  • More comprehensive test coverage for the new plugin filtering logic
  • Documentation updates explaining the rationale for $nu.current-exe usage

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR modernizes Nu setup by switching to the new $nu.current-exe API, refactors plugin filtering to support executables with extensions, and removes an outdated script.

  • Replace which nu lookups with $nu.current-exe for path discovery
  • Refactor plugin filtering from filter to reduce to handle .exe extensions
  • Remove the obsolete nu/prepare.nu script
  • Update documentation and CI workflows to use the new path resolution

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/plugins.ts Use $nu.current-exe and refactor plugin filtering with reduce
nu/register-plugins.nu Mirror path lookup and filtering changes in the registration flow
nu/prepare.nu Entirely removed obsolete setup script
README.md & README.zh-CN.md Update examples to use $nu.current-exe for directory listing
Justfile Update NU_DIR to derive from $nu.current-exe
.github/workflows/*.yaml Adjust CI steps to list directory contents via $nu.current-exe
Comments suppressed due to low confidence (3)

src/plugins.ts:44

  • [nitpick] The comment could be expanded to explain why splitting on '.' is safe for all plugin filenames and how it handles names with multiple dots.
        # "split row . | first" used to handle binary with .exe extension

src/plugins.ts:43

  • The new filtering logic, especially handling .exe extensions, should have dedicated unit tests to verify correct behavior across different plugin name patterns.
      $allPlugins | reduce -f [] {|it, acc|

Comment thread src/plugins.ts
Comment on lines +43 to +50
$allPlugins | reduce -f [] {|it, acc|
# "split row . | first" used to handle binary with .exe extension
if $enablePlugins =~ ($it.name | path basename | split row . | first) {
$acc | append $it
} else {
$acc
}
}

Copilot AI Jul 15, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The reduce-based plugin filtering logic is duplicated in both plugins.ts and register-plugins.nu; consider extracting this into a shared helper to avoid duplication and improve maintainability.

Suggested change
$allPlugins | reduce -f [] {|it, acc|
# "split row . | first" used to handle binary with .exe extension
if $enablePlugins =~ ($it.name | path basename | split row . | first) {
$acc | append $it
} else {
$acc
}
}
filterPlugins($allPlugins, $enablePlugins)

Copilot uses AI. Check for mistakes.
Comment thread nu/register-plugins.nu
$allPlugins
} else {
$allPlugins | filter {|it| $enablePlugins =~ ($it.name | path basename | split row . | first)}
$allPlugins | reduce -f [] {|it, acc|

Copilot AI Jul 15, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Similar plugin filtering logic is duplicated here; consider consolidating this into a single reusable function to reduce code duplication.

Copilot uses AI. Check for mistakes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
.github/workflows/full-matrix.yaml (1)

43-46: Guard $nu.current-exe usage for Nushell < 0.101.0

$nu.current-exe was only introduced in Nushell 0.101.0 (released Dec 24, 2024)1, so referencing it in older versions (e.g. 0.86) will cause the step to fail at runtime.

Suggested fixes:

  • Restrict the test matrix to Nushell >= 0.101.0.
  • Or provide a fallback for older releases, e.g. use which nu when $nu.current-exe is undefined.

Location:

  • .github/workflows/full-matrix.yaml: lines 43–46
🧹 Nitpick comments (6)
src/plugins.ts (1)

43-50: Consider reverting to the simpler filter approach.

The change from filter to reduce makes the code more verbose without providing additional benefits. The original filter approach was more concise and readable:

-      $allPlugins | reduce -f [] {|it, acc|
-        # "split row . | first" used to handle binary with .exe extension
-        if $enablePlugins =~ ($it.name | path basename | split row . | first) {
-          $acc | append $it
-        } else {
-          $acc
-        }
-      }
+      $allPlugins | filter {|it|
+        # "split row . | first" used to handle binary with .exe extension
+        $enablePlugins =~ ($it.name | path basename | split row . | first)
+      }
README.zh-CN.md (1)

51-52: Great simplification, but keep examples consistent.

Switching from ((which nu).path.0 | path dirname) to ($nu.current-exe | path dirname) removes the array‐indexing hack – nice.
However, earlier in the same README we still print the path with (which nu). Consider updating the remaining occurrences so newcomers don’t wonder why two different idioms are used.

-    print $'Nu path:(which nu)(char nl)'
+    print $'Nu path:($nu.current-exe)(char nl)'
.github/workflows/basic.yaml (1)

55-59: Update the matching “Nu path” print for coherence

Now that directory discovery relies on $nu.current-exe, printing the binary path via which nu feels uneven. Unless you purposely want to demo both ways, align them:

-        print $'Nu path:(which nu)(char nl)'
+        print $'Nu path:($nu.current-exe)(char nl)'
README.md (1)

55-56: Keep documentation consistent across languages

Same inconsistency here as in the Chinese README: we switched the ls example but left the “Nu path” line untouched. Recommend updating for uniformity (see diff below).

-    print $'Nu path:(which nu)(char nl)'
+    print $'Nu path:($nu.current-exe)(char nl)'
.github/workflows/main-matrix.yaml (1)

38-41: Same consistency & compatibility notes as above

  1. Consider changing the preceding “Show Nu Binary Path” step to use $nu.current-exe for symmetry.
  2. Confirm $nu.current-exe exists for all versions in this matrix, otherwise gate the dir-listing step with a version check.
-      run: print $'Nu path:(which nu)(char nl)'
+      run: print $'Nu path:($nu.current-exe)(char nl)'
nu/register-plugins.nu (1)

36-43: Consider reverting to the more idiomatic filter approach.

The change from filter to reduce adds unnecessary complexity without functional benefit. The original filter approach would be cleaner and more idiomatic:

-      $allPlugins | reduce -f [] {|it, acc|
-        # "split row . | first" used to handle binary with .exe extension
-        if $enablePlugins =~ ($it.name | path basename | split row . | first) {
-          $acc | append $it
-        } else {
-          $acc
-        }
-      }
+      $allPlugins | filter {|it|
+        # "split row . | first" used to handle binary with .exe extension
+        $enablePlugins =~ ($it.name | path basename | split row . | first)
+      }

The filter approach is more concise, readable, and semantically appropriate for this use case.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e58310e and 80256e0.

⛔ Files ignored due to path filters (1)
  • dist/index.js is excluded by !**/dist/**
📒 Files selected for processing (13)
  • .github/workflows/basic.yaml (2 hunks)
  • .github/workflows/build.yaml (1 hunks)
  • .github/workflows/full-matrix.yaml (1 hunks)
  • .github/workflows/latest-matrix.yaml (1 hunks)
  • .github/workflows/main-matrix.yaml (1 hunks)
  • .github/workflows/release-matrix.yaml (1 hunks)
  • .github/workflows/use-nightly.yaml (1 hunks)
  • Justfile (1 hunks)
  • README.md (1 hunks)
  • README.zh-CN.md (1 hunks)
  • nu/prepare.nu (0 hunks)
  • nu/register-plugins.nu (2 hunks)
  • src/plugins.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • nu/prepare.nu
🔇 Additional comments (10)
src/plugins.ts (2)

24-24: Good improvement: Using internal Nu variable instead of external command.

Replacing which nu with $nu.current-exe is a more reliable approach as it:

  • Eliminates dependency on external shell commands
  • Uses Nu's internal variable which is guaranteed to be available
  • Avoids potential PATH resolution issues

28-28: Consistent debug output update.

The debug output change aligns with the switch to $nu.current-exe, providing consistent information about the executable path.

.github/workflows/release-matrix.yaml (1)

39-39: Consistent improvement: Using Nu's internal executable variable.

The change from (which nu).path.0 | path dirname to $nu.current-exe | path dirname is consistent with the overall refactoring effort and provides better reliability by using Nu's internal variable instead of external shell command lookups.

.github/workflows/latest-matrix.yaml (1)

40-40: Consistent with the refactoring effort.

The change to use $nu.current-exe | path dirname aligns with the project-wide effort to replace external shell command lookups with Nu's internal variables, improving reliability and consistency.

.github/workflows/build.yaml (1)

51-51: Consistent refactoring improvement.

The change maintains consistency with the project-wide refactoring to use Nu's internal $nu.current-exe variable instead of external shell command lookups, which is more reliable and future-proof.

.github/workflows/use-nightly.yaml (1)

51-51: Completes the consistent refactoring across workflow files.

This change aligns with the updates made across all other workflow files, ensuring a unified approach to determining the Nu executable directory using Nu's internal variable instead of external shell commands.

.github/workflows/basic.yaml (1)

24-25: 👍 Cleaner dir-lookup

The switch to $nu.current-exe avoids the brittle which … | get 0. Looks good.

Justfile (1)

31-31: LGTM! Good modernization for future Nu compatibility.

The change from (which nu).path.0 to $nu.current-exe is a solid improvement that:

  • Uses Nu's built-in variable instead of external shell command
  • Improves reliability and future compatibility
  • Aligns with the PR objective to update Nu for future versions
nu/register-plugins.nu (2)

17-17: LGTM! Modernized executable path resolution.

The change from (which nu | get 0.path | path dirname) to $nu.current-exe | path dirname improves future compatibility by using Nu's built-in variable instead of external shell commands.


21-21: LGTM! Consistent debug output update.

The debug output correctly reflects the new approach using $nu.current-exe.

@hustcer
hustcer merged commit f65679f into main Jul 15, 2025
119 checks passed
@github-actions github-actions Bot added this to the v3.20 milestone Jul 15, 2025
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.

2 participants