Skip to content

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

@j-murata

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.

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