Comments (13)
but that would mean not capitalising on the added optimization that happens when using fork, as mentioned here.
That is, as always with Stack Overflow answers, incorrect. .fork
is just .spawn
with an IPC channel. You can easily do that with .spawn
too, by specifying it in the stdio
option.
We should definitely add .fork()
here though, as it's handy. I was thinking about it initially, but wanted to explore ways of making .fork()
better and never got to it.
Pull request welcome :)
from execa.
If anyone wants to take on this, see #108 for context and previous work.
from execa.
@IssueHunt has funded $60.00 to this issue.
- Submit pull request via IssueHunt to receive this reward.
- Want to contribute? Chip in to this issue via IssueHunt.
- Checkout the IssueHunt Issue Explorer to see more funded issues.
- Need help from developers? Add your repository on IssueHunt to raise funds.
from execa.
Just to add to the discussion, I don't think there is any "added optimization" with fork()
. If you check the Node.js source code, fork()
only performs some normalization logic then calls spawn()
. The extra logic introduced by fork()
is:
- use
process.execPath
(i.e.node
) as the main binary. I.e.fork('file.js')
becomesspawn('node', ['file.js'])
.process.execPath
can be modified with theexecPath
option. - use
process.execArgv
(i.e.node
CLI arguments). I.e. ifnode
was fired with--no-warnings
,fork('file.js')
becomesspawn('node', ['--no-warnings', 'file.js'])
.process.execArgv
can be modified with theexecArgv
option. - add a
silent
option which is the same as usingstdio: 'pipe'
. - always use
shell: false
option.
So there are no optimizations. However this is convenient for two reasons:
- it's shorter because
node
does not need to passed as argument - it re-uses the current
node
path (if severalnode
binaries are installed) and CLI flags.
from execa.
@ehmicky Yes, it's mostly for convenience, but also:
The returned ChildProcess will have an additional communication channel built-in that allows messages to be passed back and forth between the parent and child.
from execa.
Oh yes you're right.
This could be seen as a convenience as well since this can be achieved with spawn()
by adding ipc
to the stdio
option, e.g. stdio: ['inherit', 'inherit', 'inherit', 'ipc']
(which is what actually fork()
does under the hood).
Also to my above points, we should add that fork()
defaults stdio
to inherit
(with the additional ipc
) whereas spawn()
defaults it to pipe
.
from execa.
If anyone wants to take on this, see #108 for context and previous work.
@GMartigny @ehmicky I think you missed this. fork()
is not really a good name, as fork
is already a different thing in Unix: https://en.wikipedia.org/wiki/Fork_(system_call) The Node.js name is very unfortunate, since Node.js doesn't actually "fork" in the Unix sense.
from execa.
I agree that fork()
is a bad name, because it does not map to Unix forks.
I think we should either:
- try to mimic the Node.js behavior and keep the
fork()
name. - allow ourselves to deviate from the Node.js behavior and use a different name like
execa.node()
orexeca.spawnNode()
.
Some things where we might consider deviating:
a) silent
option defaulting to true
instead of false
b) not offer any silent
option at all? This option is not very useful, users can just use stdio
-related options.
c) do not push ipc
to stdio
. It's very possible many users won't use that channel, so setting it up by default is not needed, and probably not cheap. The ones that do want it can specify it in stdio
. Also half of the code in the current PR is related to this. However as @sindresorhus points it out in #108, if we don't do that, there might not be a need for this extra method at all, so we might still want to do it.
What do you think?
from execa.
allow ourselves to deviate from the Node.js behavior and use a different name like execa.node() or execa.spawnNode().
I think we should yes. Not sure which I like the most of execa.node()
and execa.spawnNode()
though.
b) not offer any silent option at all? This option is not very useful, users can just use stdio-related options.
I agree. We don't need it. It should just default to 'pipe'
like normal.
c) do not push ipc to stdio. It's very possible many users won't use that channel, so setting it up by default is not needed, and probably not cheap.
I doubt it has any real performance impact.
from execa.
Alright, so the consequences would be:
- rename
fork()
tonode()
orspawnNode()
- do not add any
silent
option. Thestdio
options should default topipe
(like normalexeca()
)
@GMartigny what do you think?
from execa.
Either .node
or .spawnNode
imply you can only use node as sub process. Should we get rid of the execPath
option as well?
We can (and certainly should) keep execArgv
to customize the sub process args.
from execa.
Should we get rid of the execPath option as well?
No, it's meant to be able to specify which Node.js executable you want. I already commented about clarifying the option description in your PR.
from execa.
@sindresorhus has rewarded $54.00 to @GMartigny. See it on IssueHunt
- 💰 Total deposit: $60.00
- 🎉 Repository reward(0%): $0.00
- 🔧 Service fee(10%): $6.00
from execa.
Related Issues (20)
- Not able to inject environment variables HOT 3
- Node.js engine version in package.json is not up-to-date HOT 6
- Document CLI utilities
- Subprocess is considered as failed exit when using `process.kill` on windows only HOT 6
- Graceful termination HOT 1
- Document idiomatic ternary interpolation pattern? HOT 2
- TypeError: The "eventTargets" argument must be an instance of EventEmitter or EventTarget. Received an instance of AbortSignal HOT 7
- Feature request: Possibility to use a custom verbose log format? HOT 5
- stdout/stderr with 'inherit' + transform should not capture output HOT 2
- Unable to extend env when `ProcessEnv` has been manipulated HOT 7
- Typescript: Verbose option type mismatch? HOT 2
- Memory Leak of pipe HOT 3
- `parseCommandString()` splits at whitespace inside quotes HOT 3
- Timeout / cancel stuck process HOT 4
- The command cannot be executed HOT 1
- Intl needed for v. 9 HOT 10
- Error: Premature close HOT 23
- Small package alternative to Execa HOT 9
- Add a link to `nano-spawn`
- How to get both live and programmatic output? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from execa.