From 98205da008601525a658a106edb3c26199beb2b7 Mon Sep 17 00:00:00 2001 From: xxxigm Date: Sun, 14 Jun 2026 17:21:25 +0700 Subject: [PATCH] test(install): cover bundled-Node npm global prefix redirect Guards that install.sh and node-bootstrap.sh redirect the bundled Node's npm global prefix to the command link dir's parent via a prefix-local global npmrc, so `npm install -g` binaries land on PATH instead of the off-PATH $HERMES_HOME/node/bin. --- tests/test_install_sh_node_global_prefix.py | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/test_install_sh_node_global_prefix.py diff --git a/tests/test_install_sh_node_global_prefix.py b/tests/test_install_sh_node_global_prefix.py new file mode 100644 index 00000000000..f604fc97d77 --- /dev/null +++ b/tests/test_install_sh_node_global_prefix.py @@ -0,0 +1,39 @@ +"""Regression tests for the Hermes-managed Node's npm global prefix. + +When the installer falls back to a bundled Node under ``$HERMES_HOME/node``, +npm's default global prefix is that Node dir, so ``npm install -g `` +drops the package binary in ``$HERMES_HOME/node/bin`` — which is NOT on PATH +(only the command link dir is) and is wiped on every Node upgrade. Users then +report "I can ``npm i -g`` but the package isn't usable on the command line". + +The fix redirects the bundled Node's global prefix to the command link dir's +parent (so global bins land in the already-on-PATH link dir alongside +node/npm/npx), scoped to the bundled Node via its prefix-local global npmrc. +""" + +from pathlib import Path + + +REPO_ROOT = Path(__file__).resolve().parent.parent +INSTALL_SH = REPO_ROOT / "scripts" / "install.sh" +NODE_BOOTSTRAP = REPO_ROOT / "scripts" / "lib" / "node-bootstrap.sh" + + +def test_install_sh_redirects_bundled_npm_global_prefix_to_link_dir() -> None: + text = INSTALL_SH.read_text() + + # The redirect must target the link dir's PARENT so global bins resolve to + # /bin == the command link dir (node/npm/npx live there and it is + # guaranteed on PATH by the installer's PATH setup). + assert 'printf \'prefix=%s\\n\' "$(dirname "$node_link_dir")" > "$HERMES_HOME/node/etc/npmrc"' in text + + # The npmrc lives under the bundled Node so it only affects this npm, not + # the user's other Node installs or their ~/.npmrc. + assert '"$HERMES_HOME/node/etc/npmrc"' in text + + +def test_node_bootstrap_redirects_bundled_npm_global_prefix_to_link_dir() -> None: + text = NODE_BOOTSTRAP.read_text() + + assert 'printf \'prefix=%s\\n\' "$(dirname "$_link_dir")" > "$HERMES_HOME/node/etc/npmrc"' in text + assert '"$HERMES_HOME/node/etc/npmrc"' in text