-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: child_process.exec(cmd, { additionalEnv }) #14823
Comments
FWIW, in Node.js 8.3.0 we can do:
|
I've thought about this in the past. It seems like an awkward API to me though. I like @vsemozhetbyt's solution moving forward, and |
Ack that object spreads make this more succinct. |
C programmers will disagree with you. This feature request seems like a solution in search of a problem and as to the syntax, I agree with Colin's choice of words: awkward. |
That's sort of my point that (C programmes) != (node programmers). I don't have an elegant solution for syntax. Since the API was designed to mimic the system calls, everything would look awkward 🤷♂️ The most elegant solution would have been to change the semantics of |
🤔 trying to be creative: const aes = child_process.addativeEnvSymbol;
const env = { [aes]: true, NEW_VAR:1 }
child_process.exec(cmd, { env }) |
The spread operator is a pretty good solution for this, imho, but I like the idea of an option to ease the work of merging too. I thought of something like: const env = { /* ... */ };
child_process.exec(cmd, { env, mergeEnvs: true });
The naming might be tricky to get right, since to be descriptive enough it would have to be longer lol Edit: (Happy to PR if this goes forward 😄) |
I feel like this is something that could easily be done in an npm package |
After reading some POSIX design stories, I tend to agree that this should stay as is for |
I think a child_process.exec(cmd, { env: common.envPlus({NEW_VAR:1}) }) would make sense, and would hopefully solve the problem we have in tests, which is that adding something to the existing env isn't exactly intuitive. Whether this is something that the larger community would need is a different question though, and can probably be dealt with separately. |
Would function envPlus(env) {
return Object.assign({}, process.env, env);
} If so, we could probably live without it. |
For |
Check out |
Raised a PR for discussion purposed: #14845 Not 100% sold on having the function, but it's easier to discuss over code. |
Add a helper function to provide an easy way to modify the environment passed to child processes. Fixes: nodejs#14823
Closed for no consensus |
PR-URL: #14845 Fixes: #14823 Refs: #14822 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: nodejs/node#14845 Fixes: nodejs/node#14823 Refs: nodejs/node#14822 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #14845 Fixes: #14823 Refs: #14822 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #14845 Fixes: #14823 Refs: #14822 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #14845 Fixes: #14823 Refs: #14822 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: nodejs#14845 Backport-PR-URL: nodejs#15557 Fixes: nodejs#14823 Refs: nodejs#14822 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #14845 Backport-PR-URL: #15557 Fixes: #14823 Refs: #14822 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #14845 Backport-PR-URL: #15557 Fixes: #14823 Refs: #14822 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
child_process.exec(cmd, { env: Object.assign({}, process.env, {NEW_VAR:1}) })
is a very common pattern. IMHO adding an{ additionalEnv }
option that implements this pattern, will make the API more complete, and less error prone.The text was updated successfully, but these errors were encountered: