feat(cli): support reading JavaScript from piped stdin#4734
feat(cli): support reading JavaScript from piped stdin#4734Nakshatra480 wants to merge 10 commits intoboa-dev:mainfrom
Conversation
Test262 conformance changes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4734 +/- ##
==========================================
+ Coverage 47.24% 57.05% +9.80%
==========================================
Files 476 552 +76
Lines 46892 60575 +13683
==========================================
+ Hits 22154 34559 +12405
- Misses 24738 26016 +1278 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Detect when stdin is not a terminal and read the piped input as a script instead of launching the interactive REPL. This allows common Unix workflows such as: echo 'console.log(1 + 2)' | boa cat script.js | boa boa < script.js The REPL is still launched as usual when stdin is a terminal.
f9b2cec to
9d3cdc7
Compare
|
@nekevss i have implemented the feature that i discussed in the community channel, can you review this PR. |
|
Hey @nekevss @jedel1043 just following up here 🙂 These changes makes boa run JavaScript piped to stdin (for example echo '1+1' | boa or boa < script.js) instead of launching the REPL. It detects non-terminal stdin with std::io::IsTerminal (after the existing file and -e checks), reads the piped input and evaluates it as a script, REPL stays the same when stdin is a terminal. Would really appreciate a review. I’m happy to make any tweaks. |
…erving REPL flow with clean early returns
nekevss
left a comment
There was a problem hiding this comment.
Super cool addition! I actually really like it.
Can you add some examples of this functionality to the README.md for boa_cli so that this functionality is displayed somewhere.
Summary
This PR adds support for reading JavaScript from piped stdin in the CLI.
Currently, when no file or
-eexpression is provided, Boa always drops into the interactive REPL — even if stdin is being piped from another command. This means common workflows like these don't work:Changes
Added a check using
std::io::IsTerminalin main() to detect when stdin is not a terminal. When piped input is detected, the CLI reads the full input and evaluates it as a script instead of launching the REPL. The normal interactive REPL behavior is completely unchanged.How it works
The detection happens after the existing file and
-echecks, so the priority order is:-eexpression → evaluate expressionTesting