Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pwsh): Add support for pipeline input #43

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 30 additions & 5 deletions index.js
Expand Up @@ -203,10 +203,20 @@ function writeShim_ (from, to, prog, args, variables, cb) {
// $exe = ".exe"
// }
// if (Test-Path "$basedir/node") {
// & "$basedir/node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args
// # Support 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 {
// & "node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args
// # Support pipeline input
// if ($MyInvocation.ExpectingInput) {
// $input | & "node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args
// } else {
// & "node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args
// }
// $ret=$LASTEXITCODE
// }
// exit $ret
Expand All @@ -223,16 +233,31 @@ function writeShim_ (from, to, prog, args, variables, cb) {
pwsh = pwsh
+ "$ret=0\n"
+ "if (Test-Path " + pwshLongProg + ") {\n"
+ " & " + pwshLongProg + " " + args + " " + shTarget + " $args\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"
+ " & " + pwshProg + " " + args + " " + shTarget + " $args\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"
} else {
pwsh = pwsh
+ "& " + pwshProg + " " + args + " " + shTarget + " $args\n"
+ "# Support pipeline input\n"
+ "if ($MyInvocation.ExpectingInput) {\n"
+ " $input | & " + pwshProg + " " + args + " " + shTarget + " $args\n"
+ "} else {\n"
+ " & " + pwshProg + " " + args + " " + shTarget + " $args\n"
+ "}\n"
+ "exit $LASTEXITCODE\n"
}

Expand Down
91 changes: 78 additions & 13 deletions tap-snapshots/test-basic.js-TAP.test.js
Expand Up @@ -38,10 +38,20 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
}
$ret=0
if (Test-Path "$basedir/node$exe") {
& "$basedir/node$exe" "$basedir/from.env" $args
# 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 {
& "node$exe" "$basedir/from.env" $args
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "node$exe" "$basedir/from.env" $args
} else {
& "node$exe" "$basedir/from.env" $args
}
$ret=$LASTEXITCODE
}
exit $ret
Expand Down Expand Up @@ -100,10 +110,20 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
}
$ret=0
if (Test-Path "$basedir/node$exe") {
& "$basedir/node$exe" --expose_gc "$basedir/from.env.args" $args
# 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 {
& "node$exe" --expose_gc "$basedir/from.env.args" $args
# 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
Expand Down Expand Up @@ -163,10 +183,20 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
}
$ret=0
if (Test-Path "$basedir/node$exe") {
& "$basedir/node$exe" "$basedir/from.env.variables" $args
# 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 {
& "node$exe" "$basedir/from.env.variables" $args
# 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
Expand Down Expand Up @@ -225,10 +255,20 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
}
$ret=0
if (Test-Path "$basedir//usr/bin/sh$exe") {
& "$basedir//usr/bin/sh$exe" "$basedir/from.sh" $args
# 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 {
& "/usr/bin/sh$exe" "$basedir/from.sh" $args
# 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
Expand Down Expand Up @@ -287,10 +327,20 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
}
$ret=0
if (Test-Path "$basedir//usr/bin/sh$exe") {
& "$basedir//usr/bin/sh$exe" -x "$basedir/from.sh.args" $args
# 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 {
& "/usr/bin/sh$exe" -x "$basedir/from.sh.args" $args
# 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
Expand Down Expand Up @@ -339,7 +389,12 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# are installed in the same directory
$exe=".exe"
}
& "$basedir/from.exe" $args
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "$basedir/from.exe" $args
} else {
& "$basedir/from.exe" $args
}
exit $LASTEXITCODE

`
Expand Down Expand Up @@ -380,7 +435,12 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# are installed in the same directory
$exe=".exe"
}
& "$basedir/" $args
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "$basedir/" $args
} else {
& "$basedir/" $args
}
exit $LASTEXITCODE

`
Expand Down Expand Up @@ -421,7 +481,12 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# are installed in the same directory
$exe=".exe"
}
& "$basedir/from.exe" $args
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "$basedir/from.exe" $args
} else {
& "$basedir/from.exe" $args
}
exit $LASTEXITCODE

`
Expand Down