feat: JS Wrapper Around The Polywrap CLI#1359
Conversation
…ce in codegen-dir option description
…se (tests for infra, deploy, and awaitResponse failing)
…s passing for infra, codegen, build, deploy, and awaitResponse
Streaming Typings From CLI -> CLI-JS
pileks
left a comment
There was a problem hiding this comment.
All in all, looks amazing! I’d want to see my 2nd comment be addressed, but it’s good either way.
|
This pull request introduces 20 alerts when merging 039b836 into 46446f0 - view on LGTM.com new alerts:
|
|
This pull request introduces 20 alerts when merging 9ada2ce into 46446f0 - view on LGTM.com new alerts:
|
|
Hey @dOrgJelli would it be possible to fix LGTM alerts before merging this? |
|
|
||
| try { | ||
| const stdout = execSync(command, { | ||
| const stdout = execSync(`${command} ${args.join(" ")}`, { |
Check warning
Code scanning / CodeQL
Unsafe shell command constructed from library input
|
|
||
| const childObj = exec( | ||
| command, | ||
| `${command} ${args.join(" ")}`, |
Check warning
Code scanning / CodeQL
Unsafe shell command constructed from library input
|
|
||
| try { | ||
| const stdout = execSync(command, { | ||
| const stdout = execSync(`${command} ${args.join(" ")}`, { |
Check warning
Code scanning / CodeQL
Shell command built from environment values
|
|
||
| const childObj = exec( | ||
| command, | ||
| `${command} ${args.join(" ")}`, |
Check warning
Code scanning / CodeQL
Shell command built from environment values
…updated syntax for listing multiple modules
Niraj-Kamdar
left a comment
There was a problem hiding this comment.
I agree about exposing the functionality of CLI with JS API, but from what I believe most of the tool that provide the API lib in native language exposes the underlying API methods that CLI would run, they doesn't generally wrap the CLI with exec because user can easily do this if they want to by themselves.
|
Hey @Niraj-Kamdar, the reasons for having the JS SDK spawning the CLI as a child process are as follows:
Also the point of this package is to allow users to easily script against the CLI in JS, while maintaining type safety with the CLI's commands & their arguments + options. We've written it in a way that the types flow easily from the command's source files, into the JS SDK, see here: This gives us an easy to use (typed) interface like so: await Commands.build({
manifestFile: "...",
outputDir: "...",
codegen: true
}, {
cwd: "/path/to/project",
env: {
CUSTOM_ENV_VAR: "..."
}
});Given all of this, would you agree this package is useful and implemented well? |
pileks
left a comment
There was a problem hiding this comment.
Other than the comments already listed out, looks good!
The explanation you gave to Niraj helps a lot too.
I'd advise that you reuse that comment to edit the PR description so that we have an immediate reference for this PR (without scrolling through tons of comments).
|
@pileks description updated! Thanks for the recommendation. |
This PR creates a JS SDK that wraps the CLI, allowing developers to more easily script against the
polywrapCLI. This has been previously discussed here: #1343The
@polywrap/cli-jspackage spawns thepolywrapCLI as a child-process. This is done for the following reasons:Moreover, this JS SDK aims to be completely type-safe, and tied to the typings used within the CLI command's themselves. We've written it in a way that the types flow easily from the command's source files, into the JS SDK, see here:
https://github.com/polywrap/toolchain/blob/ece1d33f7af4b9f22b7405fc15ac4d3435667a2c/packages/cli/src/commands/index.ts#L29-L66
And here:
https://github.com/polywrap/toolchain/blob/ece1d33f7af4b9f22b7405fc15ac4d3435667a2c/packages/js/cli/src/commands/index.ts#L30-L54
This gives us an easy to use (typed) interface like so: