From 9138ceb2f8abae266cb6f90585fb08859e67dc87 Mon Sep 17 00:00:00 2001 From: uki00a Date: Thu, 9 Mar 2023 07:07:28 +0900 Subject: [PATCH 1/4] fix: migrate `Deno.run` to `Deno.Command` --- notifiers/subprocess.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/notifiers/subprocess.ts b/notifiers/subprocess.ts index f67323b..7604c24 100644 --- a/notifiers/subprocess.ts +++ b/notifiers/subprocess.ts @@ -14,20 +14,19 @@ export abstract class SubprocessNotifier implements Notifier { maybeMessage, ); const cmd = this.buildCmd(notification); - const process = Deno.run({ - cmd, + const [executable, ...args] = cmd; + if (executable == null) { + throw new Error( + "`buildCmd()` should return an array with at least one element", + ); + } + + const status = await new Deno.Command(executable, { + args, stderr: "piped", - }); - try { - const status = await process.status(); - if (!status.success) { - const output = await readAll(process.stderr); - const decoder = new TextDecoder(); - throw new Error(decoder.decode(output)); - } - } finally { - process.stderr.close(); - process.close(); + }).output(); + if (!status.success) { + throw new Error(decoder.decode(process.stderr)); } } From 0ccc9671efc4992365d7cd2520b6d41bc23d0876 Mon Sep 17 00:00:00 2001 From: uki00a Date: Thu, 9 Mar 2023 07:09:06 +0900 Subject: [PATCH 2/4] chore: resolve lint error --- deps.ts | 1 - notifiers/subprocess.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/deps.ts b/deps.ts index b690aa8..8948b87 100644 --- a/deps.ts +++ b/deps.ts @@ -1,3 +1,2 @@ -export { readAll } from "https://deno.land/std@0.178.0/streams/read_all.ts"; export { deferred } from "https://deno.land/std@0.178.0/async/deferred.ts"; export type { Deferred } from "https://deno.land/std@0.178.0/async/deferred.ts"; diff --git a/notifiers/subprocess.ts b/notifiers/subprocess.ts index 7604c24..c57c3f3 100644 --- a/notifiers/subprocess.ts +++ b/notifiers/subprocess.ts @@ -1,6 +1,5 @@ import type { Notification, Notifier } from "./notifier.ts"; import { normalizeNotification } from "./util.ts"; -import { readAll } from "../deps.ts"; export abstract class SubprocessNotifier implements Notifier { notify(title: string, message: string): Promise; From f8e6b2bfb3c078ad5614258d79efcb215eed3d6f Mon Sep 17 00:00:00 2001 From: uki00a Date: Thu, 9 Mar 2023 07:10:50 +0900 Subject: [PATCH 3/4] fix: type error --- notifiers/subprocess.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifiers/subprocess.ts b/notifiers/subprocess.ts index c57c3f3..ea16670 100644 --- a/notifiers/subprocess.ts +++ b/notifiers/subprocess.ts @@ -25,7 +25,7 @@ export abstract class SubprocessNotifier implements Notifier { stderr: "piped", }).output(); if (!status.success) { - throw new Error(decoder.decode(process.stderr)); + throw new Error(decoder.decode(status.stderr)); } } From df844abd00979154f3c681e12156835ba3437e97 Mon Sep 17 00:00:00 2001 From: uki00a Date: Thu, 9 Mar 2023 07:13:15 +0900 Subject: [PATCH 4/4] fix: type error (part 2) --- notifiers/subprocess.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/notifiers/subprocess.ts b/notifiers/subprocess.ts index ea16670..a55a53d 100644 --- a/notifiers/subprocess.ts +++ b/notifiers/subprocess.ts @@ -2,6 +2,8 @@ import type { Notification, Notifier } from "./notifier.ts"; import { normalizeNotification } from "./util.ts"; export abstract class SubprocessNotifier implements Notifier { + #decoder = new TextDecoder(); + notify(title: string, message: string): Promise; notify(notification: Notification): Promise; async notify( @@ -25,7 +27,7 @@ export abstract class SubprocessNotifier implements Notifier { stderr: "piped", }).output(); if (!status.success) { - throw new Error(decoder.decode(status.stderr)); + throw new Error(this.#decoder.decode(status.stderr)); } }