Skip to content

Commit d36ddaa

Browse files
committed
Handle non-path dirname in the Node $PATH override
This apparently causes issues in Turborepo, but this approach should be more reliable.
1 parent 495d501 commit d36ddaa

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

overrides/path/node

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,39 @@
22
# ^ Note that we use sh, not bash, for alpine compatibility
33
set -e
44

5+
# Find the path to this file:
6+
case "$0" in
7+
*/*)
8+
# If the invocation contained a path, "dirname" is reliable:
9+
SCRIPT_DIR=$(dirname -- "$0")
10+
;;
11+
*)
12+
# If not, we search $PATH:
13+
self_path=$(command -v -- "$0")
14+
if [ -z "$self_path" ]; then
15+
echo "Fatal: Could not find script '$0' in PATH." >&2
16+
exit 1
17+
fi
18+
SCRIPT_DIR=$(dirname -- "$self_path")
19+
;;
20+
esac
21+
522
# Exclude ourselves from PATH, find the real node, then reset PATH
6-
PATH="$(printf '%s\n' "$PATH" | sed "s:$(dirname "$0")\:::g")"
23+
PATH="$(printf '%s\n' "$PATH" | sed "s:${SCRIPT_DIR}\:::g")"
724
# ^ This is made more complicated by sh, since we can't use variable expansion, but this
825
# should be equivalent. We use : as a safe sed delim here, though it is confusing!
926

10-
real_node=`command -v node`
11-
PATH="`dirname "$0"`:$PATH"
27+
real_node=$(command -v -- node)
28+
if [ -z "$real_node" ]; then
29+
echo "Fatal: Could not find the real 'node' executable in the modified PATH." >&2
30+
exit 1
31+
fi
32+
33+
# Reset PATH back to include us again
34+
PATH="$SCRIPT_DIR:$PATH"
1235

13-
PREPEND_PATH=`dirname "$0"`/../js/prepend-node.js
36+
# Define the path to our helper script using the reliable SCRIPT_DIR
37+
PREPEND_PATH="$SCRIPT_DIR/../js/prepend-node.js"
1438

1539
# Call node with the given arguments, prefixed with our extra logic
1640
if command -v winpty >/dev/null 2>&1; then

0 commit comments

Comments
 (0)