Repository navigation
Conversation
There was a problem hiding this comment.
This logic could be moved down to https://github.com/timdp/node/blob/0bd9febb52756a8e2069d279703601bc017d5ab0/lib/child_process.js#L335, where the presence of the shell options and the windows check are already done for you.
There was a problem hiding this comment.
I considered that at first, but since the statement can make options.shell become false, that would mean that you'd have to break out of the if afterwards.
|
I'm personally -1 for adding this to core, but as I don't use Windows, I'll defer to @nodejs/platform-windows. |
|
@cjihrig I'm not a huge fan of it myself, but the performance difference is striking. I wish I could think of a more elegant solution. |
0bd9feb to
a75cb44
Compare
On Windows, Node/uv doesn't take PATHEXT into account, making
spawning fail unexpectedly if you don't pass {shell: true}.
However, that option makes spawning roughly twice as slow.
Hence, I'm adding {shell: 'auto'} to guess the need to spawn a
shell from the extension on Windows.
This implies that you can no longer pass 'auto' as the name of a
shell, which breaks backward compatibility. Alternatives include:
- Allowing {shell: 1} and checking if the type is 'number'.
- Introducing a new option such as autoShell.
- Defaulting to 'auto' if shell is undefined.
Sidenote: I'm adding a test but:
- vcbuild test makes my Windows machine freeze. Running the test
directly worked though.
- I didn't test on *NIX yet.
a75cb44 to
3249965
Compare
|
-1 Easily done from userland. |
|
@seishun The |
And it should have been, since what Node.js has now is unportable.
So you agree that it was a bad idea? |
I agree, so I'm trying to fix it.
I mainly think it's insufficient as a solution. Either you make it a hassle-free API that takes care of all the platform-specific nonsense internally, or you expose a bare-bones API and hope that someone comes up with a wrapper. The former makes Node bigger, the latter is cumbersome because in the end, everyone's going to want that wrapper, raising the question why it isn't in the core API to begin with. Hence this PR. |
You can't really translate bash to cmd, so it would only pretend to take care of it (which it kinda does now by using a platform-specific shell).
How does this help the portability problem? |
The core APIs are platform-agnostic, right? I don't see any reason to mirror the process API after bash, cmd, or any other shell, or OS in general.
It frees developers from having to write additional code to handle different executable types, thereby exposing a single API that will always pick the best execution strategy for the given command. Like I mentioned originally, I'd even consider treating |
|
As noted above, this seems easily done in userland. This is a windows-only thing too, right? I mean generally if you are passing stuff to spawn you should probably know what you are doing with it anyways, it's not exactly safe to spawn arbitrary child processes as I'm sure you are aware. |
|
@Fishrock123 Then the |
|
Just a tiny bit of history. The |
|
@timdp ... the criterion as I've come to understand is, "anything that's not currently being done that can be done in userland..." Personally I'm +0 on this, don't really have any major objections but also not seeing it as being critical. FWIW, another alternative for the value to avoid the theoretical Inside child_process: Then in the app: |
|
I'm just not fond of having a magic spawning option that is intended for generated input to be added first-class. (If I understand it's usefulness correctly.) |
|
@bnoordhuis ... given that you were the one engaging on this in the original thread (#6671) I'd love to get your thoughts. |
|
@jasnell If "anything that's not currently being done that can be done in userland" is the unwritten rule, then I'm all for moving it to an npm module. I was going to make the comparison to having to depend on Which, for me, raises the question whether future versions of Node should lose more core stuff in favor of npm. I'm a big fan of micromodules if the core APIs that they get built upon are lean and consistent. But I digress. |
|
@jasnell Personally, I'm -1: it's not strictly necessary and it's a platform-specific hack. Its redeeming feature is that it has a positive impact on spawn times (but only on Windows.) |
|
I'm -1 on this, too, if you are about to type |
|
@timdp ... I think that answers it then. Given the -1's it's not likely that this would make it in. I really do appreciate you taking the time to put the PR together. I know it's can be a bit of a hassle, especially when it doesn't end up landing but the contribution is very welcome and I hope it doesn't discourage you from making future contributions! I'm going to go ahead and close the PR. |
|
@jasnell No problem. I might bug @IndigoUnited to add this to cross-spawn instead though. :-) |
Checklist
Affected core subsystem(s)
child_process
Description of change
Discussed in #6671.
Synopsis: On Windows, Node/uv doesn't take PATHEXT into account, making spawning fail unexpectedly if you don't pass {shell: true}. However, that option makes spawning roughly twice as slow. Hence, I'm adding {shell: 'auto'} to guess the need to spawn a shell from the extension on Windows.
This implies that you can no longer pass 'auto' as the name of a shell, which breaks backward compatibility. Alternatives include:
Sidenote: I'm adding a test but: