Skip to content

feat(cli): support reading JavaScript from piped stdin#4734

Open
Nakshatra480 wants to merge 10 commits intoboa-dev:mainfrom
Nakshatra480:feature/cli-stdin-pipe
Open

feat(cli): support reading JavaScript from piped stdin#4734
Nakshatra480 wants to merge 10 commits intoboa-dev:mainfrom
Nakshatra480:feature/cli-stdin-pipe

Conversation

@Nakshatra480
Copy link
Contributor

Summary

This PR adds support for reading JavaScript from piped stdin in the CLI.

Currently, when no file or -e expression 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:

echo 'console.log("hello")' | boa
cat script.js | boa
boa < script.js

Changes

Added a check using std::io::IsTerminal in 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 -e checks, so the priority order is:

  1. File arguments → execute files
  2. -e expression → evaluate expression
  3. Piped stdin (not a terminal) → read and evaluate stdin
  4. Otherwise → launch the interactive REPL

Testing

# Simple expression
echo '1 + 2' | boa
# Output: 3

# console.log
echo 'console.log("hello")' | boa
# Output: hello

# Multi-line script
printf 'let x = 10;\nlet y = 20;\nconsole.log(x + y);' | boa
# Output: 30

# File redirection
boa < script.js

@Nakshatra480 Nakshatra480 requested a review from a team as a code owner February 26, 2026 07:09
@Nakshatra480 Nakshatra480 marked this pull request as draft February 26, 2026 07:13
@github-actions
Copy link

github-actions bot commented Feb 26, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,862 52,862 0
Passed 49,505 49,505 0
Ignored 2,261 2,261 0
Failed 1,096 1,096 0
Panics 0 0 0
Conformance 93.65% 93.65% 0.00%

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.05%. Comparing base (6ddc2b4) to head (c0ca9a7).
⚠️ Report is 704 commits behind head on main.

Files with missing lines Patch % Lines
cli/src/main.rs 0.00% 7 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.
@Nakshatra480 Nakshatra480 force-pushed the feature/cli-stdin-pipe branch from f9b2cec to 9d3cdc7 Compare February 26, 2026 08:05
@Nakshatra480 Nakshatra480 marked this pull request as ready for review February 26, 2026 08:06
@Nakshatra480
Copy link
Contributor Author

Nakshatra480 commented Feb 26, 2026

@nekevss i have implemented the feature that i discussed in the community channel, can you review this PR.
Thanks for your time.

@Nakshatra480
Copy link
Contributor Author

Nakshatra480 commented Feb 27, 2026

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.
Thanks for your time

@jedel1043 jedel1043 requested a review from nekevss February 27, 2026 20:37
@jedel1043 jedel1043 added enhancement New feature or request cli Issues and PRs related to the Boa command line interface. labels Feb 27, 2026
Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@jedel1043 jedel1043 requested a review from nekevss February 28, 2026 17:10
@jedel1043 jedel1043 added this to the v1.0.0 milestone Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Issues and PRs related to the Boa command line interface. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants