Skip to content

Volta doesn't pass certain arguments to the globally installed npm package #1852

Description

@j-murata

Reproduction Steps

  1. Create a simple npm package.

    package.json
    {
      "name": "my-pkg",
      "version": "0.0.1",
      "bin": {
        "my-cmd": "./index.mjs"
      },
      "main": "./index.mjs"
    }

    index.mjs
    #!/usr/bin/env node
    console.log(process.argv);

  2. Install this package globally with npm.

    npm i -g ./my-pkg/
  3. Run my-cmd with -h or --help arguments (e.g. my-cmd -h).

    ⇒ Then, Volta outputs the volta run help message.

    $ my-cmd -h
    Run a command with custom Node, npm, pnpm, and/or Yarn versions
    
    Usage: volta.exe run [OPTIONS] <COMMAND> [ARGS]...
    
    Arguments:
      <COMMAND>  The command to run
      [ARGS]...  Arguments to pass to the command
    
    Options:
          --node <version>    Set the custom Node version
          --npm <version>     Set the custom npm version
          --bundled-npm       Forces npm to be the version bundled with Node
          --pnpm <version>    Set the custon pnpm version
          --no-pnpm           Disables pnpm
          --yarn <version>    Set the custom Yarn version
          --no-yarn           Disables Yarn
          --env <NAME=value>  Set an environment variable (can be used multiple times)
          --verbose           Enables verbose diagnostics
          --very-verbose      Enables trace-level diagnostics
          --quiet             Prevents unnecessary output
      -h, --help              Print help

    Note that I have confirmed that the behavior is as expected when my-cmd is run without any arguments.

Consideration

The following script exists in ${LOCALAPPDATA}/Volta/bin/my-cmd.

#!/bin/bash
volta run "$(basename $0)" "$@"

This is my guess, but I suspect that the "$@" arguments that should be passed to the package are being interpreted as volta run arguments.

In fact, after modifying the script as follows (simply adding --), this issue no longer occurs.

@@ -1,2 +1,2 @@
 #!/bin/bash
-volta run "$(basename $0)" "$@"
+volta run -- "$(basename $0)" "$@"

I am not sure if this workaround is universally correct, so I would appreciate your consideration of a safe fix for this issue.

Activity

  1. charlespierce commented on Aug 16, 2024

    @charlespierce
    Contributor

    Hi @j-murata, thanks for the report and for the detailed reproduction steps! This is definitely not expected, so I'll take a look.

    I believe it's a regression in how we handle arguments to volta run, so hopefully it's something we can fix in the code itself. However, I believe your suggested workaround of adding -- to the generated script file would also solve it, so at the very least that should be a solution. If I can find a solution quickly then I'll try to get that into a 2.0.1 release I'm aiming to have today / this weekend. If not then it might have to wait for a follow-up (though not nearly as long as it took to get the 2.0.0 one out 😅)

  2. charlespierce commented on Aug 19, 2024

    @charlespierce
    Contributor

    @j-murata This should be fixed with the newly-released 2.0.1 version of Volta. The PR to add that version to Winget is still processing as of this writing, but once it's merged it should be available.

  3. j-murata commented on Aug 20, 2024

    @j-murata
    Author

    Hi @charlespierce I found Volta v2.0.1 has been shipped on winget.
    And after installation, I also confirmed that the -h flag is passed to the command correctly.

    Thank you for fixing this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions