thespyder / rescript-nodejs Goto Github PK
View Code? Open in Web Editor NEWNode bindings for ReScript
License: MIT License
Node bindings for ReScript
License: MIT License
How to use childprocess.send and process.on("message")?
main
const child = fork('xxx')
child.send("hi")
child
process.on("message', () => {})
According to Nodejs Document: lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to
,The signatures should be same, But actually it is string => Js.Promise.t<Stats.t> = "lstat"
for lstat and FileHandle.t => Js.Promise.t<Stats.t> = "stat"
for stat
Hi there,
I just started learning ReScript and I would like to use it for a NodeJS application. I'm trying to port this piece of NodeJS code to ReScript using rescript-nodejs
but I can't find a way to use Readline
module:
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: fs.createReadStream('sample.txt'),
crlfDelay: Infinity
});
rl.on('line', (line) => {
console.log(`Line from file: ${line}`);
});
I couldn't find any documentation on Readline
module. Can you give me some hints? I just want to read a text file line by line.
If this is not the right place, where should I ask this kind of question?
Thanks.
rescript: [27/118] src/Http2.ast
FAILED: src/Http2.ast
We've found a bug for you!
/Users/dsiu/code/playground/rescript-snippets/node_modules/rescript-nodejs/src/Http2.res:3:1-11:24
1 │ type settingsObject
2 │
3 │ external settingsObject: (
4 │ ~headerTableSize: int=?,
. │ ...
10 │ ~enableConnectProtocol: bool=?,
11 │ ) => settingsObject = ""
12 │
13 │ module Http2Stream = {
Not a valid global name
First, thank you for taking the time to make these bindings. They are extremely useful.
I see that push
is defined with unit
return type. It should have bool
return type. The return value is needed for back-pressure.
The biggest issue I had with uncurried was a compiler bug: rescript-lang/rescript-compiler#6517. This hasn't been released yet but I've confirmed it with a local compiler build.
However there is a limitation that doesn't seem like it can be fixed: rescript-lang/rescript-compiler#6531
The solution is just to offer multi-arg function types in the Event
module.
Lines 24 to 25 in 83e9eba
I get the following error after newly adding this package to a new project:
> [email protected] build /home/jasoons/Documents/code/envio/envio-operator
> rescript build
Dependency on @ryyppy/rescript-promise
rescript: [5/5] src/Promise.cmj
rescript: [7/7] install.stamp
Dependency on rescript-nodejs
rescript: [58/118] src/Module-NodeJs.cmj
FAILED: src/Module-NodeJs.cmj
We've found a bug for you!
/home/jasoons/Documents/code/envio/envio-operator/node_modules/.pnpm/[email protected]/node_modules/rescript-nodejs/src/Module.res:1:9-19
1 │ include Node_module
2 │
The module or file Node_module can't be found.
- If it's a third-party dependency:
- Did you list it in bsconfig.json?
- Did you run `rescript build` instead of `rescript build -with-deps`
(latter builds third-parties)?
- Did you include the file's directory in bsconfig.json?
rescript: [79/118] src/Buffer-NodeJs.cmj
FAILED: src/Buffer-NodeJs.cmj
We've found a bug for you!
/home/jasoons/Documents/code/envio/envio-operator/node_modules/.pnpm/[email protected]/node_modules/rescript-nodejs/src/Buffer.res:1:10-20
1 │ type t = Node.buffer
2 │ open Js.TypedArray2
3 │
The module or file Node can't be found.
- If it's a third-party dependency:
- Did you list it in bsconfig.json?
- Did you run `rescript build` instead of `rescript build -with-deps`
(latter builds third-parties)?
- Did you include the file's directory in bsconfig.json?
rescript: [97/118] src/Assert-NodeJs.cmj
FAILED: cannot make progress due to previous errors.
Failure: /home/jasoons/Documents/code/envio/envio-operator/node_modules/.pnpm/[email protected]/node_modules/rescript/linux/ninja.exe
Location: /home/jasoons/Documents/code/envio/envio-operator/node_modules/rescript-nodejs/lib/bs
ELIFECYCLE Command failed with exit code 1.
I'll clone locally and investigate a bit - seems strange - but I also don't know what Node_module
is.
It looks like timers/promises
is the only new API:
https://epnovate.com/blog/whats-new-in-node-v16/
https://nodejs.org/api/timers.html#timers-promises-api
This will be a good chance to release the first of some breaking changes that are long overdue to leverage new ReScript capabilities.
FAILED: src/Module-NodeJs.cmj
We've found a bug for you!
/[[ project path ]]/node_modules/rescript-nodejs/src/Module.res:1:9-19
1 │ include Node_module
2 │
The module or file Node_module can't be found.
- If it's a third-party dependency:
- Did you list it in bsconfig.json?
- Did you run `rescript build` instead of `rescript build -with-deps`
(latter builds third-parties)?
- Did you include the file's directory in bsconfig.json?
rescript: [74/118] src/Buffer-NodeJs.cmj
FAILED: src/Buffer-NodeJs.cmj
We've found a bug for you!
/[[ project path ]]/node_modules/rescript-nodejs/src/Buffer.res:1:10-20
1 │ type t = Node.buffer
2 │ open Js.TypedArray2
3 │
Unless I am not seeing something very obvious, why is everything in Process
module typed (t, ...) => ...
?
Something as seemingly trivial as NodeJs.Process.exit(0)
just wouldn't work.
To support uncurried mode I patched the multi-argument event handler in a test. Turns out it was never actually used, so it triggers a compile failure
rescript-lang/rescript-compiler#6531 (comment)
It needs to be deleted unless someone finds an actual use for this and then I'll figure out how to implement it properly.
I would like to use async/await from the 10.1 version of the compiler.
Can you provide instructions to build it or are you planning on updating the package soon?
Currently, the greatest version is 14.3.0 and the latest version is 14.2.1. Because of this, if a user sets their rescript-nodejs version to "^14.2.1", they will receive the older 14.3.0.
Publishing the current head of main as version 14.3.1 to resolve this issue.
Also, I noticed that the change here isn't backwards-compatible. Publishing the change as 14.3.0 from 14.2.0 violated NPM's semantic versioning convention.
--- a/src/Fs.res
+++ b/src/Fs.res
@@ -248,7 +248,7 @@ external openSyncWith: (string, ~flag: Flag.t=?, ~mode: int=?) => fd = "openSync
@module("node:fs")
external readFileSync: string => Buffer.t = "readFileSync"
@module("node:fs")
-external readFileSyncWith: (string, readFileOptions) => Buffer.t = "readFileSync"
+external readFileSyncWith: (string, readFileOptions) => string = "readFileSync"
@module("node:fs") external existsSync: string => bool = "existsSync"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.