sindresorhus / nano-spawn

Tiny process execution for humans — a better child_process
MIT License
441 stars 6 forks source link

Make `env` option augment by default #11

Closed ehmicky closed 2 months ago

ehmicky commented 2 months ago

When a user sets environment variables, those should be extending the current ones, as opposed to redefining them. Just like the default behavior of Execa (extendEnv: true.

Reasons:

  1. This is what users most likely expect.
  2. This is how shells behave when running EXAMPLE_ENVVAR=value binary arg....
  3. This is how environment variables were designed: child processes inherit from their parent.
  4. When running a binary by its filename (as opposed to its file path), the PATH environment variable is needed. If the env option was to override the current environment variables (including PATH), most users will then get a ENOENT error, which might confuse them. Source: it just happens to me and it took me 30 seconds to realize what was going on.

Also, this can be implemented in very few bytes: {...process.env, ...options.env}.

I am also thinking that we don't need to expose any extendEnv option like Execa, since that's usually not needed, and in the spirit of keeping things small.

Thoughts?

sindresorhus commented 2 months ago

Yeah, let's try without exposing the option first.