fix(install): skip npm link when the installer runs from the global npm install - #1231
Merged
Conversation
…pm install `egc install` after `npm install -g @egchq/egc` executes the installer from inside the global npm prefix, where npm link is redundant: the egc bin on PATH already points at that tree. With a root-owned global prefix (distro Node installed with sudo) the link step could only fail and print a note telling the person to run commands "from this checkout" when they do not have one (#1218 Linux report, Ubuntu 26.04 with distro Node 22 and npm 9). Both installers now resolve the global package directory (npm root -g) and compare it against their own root before attempting the link: equal means the global install already provides the command, and the step is announced as skipped. Anything else keeps the previous npm link behavior for git checkouts and unpacked tarballs. The comparison resolves symlinks on both sides (pwd -P and Resolve-Path), so nvm/mise-style symlinked prefixes still compare equal. Covered by structural tests on both installers, parity-checked so install.sh and install.ps1 cannot drift. Reported-by: ankit <rathaurankit501@gmail.com> Signed-off-by: Felipe Marzochi <fmarzochi@gmail.com>
…ed (#1231) Signed-off-by: Felipe Marzochi <fmarzochi@gmail.com>
Signed-off-by: Felipe Marzochi <fmarzochi@gmail.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
egc installrun from the globally installed npm package no longer attemptsnpm linkthere: the guard resolves$(npm root -g)/@egchq/egcand compares it with the installer root (symlink-safe on both sides viapwd -P/Resolve-Path); on match it printsegc command already provided by the global npm installinstead of failing with a note about a checkout the user does not havenpm linkplus the best-effort fallback noteinstall-ps1.test.jssoinstall.shandinstall.ps1cannot drift apart on this guardWhy
The v1.1.18 Linux testing round (#1218) reproduced this on Ubuntu 26.04 with distro-packaged Node 22 (root-owned global prefix,
sudo npm install -g): the install succeeds and theegcbin works, but the log ends with a scarynpm link failednote pointing at a nonexistent checkout. The link step only makes sense when the installer runs from a tree that is not the global install itself.Credit
Reported by @rathaur-ankit in #1218 with a precise environment description and screenshot (Ubuntu 26.04 LTS, distro Node 22 with npm 9, zsh, sudo global prefix): his second Linux testing report for EGC, after authoring the German README translation (#972).
Testing
bash -n scripts/install.shpassesnode tests/scripts/install-sh.test.js: 7/7, including the new guard casenode tests/scripts/install-ps1.test.js: 10/10, including the new parity case (PowerShell execution paths skipped on Linux as usual)