Skip to content

Commit 4524e28

Browse files
committed
feat(volta): unset _VOLTA_TOOL_RECURSION
1 parent bf6862c commit 4524e28

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

examples/volta/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/volta/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "example-volta-project",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"volta": { "node": "23.0.0" }
6+
}

shell-modules/volta.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,31 @@
4949
VOLTA_HOME="${cfg.home}"
5050
export VOLTA_HOME
5151
'';
52+
53+
# When a volta shim runs an npm script, if the environment variable
54+
# _VOLTA_TOOL_RECURSION is not set, it sets it in the script's
55+
# environment, and prepends the directory containing the non-shim tools
56+
# of the pinned version to PATH.
57+
#
58+
# So with a package.json file like this, the command `npm run script`
59+
# will run the shim `npm`, and the actual node version 23.0.0, with the
60+
# output "v23.0.0":
61+
# ```json
62+
# {
63+
# "scripts": { "script": "node --version" },
64+
# "volta": { "node": "23.0.0" }
65+
# }
66+
# ```
67+
#
68+
# However, if the script evaluates this shell again, then the directory
69+
# containing all the shims will be prepended to PATH, prioritizing them
70+
# over the non-shim tools. If the script then runs any of those shims,
71+
# they will not modify PATH, because _VOLTA_TOOL_RECURSION will be set.
72+
# This can happen with scripts that use `direnv exec`, and can cause
73+
# scripts to hang, or to error with `Volta error: <tool> is not
74+
# available`.
75+
#
76+
# To prevent all this, we unset the variable when entering a shell.
77+
env._VOLTA_TOOL_RECURSION = null;
5278
};
5379
}

0 commit comments

Comments
 (0)