Repository navigation
fix: exit cleanly on Ctrl+C when npm runs the framework on Windows - #413
Conversation
Node's bundled npm.cmd and npx.cmd keep a batch file running under npm, so Ctrl+C left cf waiting at cmd's "Terminate batch job (Y/N)?" prompt. Run npm's CLI script with Node directly instead. Fixes cloudflare#412
|
Hi @Cherry. Thanks for contributing to During the open beta, we’re being very intentional about the changes we accept so that we can prioritise stability for GA. We’re limiting pull requests to contributions coordinated with the team in advance, so this PR has been automatically closed. We’d still love to hear about your use case, so please make sure it’s captured in a |
|
This pull request's reviews are posted as pull request reviews: see the review of |
commit: |
|
clanker review |
There was a problem hiding this comment.
⚠️ Out of date: this review is of6af1ec92; the pull request is now at61f184ce. Someone with write access can commentclanky review(orclanker reviewor@clanky-the-clanker review) to review the new commits.
💬 Approved with comments — The fix works. Two WARNINGs: on some PATH layouts the resolver can choose a different npm (it skips .exe shims) or a different Node (it falls back to process.execPath) than npm's launcher would. Two smaller notes on environment handling and the probe timeout.
Findings: 2 warnings · 1 info · 1 suggestion (4 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #413.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (2)
### [Code Quality] The PATH scan only looks for `npm.cmd`/`npx.cmd`, so it skips an earlier `npm.exe`/`npx.exe` shim and can run a different npm than before.
- **File:** packages/cli/src/lib/npm-launcher.ts:24
### [Code Quality] When there is no adjacent `node.exe`, the code falls back to `process.execPath` instead of `node` from PATH, so the project can run under a different Node version.
- **File:** packages/cli/src/lib/npm-launcher.ts:35
## INFO (1)
### [Performance] The synchronous `npm-prefix.js` probe has no timeout, so a hung probe would hang `cf dev`/`cf build`.
- **File:** packages/cli/src/lib/npm-launcher.ts:50
## SUGGESTION (1)
### [Code Quality] The resolver reads `process.env`, but the child is started with `options.env`.
- **File:** packages/cli/src/lib/autoconfig.ts:183
📋 Code Quality: ⚠️ 2 warnings · 1 suggestion
The resolver fixes the Ctrl+C hang, but it finds npm and Node differently from npm's launcher and PATH, so it can run a different npm or Node.
Recommendation: 📝 Minor Comments
- [WARNING] The PATH scan only looks for
npm.cmd/npx.cmd, so it skips an earliernpm.exe/npx.exeshim and can run a different npm than before. (packages/cli/src/lib/npm-launcher.ts:24) - [WARNING] When there is no adjacent
node.exe, the code falls back toprocess.execPathinstead ofnodefrom PATH, so the project can run under a different Node version. (packages/cli/src/lib/npm-launcher.ts:35) - [SUGGESTION] The resolver reads
process.env, but the child is started withoptions.env. (packages/cli/src/lib/autoconfig.ts:183)
View full review
- Lookup order (
npm-launcher.ts:22-24): the resolver takes the first PATH entry that containsnpm.cmd/npx.cmd. An earlier nativenpm.exe/npx.exeor shim is skipped, which bypasses version managers that put such shims first. - Node fallback (
npm-launcher.ts:34-35): with no adjacentnode.exe, npm's launcher usesnodefrom PATH. This code uses cf's ownprocess.execPathinstead, both for the CLI and fornpm-prefix.js. - Environment (
autoconfig.ts:183):resolveNpmLauncherreadsprocess.env, but the child is started withoptions.env.
⚡ Performance: 💬 1 info
The npm-prefix.js probe is synchronous and has no timeout.
Recommendation: 💬 Optional Nits
- [INFO] The synchronous
npm-prefix.jsprobe has no timeout, so a hung probe would hangcf dev/cf build. (packages/cli/src/lib/npm-launcher.ts:50)
View full review
globalPrefixScript spawns Node synchronously on every Windows npm/npx delegation. It blocks the event loop and has no timeout.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues. execFileSync takes an argument array, so it runs no shell, and the command name is limited to npm/npx by a strict regex. The PATH lookup does not search the current directory.
📖 AGENTS.md: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
The changeset follows the repository's conventions.
Reviewed commit: 6af1ec92
Resolve npm the way the child process would and only rewrite npm's batch launchers, fall back to node on PATH, and time out the global prefix probe.
Fixes #412
On Windows,
cf dev,cf buildandcf initrunnpm/npxthrough thenpm.cmd/npx.cmdbundled with Node. Those keep a batch file running under npm, so after Ctrl+C cmd sits atTerminate batch job (Y/N)?and cf never exits.runProjectCommandnow resolvesnpm/npxto the CLI script the launcher would run and starts it with Node directly. It follows the launcher's own lookup: thenode.exenext to it, and an npm upgraded into the global prefix vianpm-prefix.js. Anything it doesn't recognise runs as before.pnpm projects still prompt from pnpm's own
node_modules\.binshims, which is outside cf.npxcases to the Windows console Ctrl+C test, using a verbatim copy of npm'snpx.cmd. They hang without this change.