Skip to content

feat(cli): prompt to run npm init when package.json is missing#72

Merged
jheddings merged 4 commits intomainfrom
feat/npm-init-prompt
May 8, 2026
Merged

feat(cli): prompt to run npm init when package.json is missing#72
jheddings merged 4 commits intomainfrom
feat/npm-init-prompt

Conversation

@jheddings
Copy link
Copy Markdown
Collaborator

@jheddings jheddings commented May 5, 2026

Summary

  • we init now detects a missing package.json and asks the user if they'd like to run npm init instead of failing immediately
  • If the user accepts, npm init runs interactively and we init continues scaffolding once it completes
  • If the user declines, the command exits cleanly with a short redirect message
  • Adds --yes/-y flag that bypasses the confirmation prompt and passes -y through to npm init for non-interactive use
  • In non-TTY contexts (CI, piped stdin), the prompt declines automatically rather than blocking on a closed stream — pass --yes to opt in
  • Drops shell: true from the npm install/npm init spawn calls to silence Node's DEP0190 deprecation; uses npm.cmd on Windows where the .cmd shim is required

Closes NW-18265
Replaces #71 (closed when branch was renamed)

Test Plan

  • we init in a directory with no package.json — verify prompt appears
  • Accept at the prompt — verify npm init runs interactively, then scaffolding continues
  • Decline at the prompt — verify clean exit with message (no stack trace)
  • we init -y in a directory with no package.json — verify no prompt and npm init -y is used
  • we init with stdin piped from /dev/null — verify clean exit with redirect message (no hang)
  • we init in a directory that already has package.json — verify existing behavior unchanged
  • All unit tests passing (just test)

🤖 Generated with Claude Code

jheddings and others added 4 commits May 5, 2026 13:04
Instead of failing immediately when no package.json is found, the init
command now asks the user if they'd like to run npm init first. If they
accept, npm init runs interactively and we continue scaffolding. If they
decline, the command exits cleanly with a short message.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The flag auto-accepts the npm init confirmation prompt and passes -y
through to npm init itself, making the command suitable for scripts
and CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pairing `shell: true` with an args array triggers Node's DEP0190
deprecation warning because the args aren't escaped. Switch to spawning
the platform-correct npm binary directly (`npm.cmd` on Windows,
`npm` elsewhere) so we don't need shell mode.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Short-circuit promptYesNo to false when stdin is not a TTY, so
  piped/CI invocations without --yes don't hang on a closed stream
- Move the prompt's readline output from stderr to stdout for parity
  with typical CLI prompt conventions
- Make the "without yes" spawn assertion platform-agnostic
- Add a comment at the runNpmInit call site noting npm init is
  responsible for creating package.json before the read below

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jheddings jheddings merged commit ccad5cf into main May 8, 2026
2 checks passed
@jheddings jheddings deleted the feat/npm-init-prompt branch May 8, 2026 17:26
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