Skip to content

Fix Windows npx paths containing spaces (#163) - #164

Open
elhoceyne wants to merge 4 commits into
flock-php:mainfrom
elhoceyne:main
Open

elhoceyne wants to merge 4 commits into
flock-php:mainfrom
elhoceyne:main

Conversation

@elhoceyne

@elhoceyne elhoceyne commented Nov 12, 2026 •

Copy link
Copy Markdown

Fixes #163

What and why

On Windows, run npm and npx through the selected Node executable and CLI scripts instead of generated command wrappers. This prevents installation paths containing spaces from being split by cmd.exe.

This change is Windows-only and preserves Flock's bundled Node.js/npm behavior, project version selection, global npm packages, and certificate environment.

How I tested it

  • go test ./internal/node ./internal/cli — passed
  • GOOS=windows GOARCH=amd64 go test -c -o /tmp/flock-cli.test.exe ./internal/cli — passed
  • GOOS=windows GOARCH=amd64 go test -c -o /tmp/flock-node.test.exe ./internal/node — passed
  • git diff --check — passed

Checklist

  • I tested this change
  • I updated the docs in docs/, or no docs change is needed
  • This changes only the daemon or CLI, not the apps
  • This changes the apps, and I made and tested the change on every platform:
    • macOS
    • Windows
    • Linux

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows compatibility when running npm and npx, including installations in paths with spaces and updated npm installations.
    • npm and npx commands now run through Node.js on Windows, with the appropriate command-line scripts and environment settings.
    • When an npm or npx script is unavailable, the error identifies the Node.js version and tool.

@github-actions

Copy link
Copy Markdown

Thanks for the PR, @elhoceyne! Flock takes pull requests only for issues a maintainer has approved, so this one is closed. Edit this pull request's description to reference an approved issue, then save it to reopen automatically. See CONTRIBUTING.md.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The Node fixture lacks bundled npm metadata and breaks Windows CI, while Windows regression coverage is still missing for npm and npx execution from paths containing spaces.

2 open issues
What changed in this PR

Fixes #163 by running npm and npx through Flock’s selected Node executable on Windows, avoiding command-wrapper failures when installation paths contain spaces.

Changes:

  • Passes npm/npx CLI scripts directly to node.exe, retaining existing arguments and environment settings.
  • Adds npx script lookup that prefers the major version’s updated npm package over bundled npm.
  • Adds a test for bundled and updated npx selection.
File Description
internal/​node/​npm.go Adds npx CLI script resolution.
internal/​node/​npm_test.go Tests bundled and updated npx selection.
internal/​cli/​exec.go Routes Windows npm/npx execution through the selected node.exe.

Review effort: Balanced

Comment thread internal/cli/exec.go Resolved
Comment thread internal/cli/exec.go Resolved
@onairmarc
onairmarc self-requested a review November 13, 2026 02:53

@onairmarc onairmarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there are failing tests. also please address copilot findings.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: flock-php/flock
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 346231b
  • Layers: Repository YAML (base), Repository UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d1ff3be9-6f34-49e9-b1fa-17f492bdb672
Commits

Reviewing files that changed from the base of the PR and between 6ef1567 and da0b748.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The change adds lookup for the npx CLI script in global and version-local npm packages. On Windows, resolveTool runs npm and npx through node.exe instead of invoking .cmd wrappers.

Changes: Windows CLI resolution

Layer / File(s) Summary
npx CLI lookup
internal/node/npm.go, internal/node/npm_test.go
Npx checks the major-specific global prefix and then the Node version directory for npx-cli.js. The test checks bundled and updated global npm installations.
Windows npm and npx execution
internal/cli/exec.go, internal/cli/exec_test.go, internal/cli/exec_windows_test.go
On Windows, resolveTool runs npm and npx CLI scripts through node.exe and returns an error when a script is unavailable. The tests cover platform-specific fixtures, paths with spaces, environment entries, and updated npm resolution.

Estimated code review effort: 3 (Moderate) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: lukas-frey

Merge Risk: Minimal · previous review bd21f

The change runs npm and npx on Windows through node.exe and their CLI scripts, so install paths containing spaces no longer break npx. The review found no concrete defect, and the change is Windows-only with non-Windows behavior unchanged. It looks ready to merge.

Security architecture risk: Low · up to bd21f

Launching npm and npx directly through Node fixes the wrapper’s handling of paths with spaces without adding a new privilege or network entry point. The remaining risk is local: an incomplete shared npm installation can block the bundled copy for Windows projects using the same Node major.

Retained concerns

  • Low · reliability · inferred: An incomplete major-global npm package can mask a usable bundled package. The new lookup selects the global package from version metadata alone, so if its requested CLI script is missing, Windows invocations for projects resolving to that major can fail without trying the bundled script. The base resolver selected the bundled wrapper when the global wrapper was absent.
Security review details

Security Blast Radius

  • inferred — The changed launch decision applies to local Windows npm and npx invocations. Projects under the same installation root that resolve to the same Node major can select the same global npm package; the lookup does not select a package from the project directory.

Trust Boundaries and Controls

  • observed — The CLI derives the executable and script paths before passing user arguments to the existing child-process launcher. The initial Node executable is selected from the installation rather than searched for on PATH, and the launcher requests no different credentials.

Hardening Proposals

  • proposed — Consider checking that the requested CLI script exists before preferring the major-global package, so an incomplete global install does not hide an available bundled script. Cover this fallback for both npm and npx.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: fixing Windows npx paths that contain spaces, which matches the Windows-only change to run npm and npx through node.exe and the CLI scripts. It also references issue #…
Description check Passed The description fills in the template's core parts: it links the issue with 'Fixes #163', explains the what and why, lists the test commands run and their results, and completes the checklist for the …
Linked Issues check Passed Issue #163 asks that npx run on Windows when Flock is installed under a path with spaces. At head, internal/cli/exec.go resolveTool handles the node, npm, and npx tools. On Windows, for npm and npx (n…
Out of Scope Changes check Passed All changed areas connect to the issue #163 fix. internal/cli/exec.go changes the Windows npm and npx selection. internal/node/npm.go adds the Npx lookup that this selection requires. internal/cli/exe…
Full details: Title check

Explanation

The title names the main change: fixing Windows npx paths that contain spaces, which matches the Windows-only change to run npm and npx through node.exe and the CLI scripts. It also references issue #163, which the linked objectives describe.

Full details: Description check

Explanation

The description fills in the template's core parts: it links the issue with 'Fixes #163', explains the what and why, lists the test commands run and their results, and completes the checklist for the Windows-only change. The required 'Fixes #' line is present with a value. The macOS and Linux app-platform boxes are unchecked, which is correct because the change touches only the CLI and is Windows-only.

Full details: Linked Issues check

Explanation

Issue #163 asks that npx run on Windows when Flock is installed under a path with spaces. At head, internal/cli/exec.go resolveTool handles the node, npm, and npx tools. On Windows, for npm and npx (not node), it selects the CLI script with node.Npm or the new node.Npx, sets path to binDir/node.exe, and returns argv {node.exe, cli, args...}. This avoids the generated npx.cmd and npm.cmd wrappers that split the path at the space. internal/node/npm.go adds Npx(root, version), which finds npx-cli.js in the same lookup order as Npm (major global prefix first, then the bundled version directory). It returns an empty string when no npm package exists, and resolveTool reports that as an error. The change is limited to Windows. Non-Windows tools keep the existing lookup, and Windows node still runs node.exe. Tests cover the change: internal/cli/exec_windows_test.go adds TestResolveToolRunsWindowsNpmThroughNodeWithSpaces and TestResolveToolRunsWindowsNpxThroughUpdatedNodeWithSpaces, and internal/node/npm_test.go adds TestNpxUsesTheUpdatedOne. The PR reports that the Windows test binaries compile. It does not report running them on Windows. The issue's reproduction involves the bin\npx.exe shim, which still exists. That shim now routes through flk exec, which runs node.exe directly, so the reported failure path is no longer used by exec. This is inferred from code at head, not from a Windows run.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to the issue #163 fix. internal/cli/exec.go changes the Windows npm and npx selection. internal/node/npm.go adds the Npx lookup that this selection requires. internal/cli/exec_test.go changes the Node/Vite TLS fixture to create node.exe and an npm package layout for Windows and other platforms. This supports the existing TLS test after the resolveTool change. The new Windows and npm tests verify the new behavior. The PR description states the change preserves bundled Node/npm behavior, version selection, global packages, and the certificate environment. In the code at head, NpmEnv and the NODE_EXTRA_CA_CERTS setting remain applied before the platform branch. No unrelated feature or refactor was found in the reviewed areas.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: flock-php/flock
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 1cb007d
  • Layers: Repository YAML (base), Repository UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7b530f95-009d-4291-abb9-0c683a918cc4
Commits

Reviewing files that changed from the base of the PR and between 1cb007d and bd21f95.

Files selected for processing: 5

  • internal/cli/exec.go
  • internal/cli/exec_test.go
  • internal/cli/exec_windows_test.go
  • internal/node/npm.go
  • internal/node/npm_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@github-actions

Copy link
Copy Markdown

No description provided.

@github-actions github-actions Bot added the claimed A pull request has claimed this issue label Nov 23, 2026
@elhoceyne elhoceyne closed this Nov 23, 2026
@elhoceyne elhoceyne reopened this Nov 23, 2026
@elhoceyne

Copy link
Copy Markdown
Author

Hi @onairmarc,

I have rebased the PR onto the latest main and addressed all review feedback and Copilot findings:

  1. Windows Node Fixture: Added bundled npm metadata to the Windows Node fixture in internal/cli/exec_test.go.
  2. Regression Tests: Added dedicated regression tests for Windows npm and npx path resolution with spaces in internal/cli/exec_windows_test.go (TestResolveToolRunsWindowsNpmThroughNodeWithSpaces and TestResolveToolRunsWindowsNpxThroughUpdatedNodeWithSpaces).
  3. Core Test Suite: All Go tests, vet checks, and kit tests pass 100% on Windows, macOS, and Linux:
    • Go test (Windows): PASS
    • Go vet (Windows): PASS
    • Go test (macOS & Linux): PASS
    • windows / Windows App (Kit Tests): PASS (187/187)

Note on Windows Tray Build in CI

When testing the full matrix on the windows-2025 runner, Windows App (Tray Build) encountered error CsWinRT1032 in windows/Flock.Tray/ (due to recent .NET SDK / CsWinRT analyzer rules flagging collection expressions [...] targeting IReadOnlyList<string> under TreatWarningsAsErrors).

This is upstream in the C# desktop app and independent of the Go CLI changes in this PR. I kept this PR strictly scoped to Issue #163 and the Go CLI, but I am happy to open a separate PR to resolve the CsWinRT warnings if helpful.

Whenever you have a moment, could you please approve the workflow run on upstream? Thanks!

@onairmarc

Copy link
Copy Markdown
Member

Thanks @elhoceyne! Yeah I noticed that later on. I fixed the issue in #194.

@elhoceyne
elhoceyne requested a balanced review from Copilot November 25, 2026 06:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@elhoceyne
elhoceyne requested a review from onairmarc November 25, 2026 06:48

This branch has not been deployed

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

Labels

claimed A pull request has claimed this issue pr: change requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

npx fails on Windows when Flock is installed in a path containing spaces

4 participants