diff --git a/.github/workflows/post-dependabot.yml b/.github/workflows/post-dependabot.yml index 1ea8693..3a91911 100644 --- a/.github/workflows/post-dependabot.yml +++ b/.github/workflows/post-dependabot.yml @@ -54,7 +54,7 @@ jobs: else # strip leading slash from directory so it works as a # a path to the workspace flag - echo "workspace=-w ${dependabot_dir#/}" >> $GITHUB_OUTPUT + echo "workspace=--workspace ${dependabot_dir#/}" >> $GITHUB_OUTPUT fi - name: Apply Changes diff --git a/lib/index.js b/lib/index.js index c13890a..3d9dae8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -164,31 +164,43 @@ const writeShim_ = (from, to, prog, args, variables) => { // #!/usr/bin/env pwsh // $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent // - // $ret=0 - // $exe = "" + // $exe="" // if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { // # Fix case when both the Windows and Linux builds of Node // # are installed in the same directory - // $exe = ".exe" + // $exe=".exe" // } - // if (Test-Path "$basedir/node") { - // # Suport pipeline input - // if ($MyInvocation.ExpectingInput) { - // input | & "$basedir/node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args - // } else { - // & "$basedir/node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args - // } - // $ret=$LASTEXITCODE - // } else { - // # Support pipeline input - // if ($MyInvocation.ExpectingInput) { - // $input | & "node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args + // + // $PROGRAM_EXE="node$exe" + // if (Test-Path "$basedir/node$exe") { + // $PROGRAM_EXE="$basedir/node$exe" + // } + // $PROGRAM_FILE="$basedir/node_modules/npm/bin/npm-cli.js" + // + // if ($MyInvocation.ExpectingInput) { # takes pipeline input + // $input | & "$PROGRAM_EXE" "$PROGRAM_FILE" $args + // } elseif (-not $MyInvocation.Line) { # used "-File" argument + // & "$PROGRAM_EXE" "$PROGRAM_FILE" $args + // } else { # used "-Command" argument + // if (($MyInvocation | Get-Member -Name 'Statement') -and $MyInvocation.Statement) { + // $ORIGINAL_COMMAND = $MyInvocation.Statement // } else { - // & "node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args + // $ORIGINAL_COMMAND = ( + // [Management.Automation.InvocationInfo].GetProperty('ScriptPosition', [Reflection.BindingFlags] 'Instance, NonPublic') + // ).GetValue($MyInvocation).Text // } - // $ret=$LASTEXITCODE + // + // $PROGRAM_EXE = $PROGRAM_EXE.Replace("``", "````") + // $PROGRAM_FILE = $PROGRAM_FILE.Replace("``", "````") + // + // $NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($ORIGINAL_COMMAND, [ref] $null, [ref] $null). + // EndBlock.Statements.PipelineElements.CommandElements.Extent.Text -join ' ' + // $PROGRAM_FILE_ARGS = $NO_REDIRECTS_COMMAND.Substring($MyInvocation.InvocationName.Length).Trim() + // + // Invoke-Expression "& `"$PROGRAM_EXE`" `"$PROGRAM_FILE`" $PROGRAM_FILE_ARGS" // } - // exit $ret + // + // exit $LASTEXITCODE let pwsh = '#!/usr/bin/env pwsh\n' + '$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent\n' + '\n' @@ -199,26 +211,57 @@ const writeShim_ = (from, to, prog, args, variables) => { + ' $exe=".exe"\n' + '}\n' if (shLongProg) { - pwsh = pwsh - + '$ret=0\n' - + `if (Test-Path ${pwshLongProg}) {\n` - + ' # Support pipeline input\n' - + ' if ($MyInvocation.ExpectingInput) {\n' - + ` $input | & ${pwshLongProg} ${args} ${shTarget} $args\n` - + ' } else {\n' - + ` & ${pwshLongProg} ${args} ${shTarget} $args\n` - + ' }\n' - + ' $ret=$LASTEXITCODE\n' - + '} else {\n' - + ' # Support pipeline input\n' - + ' if ($MyInvocation.ExpectingInput) {\n' - + ` $input | & ${pwshProg} ${args} ${shTarget} $args\n` - + ' } else {\n' - + ` & ${pwshProg} ${args} ${shTarget} $args\n` - + ' }\n' - + ' $ret=$LASTEXITCODE\n' - + '}\n' - + 'exit $ret\n' + const noProgramExeArgs = args.trim() === '' + if (noProgramExeArgs) { + pwsh = pwsh + + '\n' + + `$PROGRAM_EXE=${pwshProg}\n` + + `if (Test-Path ${pwshLongProg}) {\n` + + ` $PROGRAM_EXE=${pwshLongProg}\n` + + '}\n' + + `$PROGRAM_FILE=${shTarget}\n` + + '\n' + + 'if ($MyInvocation.ExpectingInput) { # takes pipeline input\n' + + ` $input | & "$PROGRAM_EXE" "$PROGRAM_FILE" $args\n` + + `} elseif (-not $MyInvocation.Line) { # used "-File" argument\n` + + ` & "$PROGRAM_EXE" "$PROGRAM_FILE" $args\n` + + '} else { # used "-Command" argument\n' + + " if (($MyInvocation | Get-Member -Name 'Statement') -and $MyInvocation.Statement) {\n" + + ' $ORIGINAL_COMMAND = $MyInvocation.Statement\n' + + ' } else {\n' + + ' $ORIGINAL_COMMAND = (\n' + + ' [Management.Automation.InvocationInfo].GetProperty(\'ScriptPosition\', [Reflection.BindingFlags] \'Instance, NonPublic\')\n' + + ' ).GetValue($MyInvocation).Text\n' + + ' }\n' + + '\n' + + ' $PROGRAM_EXE = $PROGRAM_EXE.Replace("``", "````")\n' + + ' $PROGRAM_FILE = $PROGRAM_FILE.Replace("``", "````")\n' + + '\n' + + ' $NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($ORIGINAL_COMMAND, [ref] $null, [ref] $null).\n' + + ' EndBlock.Statements.PipelineElements.CommandElements.Extent.Text -join \' \'\n' + + ' $PROGRAM_FILE_ARGS = $NO_REDIRECTS_COMMAND.Substring($MyInvocation.InvocationName.Length).Trim()\n' + + '\n' + + ' Invoke-Expression "& `"$PROGRAM_EXE`" `"$PROGRAM_FILE`" $PROGRAM_FILE_ARGS"\n' + + '}\n' + + '\n' + + 'exit $LASTEXITCODE\n' + } else { + pwsh = pwsh + + '\n' + + `$PROGRAM_EXE=${pwshProg}\n` + + `if (Test-Path ${pwshLongProg}) {\n` + + ` $PROGRAM_EXE=${pwshLongProg}\n` + + '}\n' + + '\n' + + '# Support pipeline input\n' + + 'if ($MyInvocation.ExpectingInput) {\n' + + ` $input | & "$PROGRAM_EXE" ${args} ${shTarget} $args\n` + + `} else {\n` + + ` & "$PROGRAM_EXE" ${args} ${shTarget} $args\n` + + '}\n' + + '\n' + + 'exit $LASTEXITCODE\n' + } } else { pwsh = pwsh + '# Support pipeline input\n' diff --git a/tap-snapshots/test-basic.js-TAP.test.js b/tap-snapshots/test-basic.js-TAP.test.js deleted file mode 100644 index 802f3eb..0000000 --- a/tap-snapshots/test-basic.js-TAP.test.js +++ /dev/null @@ -1,487 +0,0 @@ -/* IMPORTANT - * This snapshot file is auto-generated, but designed for humans. - * It should be checked into source control and tracked carefully. - * Re-generate by setting TAP_SNAPSHOT=1 and running tests. - * Make sure to inspect the output below. Do not ignore changes! - */ -'use strict' -exports[`test/basic.js TAP env shebang > cmd 1`] = ` -@ECHO off\\r -GOTO start\\r -:find_dp0\\r -SET dp0=%~dp0\\r -EXIT /b\\r -:start\\r -SETLOCAL\\r -CALL :find_dp0\\r -\\r -IF EXIST "%dp0%\\node.exe" (\\r - SET "_prog=%dp0%\\node.exe"\\r -) ELSE (\\r - SET "_prog=node"\\r - SET PATHEXT=%PATHEXT:;.JS;=;%\\r -)\\r -\\r -endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\from.env" %*\\r - -` - -exports[`test/basic.js TAP env shebang > ps1 1`] = ` -#!/usr/bin/env pwsh -$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent - -$exe="" -if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { - # Fix case when both the Windows and Linux builds of Node - # are installed in the same directory - $exe=".exe" -} -$ret=0 -if (Test-Path "$basedir/node$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/node$exe" "$basedir/from.env" $args - } else { - & "$basedir/node$exe" "$basedir/from.env" $args - } - $ret=$LASTEXITCODE -} else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "node$exe" "$basedir/from.env" $args - } else { - & "node$exe" "$basedir/from.env" $args - } - $ret=$LASTEXITCODE -} -exit $ret - -` - -exports[`test/basic.js TAP env shebang > shell 1`] = ` -#!/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") - -case \`uname\` in - *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; -esac - -if [ -x "$basedir/node" ]; then - exec "$basedir/node" "$basedir/from.env" "$@" -else - exec node "$basedir/from.env" "$@" -fi - -` - -exports[`test/basic.js TAP env shebang with args > cmd 1`] = ` -@ECHO off\\r -GOTO start\\r -:find_dp0\\r -SET dp0=%~dp0\\r -EXIT /b\\r -:start\\r -SETLOCAL\\r -CALL :find_dp0\\r -\\r -IF EXIST "%dp0%\\node.exe" (\\r - SET "_prog=%dp0%\\node.exe"\\r -) ELSE (\\r - SET "_prog=node"\\r - SET PATHEXT=%PATHEXT:;.JS;=;%\\r -)\\r -\\r -endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" --expose_gc "%dp0%\\from.env.args" %*\\r - -` - -exports[`test/basic.js TAP env shebang with args > ps1 1`] = ` -#!/usr/bin/env pwsh -$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent - -$exe="" -if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { - # Fix case when both the Windows and Linux builds of Node - # are installed in the same directory - $exe=".exe" -} -$ret=0 -if (Test-Path "$basedir/node$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/node$exe" --expose_gc "$basedir/from.env.args" $args - } else { - & "$basedir/node$exe" --expose_gc "$basedir/from.env.args" $args - } - $ret=$LASTEXITCODE -} else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "node$exe" --expose_gc "$basedir/from.env.args" $args - } else { - & "node$exe" --expose_gc "$basedir/from.env.args" $args - } - $ret=$LASTEXITCODE -} -exit $ret - -` - -exports[`test/basic.js TAP env shebang with args > shell 1`] = ` -#!/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") - -case \`uname\` in - *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; -esac - -if [ -x "$basedir/node" ]; then - exec "$basedir/node" --expose_gc "$basedir/from.env.args" "$@" -else - exec node --expose_gc "$basedir/from.env.args" "$@" -fi - -` - -exports[`test/basic.js TAP env shebang with variables > cmd 1`] = ` -@ECHO off\\r -GOTO start\\r -:find_dp0\\r -SET dp0=%~dp0\\r -EXIT /b\\r -:start\\r -SETLOCAL\\r -CALL :find_dp0\\r -@SET NODE_PATH=./lib:%NODE_PATH%\\r -\\r -IF EXIST "%dp0%\\node.exe" (\\r - SET "_prog=%dp0%\\node.exe"\\r -) ELSE (\\r - SET "_prog=node"\\r - SET PATHEXT=%PATHEXT:;.JS;=;%\\r -)\\r -\\r -endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\from.env.variables" %*\\r - -` - -exports[`test/basic.js TAP env shebang with variables > ps1 1`] = ` -#!/usr/bin/env pwsh -$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent - -$exe="" -if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { - # Fix case when both the Windows and Linux builds of Node - # are installed in the same directory - $exe=".exe" -} -$ret=0 -if (Test-Path "$basedir/node$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/node$exe" "$basedir/from.env.variables" $args - } else { - & "$basedir/node$exe" "$basedir/from.env.variables" $args - } - $ret=$LASTEXITCODE -} else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "node$exe" "$basedir/from.env.variables" $args - } else { - & "node$exe" "$basedir/from.env.variables" $args - } - $ret=$LASTEXITCODE -} -exit $ret - -` - -exports[`test/basic.js TAP env shebang with variables > shell 1`] = ` -#!/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") - -case \`uname\` in - *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; -esac - -if [ -x "$basedir/node" ]; then - exec NODE_PATH=./lib:$NODE_PATH "$basedir/node" "$basedir/from.env.variables" "$@" -else - exec NODE_PATH=./lib:$NODE_PATH node "$basedir/from.env.variables" "$@" -fi - -` - -exports[`test/basic.js TAP explicit shebang > cmd 1`] = ` -@ECHO off\\r -GOTO start\\r -:find_dp0\\r -SET dp0=%~dp0\\r -EXIT /b\\r -:start\\r -SETLOCAL\\r -CALL :find_dp0\\r -\\r -IF EXIST "%dp0%\\/usr/bin/sh.exe" (\\r - SET "_prog=%dp0%\\/usr/bin/sh.exe"\\r -) ELSE (\\r - SET "_prog=/usr/bin/sh"\\r - SET PATHEXT=%PATHEXT:;.JS;=;%\\r -)\\r -\\r -endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\from.sh" %*\\r - -` - -exports[`test/basic.js TAP explicit shebang > ps1 1`] = ` -#!/usr/bin/env pwsh -$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent - -$exe="" -if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { - # Fix case when both the Windows and Linux builds of Node - # are installed in the same directory - $exe=".exe" -} -$ret=0 -if (Test-Path "$basedir//usr/bin/sh$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir//usr/bin/sh$exe" "$basedir/from.sh" $args - } else { - & "$basedir//usr/bin/sh$exe" "$basedir/from.sh" $args - } - $ret=$LASTEXITCODE -} else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "/usr/bin/sh$exe" "$basedir/from.sh" $args - } else { - & "/usr/bin/sh$exe" "$basedir/from.sh" $args - } - $ret=$LASTEXITCODE -} -exit $ret - -` - -exports[`test/basic.js TAP explicit shebang > shell 1`] = ` -#!/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") - -case \`uname\` in - *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; -esac - -if [ -x "$basedir//usr/bin/sh" ]; then - exec "$basedir//usr/bin/sh" "$basedir/from.sh" "$@" -else - exec /usr/bin/sh "$basedir/from.sh" "$@" -fi - -` - -exports[`test/basic.js TAP explicit shebang with args > cmd 1`] = ` -@ECHO off\\r -GOTO start\\r -:find_dp0\\r -SET dp0=%~dp0\\r -EXIT /b\\r -:start\\r -SETLOCAL\\r -CALL :find_dp0\\r -\\r -IF EXIST "%dp0%\\/usr/bin/sh.exe" (\\r - SET "_prog=%dp0%\\/usr/bin/sh.exe"\\r -) ELSE (\\r - SET "_prog=/usr/bin/sh"\\r - SET PATHEXT=%PATHEXT:;.JS;=;%\\r -)\\r -\\r -endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" -x "%dp0%\\from.sh.args" %*\\r - -` - -exports[`test/basic.js TAP explicit shebang with args > ps1 1`] = ` -#!/usr/bin/env pwsh -$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent - -$exe="" -if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { - # Fix case when both the Windows and Linux builds of Node - # are installed in the same directory - $exe=".exe" -} -$ret=0 -if (Test-Path "$basedir//usr/bin/sh$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir//usr/bin/sh$exe" -x "$basedir/from.sh.args" $args - } else { - & "$basedir//usr/bin/sh$exe" -x "$basedir/from.sh.args" $args - } - $ret=$LASTEXITCODE -} else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "/usr/bin/sh$exe" -x "$basedir/from.sh.args" $args - } else { - & "/usr/bin/sh$exe" -x "$basedir/from.sh.args" $args - } - $ret=$LASTEXITCODE -} -exit $ret - -` - -exports[`test/basic.js TAP explicit shebang with args > shell 1`] = ` -#!/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") - -case \`uname\` in - *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; -esac - -if [ -x "$basedir//usr/bin/sh" ]; then - exec "$basedir//usr/bin/sh" -x "$basedir/from.sh.args" "$@" -else - exec /usr/bin/sh -x "$basedir/from.sh.args" "$@" -fi - -` - -exports[`test/basic.js TAP if exists (it does exist) > cmd 1`] = ` -@ECHO off\\r -GOTO start\\r -:find_dp0\\r -SET dp0=%~dp0\\r -EXIT /b\\r -:start\\r -SETLOCAL\\r -CALL :find_dp0\\r -"%dp0%\\from.exe" %*\\r - -` - -exports[`test/basic.js TAP if exists (it does exist) > ps1 1`] = ` -#!/usr/bin/env pwsh -$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent - -$exe="" -if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { - # Fix case when both the Windows and Linux builds of Node - # are installed in the same directory - $exe=".exe" -} -# Support pipeline input -if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/from.exe" $args -} else { - & "$basedir/from.exe" $args -} -exit $LASTEXITCODE - -` - -exports[`test/basic.js TAP if exists (it does exist) > shell 1`] = ` -#!/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") - -case \`uname\` in - *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; -esac - -exec "$basedir/from.exe" "$@" - -` - -exports[`test/basic.js TAP just proceed if reading fails > cmd 1`] = ` -@ECHO off\\r -GOTO start\\r -:find_dp0\\r -SET dp0=%~dp0\\r -EXIT /b\\r -:start\\r -SETLOCAL\\r -CALL :find_dp0\\r -"%dp0%\\" %*\\r - -` - -exports[`test/basic.js TAP just proceed if reading fails > ps1 1`] = ` -#!/usr/bin/env pwsh -$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent - -$exe="" -if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { - # Fix case when both the Windows and Linux builds of Node - # are installed in the same directory - $exe=".exe" -} -# Support pipeline input -if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/" $args -} else { - & "$basedir/" $args -} -exit $LASTEXITCODE - -` - -exports[`test/basic.js TAP just proceed if reading fails > shell 1`] = ` -#!/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") - -case \`uname\` in - *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; -esac - -exec "$basedir/" "$@" - -` - -exports[`test/basic.js TAP no shebang > cmd 1`] = ` -@ECHO off\\r -GOTO start\\r -:find_dp0\\r -SET dp0=%~dp0\\r -EXIT /b\\r -:start\\r -SETLOCAL\\r -CALL :find_dp0\\r -"%dp0%\\from.exe" %*\\r - -` - -exports[`test/basic.js TAP no shebang > ps1 1`] = ` -#!/usr/bin/env pwsh -$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent - -$exe="" -if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { - # Fix case when both the Windows and Linux builds of Node - # are installed in the same directory - $exe=".exe" -} -# Support pipeline input -if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/from.exe" $args -} else { - & "$basedir/from.exe" $args -} -exit $LASTEXITCODE - -` - -exports[`test/basic.js TAP no shebang > shell 1`] = ` -#!/bin/sh -basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") - -case \`uname\` in - *CYGWIN*|*MINGW*|*MSYS*) basedir=\`cygpath -w "$basedir"\`;; -esac - -exec "$basedir/from.exe" "$@" - -` diff --git a/tap-snapshots/test/basic.js.test.cjs b/tap-snapshots/test/basic.js.test.cjs index 539d6c4..15c0e1e 100644 --- a/tap-snapshots/test/basic.js.test.cjs +++ b/tap-snapshots/test/basic.js.test.cjs @@ -36,25 +36,37 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { # are installed in the same directory $exe=".exe" } -$ret=0 + +$PROGRAM_EXE="node$exe" if (Test-Path "$basedir/node$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/node$exe" "$basedir/from.env" $args - } else { - & "$basedir/node$exe" "$basedir/from.env" $args - } - $ret=$LASTEXITCODE -} else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "node$exe" "$basedir/from.env" $args + $PROGRAM_EXE="$basedir/node$exe" +} +$PROGRAM_FILE="$basedir/from.env" + +if ($MyInvocation.ExpectingInput) { # takes pipeline input + $input | & "$PROGRAM_EXE" "$PROGRAM_FILE" $args +} elseif (-not $MyInvocation.Line) { # used "-File" argument + & "$PROGRAM_EXE" "$PROGRAM_FILE" $args +} else { # used "-Command" argument + if (($MyInvocation | Get-Member -Name 'Statement') -and $MyInvocation.Statement) { + $ORIGINAL_COMMAND = $MyInvocation.Statement } else { - & "node$exe" "$basedir/from.env" $args + $ORIGINAL_COMMAND = ( + [Management.Automation.InvocationInfo].GetProperty('ScriptPosition', [Reflection.BindingFlags] 'Instance, NonPublic') + ).GetValue($MyInvocation).Text } - $ret=$LASTEXITCODE + + $PROGRAM_EXE = $PROGRAM_EXE.Replace("\`\`", "\`\`\`\`") + $PROGRAM_FILE = $PROGRAM_FILE.Replace("\`\`", "\`\`\`\`") + + $NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($ORIGINAL_COMMAND, [ref] $null, [ref] $null). + EndBlock.Statements.PipelineElements.CommandElements.Extent.Text -join ' ' + $PROGRAM_FILE_ARGS = $NO_REDIRECTS_COMMAND.Substring($MyInvocation.InvocationName.Length).Trim() + + Invoke-Expression "& \`"$PROGRAM_EXE\`" \`"$PROGRAM_FILE\`" $PROGRAM_FILE_ARGS" } -exit $ret + +exit $LASTEXITCODE ` @@ -109,25 +121,20 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { # are installed in the same directory $exe=".exe" } -$ret=0 + +$PROGRAM_EXE="node$exe" if (Test-Path "$basedir/node$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/node$exe" --expose_gc "$basedir/from.env.args" $args - } else { - & "$basedir/node$exe" --expose_gc "$basedir/from.env.args" $args - } - $ret=$LASTEXITCODE + $PROGRAM_EXE="$basedir/node$exe" +} + +# Support pipeline input +if ($MyInvocation.ExpectingInput) { + $input | & "$PROGRAM_EXE" --expose_gc "$basedir/from.env.args" $args } else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "node$exe" --expose_gc "$basedir/from.env.args" $args - } else { - & "node$exe" --expose_gc "$basedir/from.env.args" $args - } - $ret=$LASTEXITCODE + & "$PROGRAM_EXE" --expose_gc "$basedir/from.env.args" $args } -exit $ret + +exit $LASTEXITCODE ` @@ -183,25 +190,37 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { # are installed in the same directory $exe=".exe" } -$ret=0 + +$PROGRAM_EXE="node$exe" if (Test-Path "$basedir/node$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/node$exe" "$basedir/from.env.variables" $args - } else { - & "$basedir/node$exe" "$basedir/from.env.variables" $args - } - $ret=$LASTEXITCODE -} else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "node$exe" "$basedir/from.env.variables" $args + $PROGRAM_EXE="$basedir/node$exe" +} +$PROGRAM_FILE="$basedir/from.env.variables" + +if ($MyInvocation.ExpectingInput) { # takes pipeline input + $input | & "$PROGRAM_EXE" "$PROGRAM_FILE" $args +} elseif (-not $MyInvocation.Line) { # used "-File" argument + & "$PROGRAM_EXE" "$PROGRAM_FILE" $args +} else { # used "-Command" argument + if (($MyInvocation | Get-Member -Name 'Statement') -and $MyInvocation.Statement) { + $ORIGINAL_COMMAND = $MyInvocation.Statement } else { - & "node$exe" "$basedir/from.env.variables" $args + $ORIGINAL_COMMAND = ( + [Management.Automation.InvocationInfo].GetProperty('ScriptPosition', [Reflection.BindingFlags] 'Instance, NonPublic') + ).GetValue($MyInvocation).Text } - $ret=$LASTEXITCODE + + $PROGRAM_EXE = $PROGRAM_EXE.Replace("\`\`", "\`\`\`\`") + $PROGRAM_FILE = $PROGRAM_FILE.Replace("\`\`", "\`\`\`\`") + + $NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($ORIGINAL_COMMAND, [ref] $null, [ref] $null). + EndBlock.Statements.PipelineElements.CommandElements.Extent.Text -join ' ' + $PROGRAM_FILE_ARGS = $NO_REDIRECTS_COMMAND.Substring($MyInvocation.InvocationName.Length).Trim() + + Invoke-Expression "& \`"$PROGRAM_EXE\`" \`"$PROGRAM_FILE\`" $PROGRAM_FILE_ARGS" } -exit $ret + +exit $LASTEXITCODE ` @@ -256,25 +275,37 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { # are installed in the same directory $exe=".exe" } -$ret=0 + +$PROGRAM_EXE="/usr/bin/sh$exe" if (Test-Path "$basedir//usr/bin/sh$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir//usr/bin/sh$exe" "$basedir/from.sh" $args - } else { - & "$basedir//usr/bin/sh$exe" "$basedir/from.sh" $args - } - $ret=$LASTEXITCODE -} else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "/usr/bin/sh$exe" "$basedir/from.sh" $args + $PROGRAM_EXE="$basedir//usr/bin/sh$exe" +} +$PROGRAM_FILE="$basedir/from.sh" + +if ($MyInvocation.ExpectingInput) { # takes pipeline input + $input | & "$PROGRAM_EXE" "$PROGRAM_FILE" $args +} elseif (-not $MyInvocation.Line) { # used "-File" argument + & "$PROGRAM_EXE" "$PROGRAM_FILE" $args +} else { # used "-Command" argument + if (($MyInvocation | Get-Member -Name 'Statement') -and $MyInvocation.Statement) { + $ORIGINAL_COMMAND = $MyInvocation.Statement } else { - & "/usr/bin/sh$exe" "$basedir/from.sh" $args + $ORIGINAL_COMMAND = ( + [Management.Automation.InvocationInfo].GetProperty('ScriptPosition', [Reflection.BindingFlags] 'Instance, NonPublic') + ).GetValue($MyInvocation).Text } - $ret=$LASTEXITCODE + + $PROGRAM_EXE = $PROGRAM_EXE.Replace("\`\`", "\`\`\`\`") + $PROGRAM_FILE = $PROGRAM_FILE.Replace("\`\`", "\`\`\`\`") + + $NO_REDIRECTS_COMMAND = [Management.Automation.Language.Parser]::ParseInput($ORIGINAL_COMMAND, [ref] $null, [ref] $null). + EndBlock.Statements.PipelineElements.CommandElements.Extent.Text -join ' ' + $PROGRAM_FILE_ARGS = $NO_REDIRECTS_COMMAND.Substring($MyInvocation.InvocationName.Length).Trim() + + Invoke-Expression "& \`"$PROGRAM_EXE\`" \`"$PROGRAM_FILE\`" $PROGRAM_FILE_ARGS" } -exit $ret + +exit $LASTEXITCODE ` @@ -329,25 +360,20 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { # are installed in the same directory $exe=".exe" } -$ret=0 + +$PROGRAM_EXE="/usr/bin/sh$exe" if (Test-Path "$basedir//usr/bin/sh$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir//usr/bin/sh$exe" -x "$basedir/from.sh.args" $args - } else { - & "$basedir//usr/bin/sh$exe" -x "$basedir/from.sh.args" $args - } - $ret=$LASTEXITCODE + $PROGRAM_EXE="$basedir//usr/bin/sh$exe" +} + +# Support pipeline input +if ($MyInvocation.ExpectingInput) { + $input | & "$PROGRAM_EXE" -x "$basedir/from.sh.args" $args } else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "/usr/bin/sh$exe" -x "$basedir/from.sh.args" $args - } else { - & "/usr/bin/sh$exe" -x "$basedir/from.sh.args" $args - } - $ret=$LASTEXITCODE + & "$PROGRAM_EXE" -x "$basedir/from.sh.args" $args } -exit $ret + +exit $LASTEXITCODE ` @@ -502,25 +528,20 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { # are installed in the same directory $exe=".exe" } -$ret=0 + +$PROGRAM_EXE="node$exe" if (Test-Path "$basedir/node$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/node$exe" --flag-one --flag-two "$basedir/from.env.multiple.variables" $args - } else { - & "$basedir/node$exe" --flag-one --flag-two "$basedir/from.env.multiple.variables" $args - } - $ret=$LASTEXITCODE + $PROGRAM_EXE="$basedir/node$exe" +} + +# Support pipeline input +if ($MyInvocation.ExpectingInput) { + $input | & "$PROGRAM_EXE" --flag-one --flag-two "$basedir/from.env.multiple.variables" $args } else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "node$exe" --flag-one --flag-two "$basedir/from.env.multiple.variables" $args - } else { - & "node$exe" --flag-one --flag-two "$basedir/from.env.multiple.variables" $args - } - $ret=$LASTEXITCODE + & "$PROGRAM_EXE" --flag-one --flag-two "$basedir/from.env.multiple.variables" $args } -exit $ret + +exit $LASTEXITCODE ` @@ -624,25 +645,20 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { # are installed in the same directory $exe=".exe" } -$ret=0 + +$PROGRAM_EXE="node$exe" if (Test-Path "$basedir/node$exe") { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "$basedir/node$exe" --expose_gc "$basedir/from.env.S" $args - } else { - & "$basedir/node$exe" --expose_gc "$basedir/from.env.S" $args - } - $ret=$LASTEXITCODE + $PROGRAM_EXE="$basedir/node$exe" +} + +# Support pipeline input +if ($MyInvocation.ExpectingInput) { + $input | & "$PROGRAM_EXE" --expose_gc "$basedir/from.env.S" $args } else { - # Support pipeline input - if ($MyInvocation.ExpectingInput) { - $input | & "node$exe" --expose_gc "$basedir/from.env.S" $args - } else { - & "node$exe" --expose_gc "$basedir/from.env.S" $args - } - $ret=$LASTEXITCODE + & "$PROGRAM_EXE" --expose_gc "$basedir/from.env.S" $args } -exit $ret + +exit $LASTEXITCODE `