-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build(lint): disallow node process api, favor Toolkit ChildProcess api #6113
Conversation
const goPath: string = JSON.parse( | ||
(await ChildProcess.exec('go', ['env', '-json'], { collect: true })).stdout | ||
).GOPATH |
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.
Use a local var is a bit more terse and readable, at the cost of having to claim a name.
But generally, invoking a process almost always should involve checking an exit code (though that's out of scope for this PR), so inlining exec()
or run()
is unusual and likely discouraged. .
const goPath: string = JSON.parse( | |
(await ChildProcess.exec('go', ['env', '-json'], { collect: true })).stdout | |
).GOPATH | |
const r = await ChildProcess.exec('go', ['env', '-json'], { collect: true }) | |
const goPath: string = JSON.parse(r.stdout).GOPATH |
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.
Ideally checking the exit code would be part of some higher-level API provided by ChildProcess right?
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.
Ideally checking the exit code would be part of some higher-level API provided by ChildProcess right?
Failure handling in some way needs to be done by the caller, typically
This is good to have in place. We don't need to bother migrating any of the child_process cases for Q features, since most of those will use Flare. |
Co-authored-by: Justin M. Keyes <jmkeyes@amazon.com>
…aws#6113 ## Problem contributors may use the low-level node `child_process` library, which lacks the instrumentation and robustness of the toolkit `ChildProcess` utility. Example: aws#5925 (comment) ## Solution - add the node `child_process` library as a "banned import" with a message pointing to our `ChildProcess` utility. - Migrate simple cases to use our `ChildProcess`, mark more complex ones as exceptions. ## Future Work - To migrate the existing cases marked as exceptions, we will need to add functionality to our `ChildProcess` api, such as enforcing a `maxBufferSize` on the output. - Additionally, some of the current uses of `child_process` are tied to implementation details in the `child_process` library that make it hard to change without a larger-scale refactor. These cases were marked as exceptions.
Problem
contributors may use the low-level node
child_process
library, which lacks the instrumentation and robustness of the toolkitChildProcess
utility.Example: #5925 (comment)
Solution
child_process
library as a "banned import" with a message pointing to ourChildProcess
utility.ChildProcess
, mark more complex ones as exceptions.Future Work
ChildProcess
api, such as enforcing amaxBufferSize
on the output.child_process
are tied to implementation details in thechild_process
library that make it hard to change without a larger-scale refactor. These cases were marked as exceptions.License: I confirm that my contribution is made under the terms of the Apache 2.0 license.