Skip to content

fix(router-cli): pass process.argv.slice(2) to yargs for proper argument parsing#6941

Open
ThePott wants to merge 3 commits intoTanStack:mainfrom
ThePott:main
Open

fix(router-cli): pass process.argv.slice(2) to yargs for proper argument parsing#6941
ThePott wants to merge 3 commits intoTanStack:mainfrom
ThePott:main

Conversation

@ThePott
Copy link

@ThePott ThePott commented Mar 16, 2026

Problem

  • tsr generate and tsr watch commands exit silently without executing

Cause

  • calls yargs() without arguments
  • docs of yargs says to pass argument to either of yargs() or parse()
  • without argument of yargs, the parsed result is { _: [] }

Fix

  • pass process.argv.slice(2) to yargs

Summary by CodeRabbit

  • Bug Fixes

    • CLI argument handling corrected so commands process only user-provided arguments, ensuring reliable execution and help output.
  • New Features

    • CLI now requires at least one command and enforces strict command parsing to surface invalid usage promptly.

@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2026

🦋 Changeset detected

Latest commit: 348c469

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/router-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c995964a-ef66-4847-a02d-4973f3716fba

📥 Commits

Reviewing files that changed from the base of the PR and between 9f1bb40 and 348c469.

📒 Files selected for processing (1)
  • packages/router-cli/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/router-cli/src/index.ts

📝 Walkthrough

Walkthrough

The CLI now initializes yargs with process.argv.slice(2), and yargs is configured with .demandCommand(1) and .strictCommands() to require at least one command and enforce strict parsing.

Changes

Cohort / File(s) Summary
Argument parsing & yargs config
packages/router-cli/src/index.ts
Passes process.argv.slice(2) to yargs, adds .demandCommand(1) and .strictCommands() to require a command and enforce strict command parsing.
Release notes / changeset
.changeset/six-ends-grin.md
Adds a changeset documenting the CLI fix and preparing a patch release for @tanstack/router-cli.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibble argv with careful paws,

I strip the node crumbs without a pause,
Demand a command, tidy the queue,
Hopping through prompts — clean and true. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix in the changeset: passing process.argv.slice(2) to yargs for proper argument parsing in router-cli, which directly addresses the core issue causing silent command exits.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ThePott ThePott marked this pull request as draft March 16, 2026 23:21
@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Bundle Size Benchmarks

  • Commit: 3bc18d462345
  • Measured at: 2026-03-17T13:19:30.611Z
  • Baseline source: history:d6371529b5ab
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Raw Brotli Trend
react-router.minimal 87.61 KiB 0 B (0.00%) 276.07 KiB 76.12 KiB ▁▁▁▁▁▁▁▁███
react-router.full 90.65 KiB 0 B (0.00%) 286.28 KiB 78.68 KiB ▁▁▁▁▁▁▁▁███
solid-router.minimal 37.14 KiB 0 B (0.00%) 111.38 KiB 33.29 KiB ▁▁▁▁▁▁▁▁███
solid-router.full 41.36 KiB 0 B (0.00%) 124.18 KiB 37.12 KiB ▁▁▁▁▁▁▁▁███
vue-router.minimal 52.99 KiB 0 B (0.00%) 151.41 KiB 47.65 KiB ▁▁▁▁▁▁▁▁███
vue-router.full 57.69 KiB 0 B (0.00%) 166.34 KiB 51.60 KiB ▁▁▁▁▁▁▁▁███
react-start.minimal 101.99 KiB 0 B (0.00%) 324.08 KiB 88.20 KiB ▁▁▁▁▁▁▁▁███
react-start.full 105.33 KiB 0 B (0.00%) 333.89 KiB 91.02 KiB ▁▁▁▁▁▁▁▁███
solid-start.minimal 51.24 KiB 0 B (0.00%) 157.82 KiB 45.28 KiB ▁▁▁▁▁▁▁▁███
solid-start.full 56.53 KiB 0 B (0.00%) 173.32 KiB 49.72 KiB ▁▁▁▁▁▁▁▁███

Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

@ThePott ThePott marked this pull request as ready for review March 16, 2026 23:35
@jmalmo
Copy link

jmalmo commented Mar 17, 2026

Hit this exact issue in CI yesterday. Our tsr generate was exiting 0 but producing no output, which silently broke our typecheck step (routeTree.gen.ts is gitignored so CI has to generate it fresh). Took a while to figure out because the exit code was 0 and there was no error output at all.

We pinned to @tanstack/router-cli@1.164.0 as a workaround, which confirmed the regression started in the 1.166.9 range.

The process.argv.slice(2) fix looks correct. One suggestion: it might be worth adding demandCommand(1) and strictCommands() to the yargs chain as well. That way if someone runs tsr with no subcommand or a typo, they get a clear error instead of a silent exit. Would have saved us a couple hours of debugging.

 yargs(process.argv.slice(2))
   .scriptName('tsr')
   .usage('$0 <cmd> [args]')
+  .demandCommand(1)
+  .strictCommands()
   .command('generate', ...)
   .command('watch', ...)
   .help().argv

watch(process.cwd())
},
)
.help().argv
Copy link

Choose a reason for hiding this comment

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

Suggested change
.demandCommand(1)
.strictCommands()
.help().argv

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the kind guidance! I'll update yargs chain and commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants