Coder Social home page Coder Social logo

purescript-node-child-process's People

Contributors

frigoeu avatar garyb avatar hdgarrood avatar joneshf avatar jordanmartinez avatar justinwoo avatar jyh1 avatar kl0tl avatar kritzcreek avatar nwolverson avatar paf31 avatar profpatsch avatar sigma-andex avatar thomashoneyman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

purescript-node-child-process's Issues

Can we use this with esbuild

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?

No license

@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?

Sync/Async

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?

Add missing FFI: onSpawn handler

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();
      });
    };
  };
}

The ShareStream constructor is wrong

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:

  • Define 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.
  • Keep the ADT and use 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.
  • Keep the ADT and define an opaque 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 | [...]

Handle failed creation better

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.

The standard streams problem

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.

impossible to use ShareStream with purescript-node-process

| ShareStream (forall r. Stream r)

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

https://github.com/purescript-node/purescript-node-process/blob/88871d84a69f47dd2d1d9eccd7cc942be4457d46/src/Node/Process.purs#L125-L126

[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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.