[PR #1037] [MERGED] fix: validate CLI --port / --hostname values, reject missing/flags-as-values #1039

Closed
opened 2026-05-06 13:11:41 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/1037
Author: @NathanDrake2406
Created: 5/3/2026
Status: Merged
Merged: 5/3/2026
Merged by: @james-elicx

Base: mainHead: fix/cli-arg-parsing


📝 Commits (1)

  • dcbf35e fix: validate CLI --port / --hostname values, reject missing/flags-as-values (#1012)

📊 Changes

3 files changed (+399 additions, -41 deletions)

View changed files

packages/vinext/src/cli-args.ts (+147 -0)
📝 packages/vinext/src/cli.ts (+5 -41)
tests/cli-args.test.ts (+247 -0)

📄 Description

Fixes #1012

Summary

The vinext CLI argument parser silently consumed missing values for --port / -p and --hostname / -H flags, causing:

  1. NaN port → random ephemeral bind
  2. Undefined hostname → fallback to localhost
  3. Flag-eating typos where --hostname is consumed as a port value

This change adds validation that throws clear, actionable errors.

What changed

  • Extracted parseArgs to cli-args.ts module for testability
  • Added takeValue() validation rejecting missing values and flags-as-values
  • Added integer validation for --port
  • Moved --precompress env var side effect into buildApp call site
  • 33 unit tests in tests/cli-args.test.ts

Behavior parity

Next.js CLI uses similar validation via next/src/cli/next-dev.ts. Error messages follow the standard flag-requires-a-value convention.

Test plan

33 tests covering: missing value at end of args, flag consumed as value, non-numeric port, long/short forms, =value forms, boolean flags, combined flags, edge cases.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/1037 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 5/3/2026 **Status:** ✅ Merged **Merged:** 5/3/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/cli-arg-parsing` --- ### 📝 Commits (1) - [`dcbf35e`](https://github.com/cloudflare/vinext/commit/dcbf35e5218504ef3bc3c1bc47378a92cb7a1a7f) fix: validate CLI --port / --hostname values, reject missing/flags-as-values (#1012) ### 📊 Changes **3 files changed** (+399 additions, -41 deletions) <details> <summary>View changed files</summary> ➕ `packages/vinext/src/cli-args.ts` (+147 -0) 📝 `packages/vinext/src/cli.ts` (+5 -41) ➕ `tests/cli-args.test.ts` (+247 -0) </details> ### 📄 Description Fixes #1012 ## Summary The vinext CLI argument parser silently consumed missing values for --port / -p and --hostname / -H flags, causing: 1. NaN port → random ephemeral bind 2. Undefined hostname → fallback to localhost 3. Flag-eating typos where --hostname is consumed as a port value This change adds validation that throws clear, actionable errors. ### What changed - Extracted parseArgs to cli-args.ts module for testability - Added takeValue() validation rejecting missing values and flags-as-values - Added integer validation for --port - Moved --precompress env var side effect into buildApp call site - 33 unit tests in tests/cli-args.test.ts ### Behavior parity Next.js CLI uses similar validation via [next/src/cli/next-dev.ts](https://github.com/vercel/next.js/blob/canary/packages/next/src/cli/next-dev.ts). Error messages follow the standard flag-requires-a-value convention. ## Test plan 33 tests covering: missing value at end of args, flag consumed as value, non-numeric port, long/short forms, =value forms, boolean flags, combined flags, edge cases. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:11:41 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#1039
No description provided.