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

make work with dnt #768

Closed
wants to merge 2 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions command/_runtime/exit.ts
Original file line number Diff line number Diff line change
@@ -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");
}
6 changes: 6 additions & 0 deletions command/_runtime/get-argv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function getArgv(): Array<string> {
// dnt-shim-ignore deno-lint-ignore no-explicit-any
const { Deno, process } = globalThis as any;

return Deno?.args ?? process?.argv.slice(2) ?? [];
}
12 changes: 12 additions & 0 deletions command/_runtime/get-env.ts
Original file line number Diff line number Diff line change
@@ -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");
}
14 changes: 14 additions & 0 deletions command/_runtime/no_color.ts
Original file line number Diff line number Diff line change
@@ -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");
}
13 changes: 13 additions & 0 deletions command/_runtime/write_sync.ts
Original file line number Diff line number Diff line change
@@ -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");
}
}
2 changes: 1 addition & 1 deletion command/upgrade/get_runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface GetRuntimeResult {

/** Get runtime handler for current runtime. */
export async function getRuntime(): Promise<GetRuntimeResult> {
// 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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/get_args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @internal
*/
export function getArgs(): Array<string> {
// 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) ?? [];
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/get_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/get_os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/is_terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions internal/runtime/no_color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions internal/runtime/set_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/write_sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading