Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions overrides/path/node
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,21 @@ PATH="$SCRIPT_DIR:$PATH"
# Define the path to our helper script using the reliable SCRIPT_DIR
PREPEND_PATH="$SCRIPT_DIR/../js/prepend-node.js"

# Call node with the given arguments, prefixed with our extra logic
if command -v winpty >/dev/null 2>&1; then
winpty "$real_node" -r "$PREPEND_PATH" "$@"
else
"$real_node" -r "$PREPEND_PATH" "$@"
fi
case "$NODE_OPTIONS" in
*"$HTTP_TOOLKIT_OVERRIDE_PATH"*)
# If our config is already inside NODE_OPTIONS, we don't need to do anything:
if command -v winpty >/dev/null 2>&1; then
winpty "$real_node" "$@"
else
"$real_node" "$@"
fi
;;
*)
# Otherwise, we need to inject --require $PREPEND into the node CLI:
if command -v winpty >/dev/null 2>&1; then
winpty "$real_node" --require "$PREPEND_PATH" "$@"
else
"$real_node" --require "$PREPEND_PATH" "$@"
fi
;;
esac
19 changes: 16 additions & 3 deletions overrides/path/node.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ set WRAPPER_FOLDER=%HTTP_TOOLKIT_OVERRIDE_PATH%\path
call set PATH=%%PATH:%WRAPPER_FOLDER%;=%%

REM Get the real node path, store it in %REAL_NODE%
FOR /F "tokens=*" %%g IN ('where node') do (SET REAL_NODE=%%g)
FOR /F "tokens=*" %%g IN ('where node') do (
SET REAL_NODE=%%g
GOTO :Break
)
:Break

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

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