fix: preserve TTY in dev mode by inlining tsx invocation by BYK · Pull Request #1026 · getsentry/cli · GitHub
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

@BYK BYK commented May 27, 2026

Copy link
Copy Markdown
Member

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

betegon commented May 27, 2026

Copy link
Copy Markdown
Member

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

BYK commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

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

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

@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