Skip to content

feat(cli): read versions from stdin with an explicit dash - #955

Open
AbineshDev01 wants to merge 1 commit into
npm:mainfrom
AbineshDev01:feat/cli-stdin-dash-20261116-c
Open

AbineshDev01 wants to merge 1 commit into
npm:mainfrom
AbineshDev01:feat/cli-stdin-dash-20261116-c

Conversation

@AbineshDev01

Copy link
Copy Markdown

Summary

Add an explicit - operand to read whitespace-separated versions from stdin:

node -v | semver -r '^26.0.0' -
printf '2.0.0\n1.0.0\n' | semver - 3.0.0

Root cause / design

The CLI only collects versions from argv. Automatically consuming non-TTY stdin, as attempted in the closed #161, would make existing spawned callers wait for stdin to close. This follows the maintainer's suggestion there to require - instead.

Changes

  • Opt in to stdin only for a standalone - operand; repeated operands read the stream once, and help still returns immediately.
  • Tokenize UTF-8 input across chunk boundaries and combine it with argument versions. Tokens are version data, never options.
  • Reuse the existing validation/coercion/range/increment/sorting pipeline after EOF, preserving global sorting and failure behavior.
  • Handle read errors with a diagnostic and nonzero exit.
  • Document the explicit operand and update help snapshots.
  • Add child-process regressions for whitespace/CRLF, fragmented tokens, mixed argv/stdin, options, invalid/empty input, read errors, and existing invocations with open stdin.

No dependencies, configuration, library APIs, or Node engine requirements change.

Testing

  • Baseline npm test: all 54 test files passed, 100% statement/branch/function/line coverage.
  • Regression tests failed against the unchanged CLI, then passed with the implementation. The stdin error case was also observed failing without its handler.
  • ./node_modules/.bin/tap --no-coverage test/bin/semver.js: passed.
  • Final npm test on Node v26.13.1: all 54 test files passed with 100% coverage, including posttest ESLint and postlint template-oss checks.
  • Node v10.24.1 (isolated binary): four CLI smoke cases passed (CRLF + mixed argv/stdin sorting, increment, stdin treated as data, empty-input failure).
  • node --check bin/semver.js: passed.
  • git diff --check: passed.
  • npm pack --dry-run: passed (54 packaged files). There is no compilation/build script.

The full suite was run on Linux/Node 26, not the full supported runtime/platform matrix. Sorted output intentionally waits for EOF.

Issue reference

Closes #149. Supersedes the abandoned stdin approach in #161 with the explicit opt-in suggested in its review.

AI assistance was used for implementation, testing, and an independent code review.

@AbineshDev01
AbineshDev01 requested a review from a team as a code owner November 16, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Allow piping into semver to read version

1 participant