Really nice work! I threw together a quick demo of trying to run an unmodified build of Yarn within Nodebox; it almost works, which would be incredibly useful for writing tutorials for our website! Here are some of my findings:
blockers
-
The http2 module seems missing. It's used by got, one of our dependencies, so we can't disable it.
-
The Brotli functions (in particular zlib.brotliDecompressSync) don't seem supported.
-
Bug: new URL('npm:1.2.3').pathname === '//1.2.3'; the // is extraneous and breaks Yarn
-
Missing worker support (we have a build that can disable it; I need to try without).
-
Bug: The Worker constructor doesn't support the eval parameter.
workarounds
-
The trailing \n added to strings going through console.log(...) seems missing from the shell.stdout stream - I suspect it's because you also forward it to the caller's console.log function.
-
Speaking of which, it'd be good to have a way to disable this automatic forwarding - either as an option, or possibly when detecting that there are listeners bound to the data event?
-
Data written on stdout via process.stdout.write (rather than console.log) don't seem to trigger the shell.stdout callback. I workaround this by doing a process.stdout.write = console.log right before spawning the process.
-
I didn't manage to catch the output from shell.stderr - it seems the callback is never called. Yarn doesn't use stderr so it's not a problem for my use case.
-
It doesn't seem possible at the moment to set environment variables in the shell before spawning the process. It'd be nice if it was natively supported (for example by an env option on both emulator.shell.create() and shell.runCommand()).
-
It seems that even once the process within a shell exits, shell.kill() must be called if we want to run a new command (seems it's just a matter of shell.id not being reset on exit).
nits
-
It'd be nice to have an helper function doing the equivalent of new Promise((resolve) => shell.on(exit, resolve));
-
The iframe parameter from the Nodebox constructor should probably be moved to connect, since it's not needed until this point. This way the instance can be created before we have the ref to the iframe.
Really nice work! I threw together a quick demo of trying to run an unmodified build of Yarn within Nodebox; it almost works, which would be incredibly useful for writing tutorials for our website! Here are some of my findings:
blockers
Thehttp2module seems missing. It's used bygot, one of our dependencies, so we can't disable it.The Brotli functions (in particularzlib.brotliDecompressSync) don't seem supported.Bug:new URL('npm:1.2.3').pathname === '//1.2.3'; the//is extraneous and breaks YarnMissing worker support (we have a build that can disable it; I need to try without).Bug: The
Workerconstructor doesn't support theevalparameter.workarounds
The trailing\nadded to strings going throughconsole.log(...)seems missing from theshell.stdoutstream - I suspect it's because you also forward it to the caller'sconsole.logfunction.Speaking of which, it'd be good to have a way to disable this automatic forwarding - either as an option, or possibly when detecting that there are listeners bound to the
dataevent?Data written on stdout viaprocess.stdout.write(rather thanconsole.log) don't seem to trigger theshell.stdoutcallback. I workaround this by doing aprocess.stdout.write = console.logright before spawning the process.I didn't manage to catch the output fromshell.stderr- it seems the callback is never called. Yarn doesn't use stderr so it's not a problem for my use case.It doesn't seem possible at the moment to set environment variables in the shell before spawning the process. It'd be nice if it was natively supported (for example by anenvoption on bothemulator.shell.create()andshell.runCommand()).It seems that even once the process within a shell exits,
shell.kill()must be called if we want to run a new command (seems it's just a matter ofshell.idnot being reset on exit).nits
It'd be nice to have an helper function doing the equivalent of
new Promise((resolve) => shell.on(exit, resolve));The
iframeparameter from theNodeboxconstructor should probably be moved toconnect, since it's not needed until this point. This way the instance can be created before we have the ref to the iframe.