Skip to content

Commit 06a1a3b

Browse files
authored
Merge pull request #169 from PenguinDevs/remove-shortform-node
Remove redundant -r Node flags
2 parents 38100fc + 74b428e commit 06a1a3b

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

overrides/path/node

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,21 @@ PATH="$SCRIPT_DIR:$PATH"
3636
# Define the path to our helper script using the reliable SCRIPT_DIR
3737
PREPEND_PATH="$SCRIPT_DIR/../js/prepend-node.js"
3838

39-
# Call node with the given arguments, prefixed with our extra logic
40-
if command -v winpty >/dev/null 2>&1; then
41-
winpty "$real_node" -r "$PREPEND_PATH" "$@"
42-
else
43-
"$real_node" -r "$PREPEND_PATH" "$@"
44-
fi
39+
case "$NODE_OPTIONS" in
40+
*"$HTTP_TOOLKIT_OVERRIDE_PATH"*)
41+
# If our config is already inside NODE_OPTIONS, we don't need to do anything:
42+
if command -v winpty >/dev/null 2>&1; then
43+
winpty "$real_node" "$@"
44+
else
45+
"$real_node" "$@"
46+
fi
47+
;;
48+
*)
49+
# Otherwise, we need to inject --require $PREPEND into the node CLI:
50+
if command -v winpty >/dev/null 2>&1; then
51+
winpty "$real_node" --require "$PREPEND_PATH" "$@"
52+
else
53+
"$real_node" --require "$PREPEND_PATH" "$@"
54+
fi
55+
;;
56+
esac

overrides/path/node.bat

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,23 @@ set WRAPPER_FOLDER=%HTTP_TOOLKIT_OVERRIDE_PATH%\path
77
call set PATH=%%PATH:%WRAPPER_FOLDER%;=%%
88

99
REM Get the real node path, store it in %REAL_NODE%
10-
FOR /F "tokens=*" %%g IN ('where node') do (SET REAL_NODE=%%g)
10+
FOR /F "tokens=*" %%g IN ('where node') do (
11+
SET REAL_NODE=%%g
12+
GOTO :Break
13+
)
14+
:Break
1115

1216
REM Reset PATH, so its visible to node & subprocesses
1317
set PATH=%ORIGINALPATH%
1418

15-
REM Start Node for real, with an extra arg to inject our logic
16-
"%REAL_NODE%" -r "%WRAPPER_FOLDER%\..\js\prepend-node.js" %*
19+
REM Check if our config is already inside NODE_OPTIONS, if so then we don't actually
20+
REM need to do anything.
21+
REM NODE_OPTIONS includes forward slash paths even on Windows for some reason, so
22+
REM check for that instead.
23+
set "OVERRIDE_PATH_POSIX=%HTTP_TOOLKIT_OVERRIDE_PATH:\=/%"
24+
echo "%NODE_OPTIONS%" | findstr /C:"%OVERRIDE_PATH_POSIX%" >nul 2>&1
25+
if %errorlevel% equ 0 (
26+
"%REAL_NODE%" %*
27+
) else (
28+
"%REAL_NODE%" --require "%WRAPPER_FOLDER%\..\js\prepend-node.js" %*
29+
)

0 commit comments

Comments
 (0)