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

* Refactored to get rid of unnecessary function.

All that needs to be done here is to check if
the version is windows. Handling each combination
of runtime and operating system will make
the existing osType difficult to test and maintain.

* Changed browser version of isWindows.

It was using a deprecated web API.

* Refactored getIsWindows.

* Added node/bun version of isWindows.

* Got cross platform os module working.

* Handled Deno error.

* Fixed type errors.

* Removed node:os import.

This is how NodeJS checks to see
if the underlying OS is windows.

* tweaks

* fix

* cleanup

* tweak

* fix

* Added support for node.

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Ben McLean 2024-08-29 18:39:59 -04:00 committed by GitHub
parent 0a71a4d3db
commit c3b113d7a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 =
(globalThis as any).Deno?.build.os === "windows" ||
(globalThis as any).navigator?.platform?.startsWith("Win") ||
(globalThis as any).process?.platform?.startsWith("win") ||
false;