diff --git a/overrides/path/node b/overrides/path/node index ee1061ca..a19c5c18 100755 --- a/overrides/path/node +++ b/overrides/path/node @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/overrides/path/node.bat b/overrides/path/node.bat index 54f32247..c3d6ac26 100755 --- a/overrides/path/node.bat +++ b/overrides/path/node.bat @@ -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" %* \ No newline at end of file +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" %* +) \ No newline at end of file