diff --git a/command/_runtime/exit.ts b/command/_runtime/exit.ts new file mode 100644 index 00000000..66ce1cc0 --- /dev/null +++ b/command/_runtime/exit.ts @@ -0,0 +1,11 @@ +export function exit(code: number): never { + // dnt-shim-ignore deno-lint-ignore no-explicit-any + const { Deno, process } = globalThis as any; + const exit: (code: number) => never = Deno?.exit ?? process?.exit; + + if (exit) { + exit(code); + } + + throw new Error("unsupported runtime"); +} diff --git a/command/_runtime/get-argv.ts b/command/_runtime/get-argv.ts new file mode 100644 index 00000000..d20de72a --- /dev/null +++ b/command/_runtime/get-argv.ts @@ -0,0 +1,6 @@ +export function getArgv(): Array { + // dnt-shim-ignore deno-lint-ignore no-explicit-any + const { Deno, process } = globalThis as any; + + return Deno?.args ?? process?.argv.slice(2) ?? []; +} diff --git a/command/_runtime/get-env.ts b/command/_runtime/get-env.ts new file mode 100644 index 00000000..5912af6f --- /dev/null +++ b/command/_runtime/get-env.ts @@ -0,0 +1,12 @@ +export function getEnv(name: string): string | undefined { + // dnt-shim-ignore deno-lint-ignore no-explicit-any + const { Deno, process } = globalThis as any; + + if (Deno) { + return Deno.env.get(name); + } else if (process) { + return process.env[name]; + } + + throw new Error("unsupported runtime"); +} diff --git a/command/_runtime/no_color.ts b/command/_runtime/no_color.ts new file mode 100644 index 00000000..8055511f --- /dev/null +++ b/command/_runtime/no_color.ts @@ -0,0 +1,14 @@ +export function getNoColor(): boolean { + // dnt-shim-ignore deno-lint-ignore no-explicit-any + const { Deno, process } = globalThis as any; + + if (Deno) { + return Deno.noColor; + } else if (process) { + return ( + process?.env.NO_COLOR === "1" || process?.env.NODE_DISABLE_COLORS === "1" + ); + } + + throw new Error("unsupported runtime"); +} diff --git a/command/_runtime/write_sync.ts b/command/_runtime/write_sync.ts new file mode 100644 index 00000000..65d879a0 --- /dev/null +++ b/command/_runtime/write_sync.ts @@ -0,0 +1,13 @@ +export function writeSync(data: Uint8Array): number { + // dnt-shim-ignore deno-lint-ignore no-explicit-any + const { Deno, process } = globalThis as any; + + if (Deno) { + return Deno.stdout.writeSync(data); + } else if (process) { + process.stdout.write(data); + return data.byteLength; + } else { + throw new Error("unsupported runtime"); + } +} diff --git a/command/upgrade/get_runtime.ts b/command/upgrade/get_runtime.ts index 31cd925b..5fa1d250 100644 --- a/command/upgrade/get_runtime.ts +++ b/command/upgrade/get_runtime.ts @@ -9,7 +9,7 @@ export interface GetRuntimeResult { /** Get runtime handler for current runtime. */ export async function getRuntime(): Promise { - // deno-lint-ignore no-explicit-any + // dnt-shim-ignore deno-lint-ignore no-explicit-any const { Deno, process } = globalThis as any; if (Deno?.version?.deno) { diff --git a/internal/runtime/exit.ts b/internal/runtime/exit.ts index ed5e8579..fb34258f 100644 --- a/internal/runtime/exit.ts +++ b/internal/runtime/exit.ts @@ -5,7 +5,7 @@ * @param code The exit code. */ export function exit(code: number): never { - // deno-lint-ignore no-explicit-any + // dnt-shim-ignore deno-lint-ignore no-explicit-any const { Deno, process } = globalThis as any; const exit: (code: number) => never = Deno?.exit ?? process?.exit; diff --git a/internal/runtime/get_args.ts b/internal/runtime/get_args.ts index 6f81d7ab..460df100 100644 --- a/internal/runtime/get_args.ts +++ b/internal/runtime/get_args.ts @@ -4,7 +4,7 @@ * @internal */ export function getArgs(): Array { - // deno-lint-ignore no-explicit-any + // dnt-shim-ignore deno-lint-ignore no-explicit-any const { Deno, process } = globalThis as any; return Deno?.args ?? process?.argv.slice(2) ?? []; diff --git a/internal/runtime/get_env.ts b/internal/runtime/get_env.ts index 03af34e1..53dbc3f4 100644 --- a/internal/runtime/get_env.ts +++ b/internal/runtime/get_env.ts @@ -5,7 +5,7 @@ * @param name The name of the environment variable. */ export function getEnv(name: string): string | undefined { - // deno-lint-ignore no-explicit-any + // dnt-shim-ignore deno-lint-ignore no-explicit-any const { Deno, process } = globalThis as any; if (Deno) { diff --git a/internal/runtime/get_os.ts b/internal/runtime/get_os.ts index d2481fbf..1d6676ee 100644 --- a/internal/runtime/get_os.ts +++ b/internal/runtime/get_os.ts @@ -16,7 +16,7 @@ export function getOs(): | "openbsd" | "sunos" | "win32" { - // deno-lint-ignore no-explicit-any + // dnt-shim-ignore deno-lint-ignore no-explicit-any const { Deno, process } = globalThis as any; if (Deno) { diff --git a/internal/runtime/is_terminal.ts b/internal/runtime/is_terminal.ts index db4981be..176e3eac 100644 --- a/internal/runtime/is_terminal.ts +++ b/internal/runtime/is_terminal.ts @@ -4,7 +4,7 @@ * @internal */ export function isTerminal(): boolean { - // deno-lint-ignore no-explicit-any + // dnt-shim-ignore deno-lint-ignore no-explicit-any const { Deno, process } = globalThis as any; if (Deno) { diff --git a/internal/runtime/no_color.ts b/internal/runtime/no_color.ts index bb860138..ca227550 100644 --- a/internal/runtime/no_color.ts +++ b/internal/runtime/no_color.ts @@ -4,14 +4,15 @@ * @internal */ export function getNoColor(): boolean { - // deno-lint-ignore no-explicit-any + // dnt-shim-ignore deno-lint-ignore no-explicit-any const { Deno, process } = globalThis as any; if (Deno) { return Deno.noColor; } else if (process) { - return process?.env.NO_COLOR === "1" || - process?.env.NODE_DISABLE_COLORS === "1"; + return ( + process?.env.NO_COLOR === "1" || process?.env.NODE_DISABLE_COLORS === "1" + ); } throw new Error("unsupported runtime"); diff --git a/internal/runtime/set_raw.ts b/internal/runtime/set_raw.ts index ffd48ffb..dcd14b1a 100644 --- a/internal/runtime/set_raw.ts +++ b/internal/runtime/set_raw.ts @@ -7,9 +7,9 @@ */ export function setRaw( mode: boolean, - { cbreak }: { cbreak?: boolean } = {}, + { cbreak }: { cbreak?: boolean } = {} ): void { - // deno-lint-ignore no-explicit-any + // dnt-shim-ignore deno-lint-ignore no-explicit-any const { Deno, process } = globalThis as any; if (Deno) { diff --git a/internal/runtime/write_sync.ts b/internal/runtime/write_sync.ts index 1b5623cd..25e320a8 100644 --- a/internal/runtime/write_sync.ts +++ b/internal/runtime/write_sync.ts @@ -5,7 +5,7 @@ * @param data Data to write to stdout. */ export function writeSync(data: Uint8Array): number { - // deno-lint-ignore no-explicit-any + // dnt-shim-ignore deno-lint-ignore no-explicit-any const { Deno, process } = globalThis as any; if (Deno) {