Skip to content

fix(nodeenv): link nodejs.exe without mklink - #415

Merged
ekalinin merged 1 commit into
masterfrom
fix/nodejs-exe-link
Sep 26, 2026
Merged

ekalinin merged 1 commit into
masterfrom
fix/nodejs-exe-link

Conversation

@ekalinin

@ekalinin ekalinin commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Closes #303.

Problem

On Windows install_activate created Scripts/nodejs.exe through cmd:

callit(['mklink', shim_nodejs, 'node.exe'], True, True)

That call fails in two ways:

The report is also misleading. callit prints each output line as it reads it and prints the whole buffer again on a nonzero exit, so the single mklink line shows up twice, followed by Error: Failed to create nodejs.exe link at ERROR level. Since #180 the failure is non-fatal and nodeenv exits 0 with a usable env, but the output reads like the run failed.

Fix

mklink is a cmd builtin, which is the only reason a shell was involved. Python does it directly, the way the non-Windows branch already does:

  1. os.symlink('node.exe', shim_nodejs) - works with elevation, and without it when Developer Mode is on.
  2. os.link(Scripts/node.exe, shim_nodejs) - a hard link needs neither.
  3. If both fail, a single logger.warning that says what is lost: nothing, unless something on the system invokes node as nodejs.

No shell means no quoting problem and no doubled output, and the common unprivileged case now gets a working nodejs.exe instead of an error.

Verification

Three tests in tests/test_install_activate.py fake is_WIN, so they run on every platform:

  • test_win_nodejs_symlink_created - a symlink to node.exe in an env path containing a space (skipped on a real Windows host, like the existing symlink test);
  • test_win_nodejs_hardlink_when_symlink_fails - os.symlink raises, the hard link points at the same file;
  • test_win_nodejs_link_failure_is_a_warning - both raise, one warning and no error.

All three fail before the change. The fake_win fixture used to stub callit because of mklink; it now stubs os.symlink, so Scripts/ still holds only the generated scripts.

mklink ran through cmd with an unquoted command line, so env paths with
forward slashes or spaces broke it, and it needs elevation or Developer
Mode. Its output was also printed twice and reported at ERROR level,
although the environment was fine.

Use os.symlink, fall back to a hard link, and only warn if both fail.

Fixes #303
@ekalinin
ekalinin merged commit 1767015 into master Sep 26, 2026
44 checks passed
@ekalinin ekalinin added the bug label Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better report success when nodejs.exe creation fails

1 participant