Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.merlin
.bsb.lock
npm-debug.log
/lib/bs
/lib/
/node_modules/
bsb
package-lock.json
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ or
yarn add rescript-nodejs
```

Then add rescript-nodejs to `bsconfig.json`:
Then add rescript-nodejs to `rescript.json`:

```
"bs-dependencies": [
"dependencies": [
"rescript-nodejs"
],
```
Expand All @@ -40,7 +40,7 @@ Help all ReScript Node.js apps and libraries to be built faster by reducing the

## Principles

- When available, prefer binding to the promise version of the library instead of the callback version to reduce binding surface. `Js.Promise2` is the new improved API.
- When available, prefer binding to the promise version of the library instead of the callback version to reduce binding surface.
- Use subtyping only where the benefit is substantial. Subtyping is used for various APIs that implement Node Streams, such as HTTP Request and Response, FileSystem streams, Crypto streams, and etc. This provides a single set of functions to manipulate and combine streams across different modules. For example:

### Stream a file into stdout:
Expand All @@ -50,7 +50,7 @@ open NodeJs

Fs.createReadStream("/path")
->Stream.pipe(Process.stdout(Process.process))
->Stream.onError(_ => Js.log("handleError"))
->Stream.onError(_ => Console.log("handleError"))
```

### Echo server:
Expand All @@ -59,7 +59,7 @@ Fs.createReadStream("/path")
open NodeJs

Http.createServer((request, response) => {
request->Stream.onData(data => Js.log(data))
request->Stream.onData(data => Console.log(data))
request->Stream.pipe(response)->ignore
});
```
Expand Down
2 changes: 1 addition & 1 deletion examples/ReadFileByLine.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ let rl = Readline.make({input: Fs.createReadStream("sample.txt"), crlfDelay: inf

rl
->Readline.Interface.on(Event.fromString("line"), line => {
Js.log(`Received: ${line}`)
Stdlib.Console.log(`Received: ${line}`)
})
->ignore
18 changes: 18 additions & 0 deletions examples/ReadFileByLine.res.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions examples/StreamTextToFile.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ let outputPath = Path.relative(~from=Process.cwd(process), ~to_="example__output
let writeStream = Fs.createWriteStream(outputPath)

let logErrorIfExists = maybeError =>
switch Js.Nullable.toOption(maybeError) {
| Some(err) => Js.log2("An error occurred", err)
switch Nullable.toOption(maybeError) {
| Some(err) => Stdlib.Console.log2("An error occurred", err)
| None => ()
}

let () =
writeStream
->Stream.writeWith(
data,
~callback=maybeError => {
logErrorIfExists(maybeError)
Js.log("Finished")
},
(),
)
->Stream.writeWith(data, ~callback=maybeError => {
logErrorIfExists(maybeError)
Stdlib.Console.log("Finished")
})
->ignore
33 changes: 33 additions & 0 deletions examples/StreamTextToFile.res.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions lib/js/examples/ReadFileByLine.bs.js

This file was deleted.

34 changes: 0 additions & 34 deletions lib/js/examples/StreamTextToFile.bs.js

This file was deleted.

33 changes: 0 additions & 33 deletions lib/js/src/BigInt.bs.js

This file was deleted.

105 changes: 0 additions & 105 deletions lib/js/src/Cluster.bs.js

This file was deleted.

46 changes: 0 additions & 46 deletions lib/js/src/Event.bs.js

This file was deleted.

Loading