Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/post-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
119 changes: 81 additions & 38 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
Loading