purescript-node / purescript-node-child-process Goto Github PK
View Code? Open in Web Editor NEWSpawn child processes in PureScript via the Node.js child_process API.
License: MIT License
Spawn child processes in PureScript via the Node.js child_process API.
License: MIT License
Want to know the best way to use this in the browser I heard recently all of purescript changed to es6 fully did this as well?
@joneshf: I just pushed your repository to here - sorry for being impatient.
I just noticed there's no license. Would you be ok with MIT? Is assigning copyright to PureScript ok?
Is there a reason why this library does only has bindings to the async versions of the functions? spawnSync
e.g. is missing. purescript-node-fs
has split them into a Sync
and Async
module, maybe an option for this one too?
I noticed the onSpawn
handler is missing here.
Adding it is straight-forward though we should use EffectFn2
for this:
export function onSpawn(cp) {
return function (cb) {
return function () {
cp.on("spawn", function () {
cb();
});
};
};
}
mkOnClose
currently adds a callback for the "exit"
signal, yet the node documentation clearly states that "close"
βis distinct from the 'exit' event, since multiple processes might share the same stdio streams.β.
My intention was that you would be able to put any kind of Stream with any row of effects into the ShareStream
constructor, which is what led me to write it as it is now:
data StdIOBehaviour = ShareStream (forall r eff. Stream r eff) | [...]
However, pretty much any Stream
you might come across is going to have something in both of these rows, so as far as I can tell, you pretty much have to use unsafeCoerce
to actually use this constructor.
Possible solutions:
newtype StdIOBehaviour = StdIOBehaviour Foreign
and replace the constructors with normal functions. So eg Pipe
would become a normal value pipe :: StdIOBehaviour
, and ShareStream
would become shareStream :: forall r eff. Stream r eff -> StdIOBehaviour
. You lose pattern matching by doing it this way, but it is very simple, and if a user of this library really wanted to do some kind of case analysis, they could use purescript-foreign
.purescript-exists
so that we have something like ShareStream (exists r. exists eff. Stream r eff)
(although of course we can't actually do that). I guess it would have to be something like data StdIOBehaviour = ShareStream (Exists (Exists Stream))
which is a bit weird.AnyStream
type for use with the ShareStream
constructor. So something like this:-- A stream where you don't know whether it's readable or writable,
-- or what the effects associated with reading/writing are.
foreign import data AnyStream :: *
toAnyStream :: forall r eff. Stream r eff -> AnyStream
-- It is the caller's responsibility to check that the `Stream` being returned
-- has the appropriate type.
unsafeFromAnyStream :: forall r eff. AnyStream -> Stream r eff
data StdIOBehaviour = ShareStream AnyStream | [...]
We need to add a better wrapper around ChildProcess and Node Streams
purescript-node-streams-aff
Currently, Node.ChildProcess.spawn
with a non-existent executable will return a ChildProcess
which isn't "real". For example, its pid will be undefined
. This is not ideal.
Currently, you have to handle this by calling onError
. Unfortunately, onError
is used for other failure conditions that do not happen immediately; see the Node docs.
It's not currently clear to me how best to handle this.
See also joneshf/purescript-node-child-process#4
For each of stdin, stdout, and stderr, the stream will be accessible on the child process object if and only if "pipe" was passed as the relevant stdio options. For example, if you did var child = spawn(cmd, args, { stdio: ["pipe", someStream, "pipe"]}
, then you would be able to read child.stderr
and write child.stdin
, but child.stdout
would be null.
Currently, we throw an error if you try to access one of the standard streams after spawning it and passing something other than Pipe
for that stream. It might be nice to work out how to do this in a safer way than just failing at runtime, if possible.
when I try to write custom something like
import Node.Process as Node.Process
noInputOnlyOutput = [Just Ignore, Just (ShareStream Node.Process.stdout), Just Pipe]
I cannot
[1/1 TypesDoNotUnify] webpack/NextjsWebpack/Utils/OnFilesChangedRunCommand.purs:26:53
26 noInputOnlyOutput = [Just Ignore, Just (ShareStream Node.Process.stdout), Just Pipe]
^^^^^^^^^^^^^^^^^^^
Could not match type
( write :: Write
)
with type
r0
it also cannot be rewritten with Exists
data StdIOBehaviour
= Pipe
| Ignore
| ShareStream (Exists Stream)
| ShareFD FS.FileDescriptor
Could not match kind
# Type
with kind
Type
But it's Unit
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.