rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.7k stars 446 forks source link

Question: Any option to output to STDOUT #392

Closed t9md closed 8 years ago

t9md commented 8 years ago

I'm trying my Atom-editor plugin support "write js compiled output to another editor" so that I can learn OCaml itself and how buclescript compile to JavaScript.

To do this, the best I want is write bsc's output to STDOUT. Is this supported? Trying to -o option with -o - not work. even normal -o hoo.js seem to not work. Next question, can I suppress output of .cmj and .cmi file? I just need js output only for my editor package.

I'm just start learning OCaml itself, so sorry if my question seems stupid, btw I could successfully get output of bsc.

$ ls
my_prog.ml
$ cat my_prog.ml
let () = print_endline "Hello, World!"
$ bsc -I . my_prog.ml
$ ls
my_prog.cmi my_prog.cmj my_prog.js  my_prog.ml
$ node my_prog.js
Hello, World!
$
t9md commented 8 years ago

Here is I'm doing, I could what I wanted, but if STDOUT is supported, I can do more simply.

atom-transformer-bucklescript

bobzhang commented 8 years ago

To do this, the best I want is write bsc's output to STDOUT. Is this supported?

not yet, but it should be easy to add an option -djs, so that bsc -djs -c hello.ml output to STDOUT, but how is it different from bsc -c hello.ml && cat hello.js, for performance issue?

-o is reserved for linker, currently we rely on webpack or google closure as a js bundler, but eventually we want to have our own bundler.

can I suppress output of .cmj and .cmi file?

no, these files are meta data needed for compiling against other ml files, but you can set js output to a separate directory via -js-npm-output-path your_npm_package_name:path/to/js/output

The gif is nice!

t9md commented 8 years ago

Thanks for eraborate explanation. Understood. The reason why STDOUT is not performance, but for easier implementation. If it can write STDOUT I can just write to Atom's buffer directly through node's child_process's stdout callback.