Skip to content

fix: preserve TTY in dev mode by inlining tsx invocation#1026

Merged
BYK merged 1 commit into
mainfrom
fix/dev-tty-preservation
Jun 2, 2026
Merged

fix: preserve TTY in dev mode by inlining tsx invocation#1026
BYK merged 1 commit into
mainfrom
fix/dev-tty-preservation

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented May 27, 2026

Problem

pnpm run cli init and pnpm run dev init cannot run sentry init interactively because TTY is lost during execution.

Root cause: The cli script was "pnpm tsx src/bin.ts". pnpm tsx is shorthand for pnpm run tsx, which creates a nested pnpm lifecycle spawn (outer pnpm → shell → inner pnpm → shell → tsx). The inner spawn loses TTY inheritance, so process.stdin.isTTY and process.stdout.isTTY are undefined in the final Node process.

This triggers three gates that block interactive mode:

  1. isNonInteractiveContext() in init.ts → requires --yes + --features
  2. isInteractiveTerminal() in factory.ts → forces LoggingUI instead of InkUI
  3. Wizard preamble in wizard-runner.ts → throws WizardError

Fix

Inline tsx --import ./script/require-shim.mjs directly into the cli and dev scripts, eliminating the nested pnpm run tsx lifecycle spawn.

With a single pnpm lifecycle layer, pnpm uses stdio: 'inherit', preserving the terminal's TTY fds.

The tsx script alias remains for the 19+ non-interactive scripts (build, generate, check, bench) where TTY doesn't matter.

Verification

In a real terminal:

pnpm run cli init --dry-run
pnpm run dev init --dry-run

Both should now enter interactive mode (InkUI) instead of erroring about non-interactive context.

Note: Do not use -- before subcommands (e.g. pnpm run cli -- init) — pnpm passes -- through as a literal argument, which breaks subcommand parsing.

@BYK BYK enabled auto-merge (squash) May 27, 2026 08:39
@betegon
Copy link
Copy Markdown
Member

betegon commented May 27, 2026

The verification steps show pnpm run cli -- init --dry-run but the -- actually gets passed through to process.argv, causing commander to fail with Command not found: -- init ....

The working form is without --:

pnpm run cli init --dry-run
pnpm run cli init /path/to/project

-- is only needed when passing flags that pnpm might intercept — but since pnpm passes it through verbatim here, it breaks subcommand parsing.

The `cli` and `dev` scripts used `pnpm tsx src/bin.ts`, which is
shorthand for `pnpm run tsx` — a nested pnpm lifecycle spawn. The inner
spawn loses TTY inheritance, so `process.stdin.isTTY` is undefined and
interactive commands like `sentry init` fall back to non-interactive mode.

Replace `pnpm tsx` with the inlined `tsx --import ./script/require-shim.mjs`
in `cli` and `dev` only. This keeps a single pnpm lifecycle layer that uses
`stdio: 'inherit'`, preserving the terminal's TTY. The `tsx` script alias
remains for the 19+ non-interactive scripts (build, generate, check, bench).
@BYK BYK force-pushed the fix/dev-tty-preservation branch from d06ca98 to 31d6e7b Compare June 2, 2026 13:44
@BYK
Copy link
Copy Markdown
Member Author

BYK commented Jun 2, 2026

Good catch! Updated the PR description to use pnpm run cli init (no --). Thanks!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 4296 uncovered lines.
✅ Project coverage is 82.04%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    82.04%    82.04%        —%
==========================================
  Files          329       329         —
  Lines        23917     23917         —
  Branches     15634     15634         —
==========================================
+ Hits         19620     19621        +1
- Misses        4297      4296        -1
- Partials      1652      1652         —

Generated by Codecov Action

@BYK BYK merged commit aa1ef81 into main Jun 2, 2026
28 checks passed
@BYK BYK deleted the fix/dev-tty-preservation branch June 2, 2026 13:52
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.

2 participants