Skip to content

npm_config_argv reflects first instead of last command in a chain #8905

@aomarks

Description

@aomarks

(This affects yarn 1.x, so I realize this is unlikely to be changed at this point, but I just wanted to note the discrepancy so that we have a place to discuss/reference).

Given a package.json:

{
  "scripts": {
    "first:yarn": "yarn run second --extra",
    "first:npm": "npm run second --extra",
    "second": "echo $npm_config_argv"
  },
}

Then running yarn run first:yarn (with yarn@1.22.19) prints:

{"remain":[],"cooked":["run","first:yarn"],"original":["run","first:yarn"]}

Whereas running npm run first:npm (with npm@6.14.17) prints:

{"remain":[],"cooked":["run","second","--extra"],"original":["run","second","--extra"]}

So, the npm behavior is that npm_config_argv reflects the current script regardless of whether that script was invoked as part of a chain of scripts. But the yarn behavior is that npm_config_argv reflects the first script in the chain. In other words, once npm_config_argv has been set by yarn, it never gets updated, even as different scripts are executed.

I believe that yarn should follow the same behavior as npm.

The context for this issue is https://github.com/google/wireit, which needs to understand which arguments have been passed to an npm or yarn script invocation, for enabling its watch mode and understanding the extra arguments to pass to child processes. If one yarn script invokes another, we therefore lose the ability to understand which arguments have been set for the second script. (wireit issue about this behavior: google/wireit#545)

(This issue does not affect yarn 3.x, because yarn 3.x doesn't set the npm_config_argv argument at all. Instead it passes all arguments after yarn run <script> to the argv of the child, which works fine for our purposes.)

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