fix: 补强 Windows rg 与 PowerShell 诊断
This commit is contained in:
+33
-1
@@ -129,6 +129,32 @@ export class SshRemovedShellAliasError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export class SshWindowsPowerShellLocalExpansionError extends Error {
|
||||
code = "ssh-windows-powershell-local-expansion";
|
||||
level = "error";
|
||||
entrypoint: string;
|
||||
route: string;
|
||||
operation = "ps";
|
||||
replacementExamples: { oneLine: string; pipeline: string; stdin: string };
|
||||
migrationHint: string;
|
||||
note = "Local Bash expands $p and $_ inside double quotes before trans receives the PowerShell source.";
|
||||
|
||||
constructor(route: string) {
|
||||
const entrypoint = sshDisplayEntrypoint();
|
||||
const replacementExamples = {
|
||||
oneLine: `${entrypoint} ${route} ps '$p = Start-Process python -PassThru; $p.Id'`,
|
||||
pipeline: `${entrypoint} ${route} ps 'Get-Process | Where-Object { $_.CPU -gt 0 }'`,
|
||||
stdin: `${entrypoint} ${route} ps <<'PS'`,
|
||||
};
|
||||
super("ssh win ps source looks like a PowerShell variable was expanded by the local shell before trans received it");
|
||||
this.name = "SshWindowsPowerShellLocalExpansionError";
|
||||
this.entrypoint = entrypoint;
|
||||
this.route = route;
|
||||
this.replacementExamples = replacementExamples;
|
||||
this.migrationHint = `Wrap the complete PowerShell source in local single quotes, for example: ${replacementExamples.oneLine}. Use a quoted PS heredoc for multiline source.`;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SshStdoutTruncationHint {
|
||||
code: "ssh-stdout-truncated" | "ssh-stderr-truncated";
|
||||
level: "warning";
|
||||
@@ -522,8 +548,10 @@ function parseWinRouteArgs(route: ParsedSshRoute, args: string[]): ParsedSshArgs
|
||||
invocationKind: "argv",
|
||||
};
|
||||
}
|
||||
const command = commandArgs[0] ?? "";
|
||||
if (looksLikeLocallyExpandedPowerShellSource(command)) throw new SshWindowsPowerShellLocalExpansionError(route.raw);
|
||||
return {
|
||||
remoteCommand: buildWindowsPowerShellInvocation(buildWindowsPowerShellInlineLauncherScript(commandArgs[0] ?? "", route.workspace)),
|
||||
remoteCommand: buildWindowsPowerShellInvocation(buildWindowsPowerShellInlineLauncherScript(command, route.workspace)),
|
||||
requiresStdin: false,
|
||||
invocationKind: "helper",
|
||||
};
|
||||
@@ -546,6 +574,10 @@ function parseWinRouteArgs(route: ParsedSshRoute, args: string[]): ParsedSshArgs
|
||||
};
|
||||
}
|
||||
|
||||
function looksLikeLocallyExpandedPowerShellSource(command: string): boolean {
|
||||
return /(?:^|[;{}]\s*)=\s*[^=]/u.test(command);
|
||||
}
|
||||
|
||||
function windowsRouteRepeatedWinOperationMessage(route: ParsedSshRoute, nextArgs: string[]): string {
|
||||
const entrypoint = sshDisplayEntrypoint();
|
||||
const suffix = nextArgs.length > 0 ? ` ${nextArgs.join(" ")}` : " ps";
|
||||
|
||||
Reference in New Issue
Block a user