Skip to content

Commit

Permalink
fix for Deno 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Dec 12, 2024
1 parent dafa9a3 commit 306bb5c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion fs/_to_file_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { isWindows } from "./_utils.ts";
export function toFileInfo(s: import("node:fs").Stats): FileInfo {
return {
atime: s.atime,
ctime: s.ctime,
// TODO(kt3k): uncomment this when we drop support for Deno 1.x
// ctime: s.ctime,
birthtime: s.birthtime,
blksize: isWindows ? null : s.blksize,
blocks: isWindows ? null : s.blocks,
Expand Down
10 changes: 7 additions & 3 deletions fs/_utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-explicit-any no-process-globals
// deno-lint-ignore-file no-explicit-any

/**
* True if the runtime is Deno, false otherwise.
Expand All @@ -15,8 +15,12 @@ export const isWindows = checkWindows();
function checkWindows(): boolean {
if (typeof navigator !== "undefined" && (navigator as any).platform) {
return (navigator as any).platform.startsWith("Win");

Check warning on line 17 in fs/_utils.ts

View check run for this annotation

Codecov / codecov/patch

fs/_utils.ts#L17

Added line #L17 was not covered by tests
} else if (typeof process !== "undefined") {
return process.platform === "win32";
} else if (typeof (globalThis as any).process !== "undefined") {
return (globalThis as any).platform === "win32";
}
return false;
}

export function getNodeFsPromises() {
return (globalThis as any).process.getBuiltinModule("node:fs/promises");
}

Check warning on line 26 in fs/_utils.ts

View check run for this annotation

Codecov / codecov/patch

fs/_utils.ts#L24-L26

Added lines #L24 - L26 were not covered by tests
5 changes: 2 additions & 3 deletions fs/unstable_stat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-process-globals

import { isDeno } from "./_utils.ts";
import { getNodeFsPromises, isDeno } from "./_utils.ts";
import { mapError } from "./_map_error.ts";
import { toFileInfo } from "./_to_file_info.ts";
import type { FileInfo } from "./unstable_types.ts";
Expand All @@ -25,7 +24,7 @@ export async function stat(path: string | URL): Promise<FileInfo> {
if (isDeno) {
return Deno.stat(path);
} else {
const fsPromises = process.getBuiltinModule("node:fs/promises");
const fsPromises = getNodeFsPromises();
try {
const stat = await fsPromises.stat(path);
return toFileInfo(stat);
Expand Down
3 changes: 2 additions & 1 deletion fs/unstable_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export interface FileInfo {
/** The last change time of the file. This corresponds to the `ctime`
* field from `stat` on Mac/BSD and `ChangeTime` on Windows. This may
* not be available on all platforms. */
ctime: Date | null;
// TODO(kt3k): uncomment this when we drop support for Deno 1.x
// ctime: Date | null;
/** ID of the device containing the file. */
dev: number;
/** Inode number.
Expand Down

0 comments on commit 306bb5c

Please sign in to comment.