Skip to content

Commit

Permalink
Remove most of "exe" check. I do not believe it is necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Feb 17, 2021
1 parent 368348a commit d7c390b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 129 deletions.
35 changes: 7 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,12 @@ const writeShim_ = (from, to, prog, args, variables) => {

// #!/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"
// }
//
// $nodepath=""
// if (($exe -ne "") -and (Test-Path ("$basedir/node" + $exe))) {
// $nodepath="$basedir/node" + $exe
// $nodepath="node"
// if ($IsWindows -and (Test-Path ("$basedir/node" + ".exe"))) {
// $nodepath="$basedir/node" + ".exe"
// } elseif (Test-Path "$basedir/node") {
// $nodepath="$basedir/node"
// } elseif (($exe -ne "") -and (Get-Command ("node" + $exe) -errorAction SilentlyContinue)) {
// $nodepath="node" + $exe
// } else {
// $nodepath="node"
// }
//
// # Support pipeline input
Expand All @@ -179,28 +169,17 @@ const writeShim_ = (from, to, prog, args, variables) => {
// exit $LASTEXITCODE
let pwsh = '#!/usr/bin/env pwsh\n'
+ '$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent\n'
+ '$exe=""\n'
+ 'if ($PSVersionTable.PSVersion -lt \"6.0\" -or $IsWindows) {\n'
+ ' # Fix case when both the Windows and Linux builds of Node\n'
+ ' # are installed in the same directory\n'
+ ' $exe=".exe"\n'
+ '}\n'
+ '\n'
+ `$nodepath=""\n`
+ `$nodepath=${pwshProg}\n`
if (pwshLongProg) {
pwsh = pwsh
+ `if (($exe -ne "") -and (Test-Path (${pwshLongProg} + $exe))) {\n`
+ ` $nodepath=${pwshLongProg} + $exe\n`
+ `if ($IsWindows -and (Test-Path (${pwshLongProg} + ".exe"))) {\n`
+ ` $nodepath=${pwshLongProg} + ".exe"\n`
+ `} elseif (Test-Path ${pwshLongProg}) {\n`
+ ` $nodepath=${pwshLongProg}\n`
+ '} else'
+ `}\n`;
}
pwsh = pwsh
+ `if (($exe -ne "") -and (Get-Command (${pwshProg} + $exe) -errorAction SilentlyContinue)) {\n`
+ ` $nodepath=${pwshProg} + $exe\n`
+ `} else {\n`
+ ` $nodepath=${pwshProg}\n`
+ `}\n`
+ '\n'
+ '# Support pipeline input\n'
+ 'if ($MyInvocation.ExpectingInput) {\n'
Expand Down
119 changes: 18 additions & 101 deletions tap-snapshots/test-basic.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,12 @@ endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\from
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"
}
$nodepath=""
if (($exe -ne "") -and (Test-Path ("$basedir/node" + $exe))) {
$nodepath="$basedir/node" + $exe
$nodepath="node"
if ($IsWindows -and (Test-Path ("$basedir/node" + ".exe"))) {
$nodepath="$basedir/node" + ".exe"
} elseif (Test-Path "$basedir/node") {
$nodepath="$basedir/node"
} elseif (($exe -ne "") -and (Get-Command ("node" + $exe) -errorAction SilentlyContinue)) {
$nodepath="node" + $exe
} else {
$nodepath="node"
}
# Support pipeline input
Expand Down Expand Up @@ -97,22 +87,12 @@ endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" --expose_gc "
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"
}
$nodepath=""
if (($exe -ne "") -and (Test-Path ("$basedir/node" + $exe))) {
$nodepath="$basedir/node" + $exe
$nodepath="node"
if ($IsWindows -and (Test-Path ("$basedir/node" + ".exe"))) {
$nodepath="$basedir/node" + ".exe"
} elseif (Test-Path "$basedir/node") {
$nodepath="$basedir/node"
} elseif (($exe -ne "") -and (Get-Command ("node" + $exe) -errorAction SilentlyContinue)) {
$nodepath="node" + $exe
} else {
$nodepath="node"
}
# Support pipeline input
Expand Down Expand Up @@ -166,22 +146,12 @@ endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\from
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"
}
$nodepath=""
if (($exe -ne "") -and (Test-Path ("$basedir/node" + $exe))) {
$nodepath="$basedir/node" + $exe
$nodepath="node"
if ($IsWindows -and (Test-Path ("$basedir/node" + ".exe"))) {
$nodepath="$basedir/node" + ".exe"
} elseif (Test-Path "$basedir/node") {
$nodepath="$basedir/node"
} elseif (($exe -ne "") -and (Get-Command ("node" + $exe) -errorAction SilentlyContinue)) {
$nodepath="node" + $exe
} else {
$nodepath="node"
}
# Support pipeline input
Expand Down Expand Up @@ -234,22 +204,12 @@ endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\from
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"
}
$nodepath=""
if (($exe -ne "") -and (Test-Path ("$basedir//usr/bin/sh" + $exe))) {
$nodepath="$basedir//usr/bin/sh" + $exe
$nodepath="/usr/bin/sh"
if ($IsWindows -and (Test-Path ("$basedir//usr/bin/sh" + ".exe"))) {
$nodepath="$basedir//usr/bin/sh" + ".exe"
} elseif (Test-Path "$basedir//usr/bin/sh") {
$nodepath="$basedir//usr/bin/sh"
} elseif (($exe -ne "") -and (Get-Command ("/usr/bin/sh" + $exe) -errorAction SilentlyContinue)) {
$nodepath="/usr/bin/sh" + $exe
} else {
$nodepath="/usr/bin/sh"
}
# Support pipeline input
Expand Down Expand Up @@ -302,22 +262,12 @@ endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" -x "%dp0%\\fr
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"
}
$nodepath=""
if (($exe -ne "") -and (Test-Path ("$basedir//usr/bin/sh" + $exe))) {
$nodepath="$basedir//usr/bin/sh" + $exe
$nodepath="/usr/bin/sh"
if ($IsWindows -and (Test-Path ("$basedir//usr/bin/sh" + ".exe"))) {
$nodepath="$basedir//usr/bin/sh" + ".exe"
} elseif (Test-Path "$basedir//usr/bin/sh") {
$nodepath="$basedir//usr/bin/sh"
} elseif (($exe -ne "") -and (Get-Command ("/usr/bin/sh" + $exe) -errorAction SilentlyContinue)) {
$nodepath="/usr/bin/sh" + $exe
} else {
$nodepath="/usr/bin/sh"
}
# Support pipeline input
Expand Down Expand Up @@ -362,19 +312,8 @@ CALL :find_dp0\\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"
}
$nodepath=""
if (($exe -ne "") -and (Get-Command ("$basedir/from.exe" + $exe) -errorAction SilentlyContinue)) {
$nodepath="$basedir/from.exe" + $exe
} else {
$nodepath="$basedir/from.exe"
}
$nodepath="$basedir/from.exe"
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
Expand Down Expand Up @@ -414,19 +353,8 @@ CALL :find_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"
}
$nodepath=""
if (($exe -ne "") -and (Get-Command ("$basedir/" + $exe) -errorAction SilentlyContinue)) {
$nodepath="$basedir/" + $exe
} else {
$nodepath="$basedir/"
}
$nodepath="$basedir/"
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
Expand Down Expand Up @@ -466,19 +394,8 @@ CALL :find_dp0\\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"
}
$nodepath=""
if (($exe -ne "") -and (Get-Command ("$basedir/from.exe" + $exe) -errorAction SilentlyContinue)) {
$nodepath="$basedir/from.exe" + $exe
} else {
$nodepath="$basedir/from.exe"
}
$nodepath="$basedir/from.exe"
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
Expand Down

0 comments on commit d7c390b

Please sign in to comment.