-
Notifications
You must be signed in to change notification settings - Fork 653
feat(node-api): create a node.js wrapper library for the JSON-RPC workspace protocol #3070
Conversation
Deploying with
|
Latest commit: |
1633ef9
|
Status: | ✅ Deploy successful! |
Preview URL: | https://3ffddac4.tools-8rn.pages.dev |
Branch Preview URL: | https://feature-node-api-jsonrpc.tools-8rn.pages.dev |
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance/way to make the Transport
testable? I would like to test the error cases, to make sure it works as expected
@@ -81,6 +81,46 @@ jobs: | |||
command: test | |||
args: --workspace --verbose | |||
|
|||
test-node-api: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the correct place. Although neither the workflow for JS file is the correct place. I mean, we should run these tests when we change Rust files AND JS files.
Maybe we should have a workflow just for this package?
"JavaScript", | ||
"TypeScript", | ||
"format", | ||
"lint", | ||
"toolchain" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: are the keywords appropriate?
npm/backend-jsonrpc/package.json
Outdated
@@ -0,0 +1,28 @@ | |||
{ | |||
"name": "@rometools/backend-jsonrpc", | |||
"version": "0.8.0-next", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably we should start from 0.0.1
? Or 0.0.0
if we don't intend to publish it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version number is the same as the main rome
package and all the cli-*
wrappers, but it gets updated automatically in the generate-packages.mjs
script that runs during releases anyway so I could set it to 0.0.0
as a placeholder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my view it would be useful to add documentation to all public types/methods and to add a small readme to the project as well (which also indicates, that this API is considered internal and may change at any point in time).
await transport.request("initialize", { | ||
capabilities: {}, | ||
client_info: { | ||
name: "@rometools/backend-jsonrpc", | ||
version: "0.8.0-next", | ||
}, | ||
}); | ||
|
||
return wrapTransport(transport); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the transport fails to initialize a connection (or create a socket)? Does it throw any errors and if so which one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating the socket isn't really up to the transport layer (it expects to be provided with an existing Socket
instance on construction), but the createSocket
function will throw an exception is the socket cannot be opened (the socket emits an instance of Error
through the "error"
event), and the remote call to initialize
may also throw an RPC error object if the remote server reports an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense for us to introduce a RomeBackendError
that is thrown in any situation where the backend runs into an error (and we use RomeError
in higher level APIs?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be useful to introduce a custom error class wrapping the RPC error objects since those contain structured informations (they may include a serialized RomeError
for instance), but I'm not sure we can provide much value by wrapping the I/O errors coming from node itself because of an issue with the connection
/* Projects */ | ||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ | ||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ | ||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if we could delete all the setting that we aren't using. It makes it hard to see what our explicit settings are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to keep them because we haven't figure out a correct build process, so if we need some specific property turned on, we have the benefit of the comments. We can clean it once the build process is final
website/playground/build.rs
Outdated
@@ -387,16 +68,10 @@ fn write_protocol() -> (String, Vec<String>) { | |||
// ensure it looks good by running it through the formatter | |||
let formatted = format_node(JsFormatContext::default(), module.syntax()).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
9783183
to
cd00bbd
Compare
Summary
Closes #3048
This PR creates a new
@rometools/backend-jsonrpc
library that implements the Workspace API by wrapping the JSON-RPC protocol exposed by the daemon server. The library is split into a few modules that may be imported independently:command
resolves a file system path to the Rome binarysocket
ensures the daemon process is spawned and opens a node.jsSocket
connection to the RPC channeltransport
wraps an open socket and implements the JSON-RPC protocol as untyped method calls and responsesworkspace
is automatically generated from the JSON schema of the Workspace API, and wraps aTransport
instance with an object implementing typed methods calls to the remote workspaceAt the top level of the library a single
createWorkspace
method calls each of these in sequence, wrapping each layer with the next one and returning aWorkspace
object ready to useTest Plan
I added a small test script that creates creates a workspace instance (using a local build of the binary from the Cargo target directory), executes a few method calls then shuts down