fix: keep npm and npx shims working for symlinked tool binaries
Merged
RY
22d ago+43+43+01234567890123456789-2-2-0123456789
Summary
npm and npx were not found after installing nodejs/node through tools. The shims in the tools bin dir were dangling symlinks.
Changes
- Skip the hardlink in
createShimFilewhen the target is itself a symlink, and point the shim at the target's absolute path instead.link(2)does not follow symlinks on Linux, so the old code copied node's relativenpm -> ../lib/node_modules/npm/bin/npm-cli.jslink into the bin dir, where it dangled. - Dangling shims from earlier installs are replaced on the next install.
- Add a test for a symlinked target that also replaces a dangling shim.
Related Issues
Closes #3229
Checklist
- Code follows the project style guidelines
- Self-review of the code has been performed
- Tests have been added or updated as needed
- Documentation has been updated as needed
- Changes have been tested locally
Tested with go test ./internal/tools/....
Summary by cubic
Fixes npm and npx not being found after installing nodejs/node through tools, caused by dangling shims in the bin dir.
Hard-linking a symlinked target copied the relative link (e.g. npm -> ../lib/node_modules/npm/bin/npm-cli.js) into the bin dir, where it dangled. Shims now point at the target's absolute path when the target is a symlink, and dangling shims from earlier installs are replaced on the next install. Added a test covering both behaviors. Closes #3229.
Summary by CodeRabbit
- Bug Fixes
- Fixed command shims for symlinked executable targets. When an executable is reached through a symlink, the shim now uses an appropriate fallback instead of creating a hard link to the symlink itself. This helps prevent dangling shims and ensures the resulting command remains executable and points to the intended target.