(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:
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: https://github.com/google/wireit/issues/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.)
(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
:Then running
yarn run first:yarn
(withyarn@1.22.19
) prints:Whereas running
npm run first:npm
(withnpm@6.14.17
) prints: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 thatnpm_config_argv
reflects the first script in the chain. In other words, oncenpm_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: https://github.com/google/wireit/issues/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 afteryarn run <script>
to the argv of the child, which works fine for our purposes.)