|
2 | 2 | # ^ Note that we use sh, not bash, for alpine compatibility
|
3 | 3 | set -e
|
4 | 4 |
|
| 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 | + |
5 | 22 | # 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")" |
7 | 24 | # ^ This is made more complicated by sh, since we can't use variable expansion, but this
|
8 | 25 | # should be equivalent. We use : as a safe sed delim here, though it is confusing!
|
9 | 26 |
|
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" |
12 | 35 |
|
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" |
14 | 38 |
|
15 | 39 | # Call node with the given arguments, prefixed with our extra logic
|
16 | 40 | if command -v winpty >/dev/null 2>&1; then
|
|
0 commit comments