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

refactor(path): make isWindows check compatible with Node and Bun #4961

Merged
merged 18 commits into from
Aug 29, 2024
Merged
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
33 changes: 7 additions & 26 deletions path/_os.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
// deno-lint-ignore-file no-explicit-any
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

// Keep this up-to-date with Deno.build.os
/**
* Operating system type, equivalent to the type of
* {@linkcode https://deno.land/api?s=Deno.build | Deno.build.os}.
*/
type OSType =
| "darwin"
| "linux"
| "windows"
| "freebsd"
| "netbsd"
| "aix"
| "solaris"
| "illumos"
| "android";

function getOsType(): OSType {
// deno-lint-ignore no-explicit-any
return (globalThis as any).Deno?.build.os ||
// deno-lint-ignore no-explicit-any
((globalThis as any).navigator?.userAgent.includes("Win")
? "windows"
: "linux");
}

export const isWindows: boolean = getOsType() === "windows";
// Check Deno, then the remaining runtimes (e.g. Node, Bun and the browser)
export const isWindows: boolean =

Check warning on line 6 in path/_os.ts

View check run for this annotation

Codecov / codecov/patch

path/_os.ts#L6

Added line #L6 was not covered by tests
(globalThis as any).Deno?.build.os === "windows" ||
(globalThis as any).navigator?.platform?.startsWith("Win") ||
(globalThis as any).process?.platform?.startsWith("win") ||
false;

Check warning on line 10 in path/_os.ts

View check run for this annotation

Codecov / codecov/patch

path/_os.ts#L10

Added line #L10 was not covered by tests
Loading