Skip to content

Commit 5c551b6

Browse files
committed
Don't use --require in node override if NODE_OPTIONS is set correctly
1 parent 3d91d2f commit 5c551b6

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-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" "$@"
42-
else
43-
"$real_node" "$@"
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: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@ 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%" %*
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+
echo "%NODE_OPTIONS%" | findstr /C:"%HTTP_TOOLKIT_OVERRIDE_PATH%" >nul 2>&1
22+
if %errorlevel% equ 0 (
23+
"%REAL_NODE%" %*
24+
) else (
25+
"%REAL_NODE%" --require "%WRAPPER_FOLDER%\..\js\prepend-node.js" %*
26+
)

0 commit comments

Comments
 (0)