Skip to content

Commit

Permalink
refactor(fs): fix uncaught errors in browsers (#6135)
Browse files Browse the repository at this point in the history
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
  • Loading branch information
QuixThe2nd and kt3k authored Oct 24, 2024
1 parent e3974ea commit c0427a0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion fs/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { getFileInfoType } from "./_get_file_info_type.ts";
import { toPathString } from "./_to_path_string.ts";
import { isSubdir } from "./_is_subdir.ts";

const isWindows = Deno.build.os === "windows";
// deno-lint-ignore no-explicit-any
const isWindows = (globalThis as any).Deno?.build.os === "windows";

/** Options for {@linkcode copy} and {@linkcode copySync}. */
export interface CopyOptions {
Expand Down
3 changes: 2 additions & 1 deletion fs/ensure_symlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { getFileInfoType, type PathType } from "./_get_file_info_type.ts";
import { toPathString } from "./_to_path_string.ts";

const isWindows = Deno.build.os === "windows";
// deno-lint-ignore no-explicit-any
const isWindows = (globalThis as any).Deno?.build.os === "windows";

function resolveSymlinkTarget(target: string | URL, linkName: string | URL) {
if (typeof target !== "string") return target; // URL is always absolute path
Expand Down
4 changes: 3 additions & 1 deletion fs/eol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const CRLF = "\r\n" as const;
* EOL; // "\n" on POSIX platforms and "\r\n" on Windows
* ```
*/
export const EOL: "\n" | "\r\n" = Deno?.build.os === "windows" ? CRLF : LF;
export const EOL: "\n" | "\r\n" =
// deno-lint-ignore no-explicit-any
(globalThis as any).Deno?.build.os === "windows" ? CRLF : LF;

const regDetect = /(?:\r?\n)/g;

Expand Down
3 changes: 2 additions & 1 deletion fs/expand_glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {

export type { GlobOptions, WalkEntry };

const isWindows = Deno.build.os === "windows";
// deno-lint-ignore no-explicit-any
const isWindows = (globalThis as any).Deno?.build.os === "windows";

/** Options for {@linkcode expandGlob} and {@linkcode expandGlobSync}. */
export interface ExpandGlobOptions extends Omit<GlobOptions, "os"> {
Expand Down

0 comments on commit c0427a0

Please sign in to comment.