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

👍 Use Deno.Command instead #4

Merged
merged 2 commits into from
May 8, 2023
Merged
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/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- macos-latest
- ubuntu-latest
version:
- "1.28.1"
- "1.28"
- "1.x"
host_version:
- vim: "v9.0.0472"
Expand Down
32 changes: 11 additions & 21 deletions denops_test/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type RunMode = "vim" | "nvim";

/** Runner option */
export interface RunOptions
extends Omit<Deno.RunOptions, "cmd" | "stdin" | "stdout" | "stderr"> {
extends Omit<Deno.CommandOptions, "cmd" | "stdin" | "stdout" | "stderr"> {
verbose?: boolean;
}

Expand All @@ -16,19 +16,20 @@ export function run(
mode: RunMode,
cmds: string[],
options: RunOptions = {},
): Deno.Process {
const cmd = [...buildArgs(mode), ...cmds.flatMap((c) => ["-c", c])];
): Deno.ChildProcess {
const [cmd, args] = buildArgs(mode);
args.unshift(...cmds.flatMap((c) => ["-c", c]));
if (options.verbose) {
cmd.unshift("--cmd", "redir >> /dev/stdout");
args.unshift("--cmd", "redir >> /dev/stdout");
}
const proc = Deno.run({
cmd,
const command = new Deno.Command(cmd, {
args,
env: options.env,
stdin: "piped",
stdout: options.verbose ? "inherit" : "null",
stderr: options.verbose ? "inherit" : "null",
});
return proc;
return command.spawn();
}

/**
Expand All @@ -44,28 +45,17 @@ export function isRunMode(mode: string): mode is RunMode {
}
}

function buildArgs(mode: RunMode): string[] {
function buildArgs(mode: RunMode): [string, string[]] {
switch (mode) {
case "vim":
return [
VIM_EXECUTABLE,
"-u",
"NONE",
"-i",
"NONE",
"-n",
"-N",
"-X",
"-e",
"-s",
["-u", "NONE", "-i", "NONE", "-n", "-N", "-X", "-e", "-s"],
];
case "nvim":
return [
NVIM_EXECUTABLE,
"--clean",
"--embed",
"--headless",
"-n",
["--clean", "--embed", "--headless", "-n"],
];
}
}
24 changes: 3 additions & 21 deletions denops_test/with.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ export async function withDenops(
},
);
} finally {
proc.stdin?.close();
await killProcess(proc);
await proc.status();
proc.close();
proc.stdin.close();
proc.kill();
await proc.status;
conn.close();
listener.close();
}
Expand All @@ -123,20 +122,3 @@ async function newDenopsImpl(
const { DenopsImpl } = await import(url.href);
return new DenopsImpl(pluginName, meta, session);
}

async function killProcess(proc: Deno.Process): Promise<void> {
if (Deno.build.os === "windows") {
// Signal API in Deno v1.14.0 on Windows
// does not work so use `taskkill` for now
const p = Deno.run({
cmd: ["taskkill", "/pid", proc.pid.toString(), "/F"],
stdin: "null",
stdout: "null",
stderr: "null",
});
await p.status();
p.close();
} else {
proc.kill("SIGTERM");
}
}