node-interop
node-interop copied to clipboard
Implement Process methods from dart:io
Hey, I'm using this library in the context of a firebase cloud function. I'm trying to utilise imagemagik from the cloud function. In JS this would be exec(...) and with dart:io i'd use Process.run(...). I can't find an alternative in node_io?
Thanks
Hi, you are right. I haven't had a chance to implement Process interface from dart:io yet.
There are bindings for Node's child_process module in package:node_interop/child_process.dart though.
I can take a look at this later this week or during the weekend. You are also welcome to submit a pull request if you need this sooner.
ah okay great, I think package:node_interop/child_process.dart should cover my needs! Thanks very much
Hey @pulyaevskiy I'm having difficulty with assigning a listener for ChildProcess events. Don't suppose you can see anything obvious?
final resize = childProcess.spawn('convert', [ ... ]);
resize
..on('error', (error) { ... })
..on('close', (int code, String signal) { ... })
..on('exit', (int code, String signal) { ... });
I'm getting the following error:
TypeError: "listener" argument must be a function
at _addListener (events.js:216:11)
at ChildProcess.addListener (events.js:276:10)
at ch.b8 (/user_code/build/node/functions.dart.js:334:29)
at J.c4 (/user_code/build/node/functions.dart.js:7921:36)
at /user_code/build/node/functions.dart.js:7823:3
at oD.a (/user_code/build/node/functions.dart.js:2372:72)
at oD.$2 (/user_code/build/node/functions.dart.js:2521:23)
at og.$1 (/user_code/build/node/functions.dart.js:2517:30)
at nm.c6 (/user_code/build/node/functions.dart.js:3261:23)
at mH.$0 (/user_code/build/node/functions.dart.js:2844:14)
I've tried using the other EventEmitter methods like once, addListener etc but not having any luck.
Thanks
Hey, yes.
Any function you pass from Dart to JS must be wrapped with allowInterop or allowInteropCaptureThis.
In your example it would be something like:
final resize = childProcess.spawn('convert', [ ... ]);
resize
..on('error', allowInterop((error) { ... }))
..on('close', allowInterop((int code, String signal) { ... }))
..on('exit', allowInterop((int code, String signal) { ... }));
Ahh - I did briefly consider that but I assumed that the library would be handling that.
Having said that I had the child_prcess.dart open and could see what it was doing, clearly not got my head in gear for 2019 yet! :)
Thanks
but I assumed that the library would be handling that.
node_interop package only provides JS interop bindings based on package:js. You can read how bindings work in the docs of that package.
This is why I also created node_io which hides all the complexity of dealing with JS interop by wrapping Node.js APIs with standard dart:io interfaces.
I'll try to find some time for the Process APIs in node_io in the next couple of weeks.