summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-04-16 06:40:30 +0100
committerGitHub <noreply@github.com>2020-04-16 01:40:30 -0400
commit5ac728a5f1af575d011c2143f5c9273b0fb4c5bb (patch)
treedfba0fdb3ba17989fd6c3af89ce17a0a71a4df0c /cli/js
parent6441852a1d5eef0d05ed172a00bef58ad5988842 (diff)
refactor(cli/js/ops/fs): Improve readdir() and FileInfo interfaces (#4763)
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/deno.ts5
-rw-r--r--cli/js/file_info.ts87
-rw-r--r--cli/js/lib.deno.ns.d.ts58
-rw-r--r--cli/js/ops/fs/read_dir.ts26
-rw-r--r--cli/js/ops/fs/stat.ts54
-rw-r--r--cli/js/tests/files_test.ts6
-rw-r--r--cli/js/tests/link_test.ts8
-rw-r--r--cli/js/tests/mkdir_test.ts2
-rw-r--r--cli/js/tests/read_dir_test.ts15
-rw-r--r--cli/js/tests/remove_test.ts40
-rw-r--r--cli/js/tests/rename_test.ts4
-rw-r--r--cli/js/tests/stat_test.ts48
-rw-r--r--cli/js/tests/symlink_test.ts8
-rw-r--r--cli/js/tests/test_util.ts2
14 files changed, 165 insertions, 198 deletions
diff --git a/cli/js/deno.ts b/cli/js/deno.ts
index ca323fc95..89795119b 100644
--- a/cli/js/deno.ts
+++ b/cli/js/deno.ts
@@ -23,7 +23,6 @@ export {
export { chdir, cwd } from "./ops/fs/dir.ts";
export { applySourceMap, formatDiagnostics } from "./ops/errors.ts";
export { errors } from "./errors.ts";
-export { FileInfo } from "./file_info.ts";
export {
File,
open,
@@ -97,7 +96,7 @@ export {
export { openPlugin } from "./plugins.ts";
export { kill } from "./ops/process.ts";
export { run, RunOptions, Process, ProcessStatus } from "./process.ts";
-export { readdirSync, readdir } from "./ops/fs/read_dir.ts";
+export { DirEntry, readdirSync, readdir } from "./ops/fs/read_dir.ts";
export { readFileSync, readFile } from "./read_file.ts";
export { readlinkSync, readlink } from "./ops/fs/read_link.ts";
export { realpathSync, realpath } from "./ops/fs/realpath.ts";
@@ -105,7 +104,7 @@ export { removeSync, remove, RemoveOptions } from "./ops/fs/remove.ts";
export { renameSync, rename } from "./ops/fs/rename.ts";
export { resources, close } from "./ops/resources.ts";
export { signal, signals, Signal, SignalStream } from "./signals.ts";
-export { statSync, lstatSync, stat, lstat } from "./ops/fs/stat.ts";
+export { FileInfo, statSync, lstatSync, stat, lstat } from "./ops/fs/stat.ts";
export { symlinkSync, symlink } from "./ops/fs/symlink.ts";
export { connectTLS, listenTLS } from "./tls.ts";
export { truncateSync, truncate } from "./ops/fs/truncate.ts";
diff --git a/cli/js/file_info.ts b/cli/js/file_info.ts
deleted file mode 100644
index 27df0bbb7..000000000
--- a/cli/js/file_info.ts
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { StatResponse } from "./ops/fs/stat.ts";
-import { build } from "./build.ts";
-
-export interface FileInfo {
- size: number;
- modified: number | null;
- accessed: number | null;
- created: number | null;
- name: string | null;
- dev: number | null;
- ino: number | null;
- mode: number | null;
- nlink: number | null;
- uid: number | null;
- gid: number | null;
- rdev: number | null;
- blksize: number | null;
- blocks: number | null;
- isFile(): boolean;
- isDirectory(): boolean;
- isSymlink(): boolean;
-}
-
-// @internal
-export class FileInfoImpl implements FileInfo {
- readonly #isFile: boolean;
- readonly #isDirectory: boolean;
- readonly #isSymlink: boolean;
- size: number;
- modified: number | null;
- accessed: number | null;
- created: number | null;
- name: string | null;
-
- dev: number | null;
- ino: number | null;
- mode: number | null;
- nlink: number | null;
- uid: number | null;
- gid: number | null;
- rdev: number | null;
- blksize: number | null;
- blocks: number | null;
-
- /* @internal */
- constructor(res: StatResponse) {
- const isUnix = build.os === "mac" || build.os === "linux";
- const modified = res.modified;
- const accessed = res.accessed;
- const created = res.created;
- const name = res.name;
- // Unix only
- const { dev, ino, mode, nlink, uid, gid, rdev, blksize, blocks } = res;
-
- this.#isFile = res.isFile;
- this.#isDirectory = res.isDirectory;
- this.#isSymlink = res.isSymlink;
- this.size = res.size;
- this.modified = modified ? modified : null;
- this.accessed = accessed ? accessed : null;
- this.created = created ? created : null;
- this.name = name ? name : null;
- // Only non-null if on Unix
- this.dev = isUnix ? dev : null;
- this.ino = isUnix ? ino : null;
- this.mode = isUnix ? mode : null;
- this.nlink = isUnix ? nlink : null;
- this.uid = isUnix ? uid : null;
- this.gid = isUnix ? gid : null;
- this.rdev = isUnix ? rdev : null;
- this.blksize = isUnix ? blksize : null;
- this.blocks = isUnix ? blocks : null;
- }
-
- isFile(): boolean {
- return this.#isFile;
- }
-
- isDirectory(): boolean {
- return this.#isDirectory;
- }
-
- isSymlink(): boolean {
- return this.#isSymlink;
- }
-}
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index 443952c96..0480d2613 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -1317,9 +1317,17 @@ declare namespace Deno {
export function readFile(path: string): Promise<Uint8Array>;
/** A FileInfo describes a file and is returned by `stat`, `lstat`,
- * `statSync`, `lstatSync`. A list of FileInfo is returned by `readdir`,
- * `readdirSync`. */
+ * `statSync`, `lstatSync`. */
export interface FileInfo {
+ /** True if this is info for a regular file. Mutually exclusive to
+ * `FileInfo.isDirectory` and `FileInfo.isSymlink`. */
+ isFile: boolean;
+ /** True if this is info for a regular directory. Mutually exclusive to
+ * `FileInfo.isFile` and `FileInfo.isSymlink`. */
+ isDirectory: boolean;
+ /** True if this is info for a symlink. Mutually exclusive to
+ * `FileInfo.isFile` and `FileInfo.isDirectory`. */
+ isSymlink: boolean;
/** The size of the file, in bytes. */
size: number;
/** The last modification time of the file. This corresponds to the `mtime`
@@ -1334,8 +1342,6 @@ declare namespace Deno {
* field from `stat` on Mac/BSD and `ftCreationTime` on Windows. This may not
* be available on all platforms. */
created: number | null;
- /** The file or directory name. */
- name: string | null;
/** ID of the device containing the file.
*
* _Linux/Mac OS only._ */
@@ -1373,15 +1379,6 @@ declare namespace Deno {
*
* _Linux/Mac OS only._ */
blocks: number | null;
- /** Returns whether this is info for a regular file. This result is mutually
- * exclusive to `FileInfo.isDirectory` and `FileInfo.isSymlink`. */
- isFile(): boolean;
- /** Returns whether this is info for a regular directory. This result is
- * mutually exclusive to `FileInfo.isFile` and `FileInfo.isSymlink`. */
- isDirectory(): boolean;
- /** Returns whether this is info for a symlink. This result is
- * mutually exclusive to `FileInfo.isFile` and `FileInfo.isDirectory`. */
- isSymlink(): boolean;
}
/** Returns absolute normalized path, with symbolic links resolved.
@@ -1408,28 +1405,33 @@ declare namespace Deno {
* Requires `allow-read` permission. */
export function realpath(path: string): Promise<string>;
- /** UNSTABLE: This API is likely to change to return an iterable object instead
- *
- * Synchronously reads the directory given by `path` and returns an array of
- * `Deno.FileInfo`.
+ export interface DirEntry extends FileInfo {
+ name: string;
+ }
+
+ /** Synchronously reads the directory given by `path` and returns an iterable
+ * of `Deno.DirEntry`.
*
- * const files = Deno.readdirSync("/");
+ * for (const dirEntry of Deno.readdirSync("/")) {
+ * console.log(dirEntry.name);
+ * }
*
* Throws error if `path` is not a directory.
*
* Requires `allow-read` permission. */
- export function readdirSync(path: string): FileInfo[];
+ export function readdirSync(path: string): Iterable<DirEntry>;
- /** UNSTABLE: This API is likely to change to return an `AsyncIterable`.
- *
- * Reads the directory given by `path` and resolves to an array of `Deno.FileInfo`.
+ /** Reads the directory given by `path` and returns an async iterable of
+ * `Deno.DirEntry`.
*
- * const files = await Deno.readdir("/");
+ * for await (const dirEntry of Deno.readdir("/")) {
+ * console.log(dirEntry.name);
+ * }
*
* Throws error if `path` is not a directory.
*
* Requires `allow-read` permission. */
- export function readdir(path: string): Promise<FileInfo[]>;
+ export function readdir(path: string): AsyncIterable<DirEntry>;
/** Synchronously copies the contents and permissions of one file to another
* specified path, by default creating a new file if needed, else overwriting.
@@ -1476,7 +1478,7 @@ declare namespace Deno {
* points to.
*
* const fileInfo = await Deno.lstat("hello.txt");
- * assert(fileInfo.isFile());
+ * assert(fileInfo.isFile);
*
* Requires `allow-read` permission. */
export function lstat(path: string): Promise<FileInfo>;
@@ -1486,7 +1488,7 @@ declare namespace Deno {
* what it points to..
*
* const fileInfo = Deno.lstatSync("hello.txt");
- * assert(fileInfo.isFile());
+ * assert(fileInfo.isFile);
*
* Requires `allow-read` permission. */
export function lstatSync(path: string): FileInfo;
@@ -1495,7 +1497,7 @@ declare namespace Deno {
* follow symlinks.
*
* const fileInfo = await Deno.stat("hello.txt");
- * assert(fileInfo.isFile());
+ * assert(fileInfo.isFile);
*
* Requires `allow-read` permission. */
export function stat(path: string): Promise<FileInfo>;
@@ -1504,7 +1506,7 @@ declare namespace Deno {
* always follow symlinks.
*
* const fileInfo = Deno.statSync("hello.txt");
- * assert(fileInfo.isFile());
+ * assert(fileInfo.isFile);
*
* Requires `allow-read` permission. */
export function statSync(path: string): FileInfo;
diff --git a/cli/js/ops/fs/read_dir.ts b/cli/js/ops/fs/read_dir.ts
index c48104d4b..29b8676ef 100644
--- a/cli/js/ops/fs/read_dir.ts
+++ b/cli/js/ops/fs/read_dir.ts
@@ -1,24 +1,32 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
-import { FileInfo, FileInfoImpl } from "../../file_info.ts";
-import { StatResponse } from "./stat.ts";
+import { FileInfo, StatResponse, parseFileInfo } from "./stat.ts";
+
+export interface DirEntry extends FileInfo {
+ name: string;
+}
interface ReadDirResponse {
entries: StatResponse[];
}
-function res(response: ReadDirResponse): FileInfo[] {
+function res(response: ReadDirResponse): DirEntry[] {
return response.entries.map(
- (statRes: StatResponse): FileInfo => {
- return new FileInfoImpl(statRes);
+ (statRes: StatResponse): DirEntry => {
+ return { ...parseFileInfo(statRes), name: statRes.name! };
}
);
}
-export function readdirSync(path: string): FileInfo[] {
- return res(sendSync("op_read_dir", { path }));
+export function readdirSync(path: string): Iterable<DirEntry> {
+ return res(sendSync("op_read_dir", { path }))[Symbol.iterator]();
}
-export async function readdir(path: string): Promise<FileInfo[]> {
- return res(await sendAsync("op_read_dir", { path }));
+export function readdir(path: string): AsyncIterable<DirEntry> {
+ const array = sendAsync("op_read_dir", { path }).then(res);
+ return {
+ async *[Symbol.asyncIterator](): AsyncIterableIterator<DirEntry> {
+ yield* await array;
+ },
+ };
}
diff --git a/cli/js/ops/fs/stat.ts b/cli/js/ops/fs/stat.ts
index 5d8860939..6b7e5ea93 100644
--- a/cli/js/ops/fs/stat.ts
+++ b/cli/js/ops/fs/stat.ts
@@ -1,6 +1,25 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
-import { FileInfo, FileInfoImpl } from "../../file_info.ts";
+import { build } from "../../build.ts";
+
+export interface FileInfo {
+ size: number;
+ modified: number | null;
+ accessed: number | null;
+ created: number | null;
+ dev: number | null;
+ ino: number | null;
+ mode: number | null;
+ nlink: number | null;
+ uid: number | null;
+ gid: number | null;
+ rdev: number | null;
+ blksize: number | null;
+ blocks: number | null;
+ isFile: boolean;
+ isDirectory: boolean;
+ isSymlink: boolean;
+}
export interface StatResponse {
isFile: boolean;
@@ -10,6 +29,7 @@ export interface StatResponse {
modified: number;
accessed: number;
created: number;
+ // Null for stat(), but exists for readdir().
name: string | null;
// Unix only members
dev: number;
@@ -23,12 +43,36 @@ export interface StatResponse {
blocks: number;
}
+// @internal
+export function parseFileInfo(response: StatResponse): FileInfo {
+ const isUnix = build.os === "mac" || build.os === "linux";
+ return {
+ isFile: response.isFile,
+ isDirectory: response.isDirectory,
+ isSymlink: response.isSymlink,
+ size: response.size,
+ modified: response.modified ? response.modified : null,
+ accessed: response.accessed ? response.accessed : null,
+ created: response.created ? response.created : null,
+ // Only non-null if on Unix
+ dev: isUnix ? response.dev : null,
+ ino: isUnix ? response.ino : null,
+ mode: isUnix ? response.mode : null,
+ nlink: isUnix ? response.nlink : null,
+ uid: isUnix ? response.uid : null,
+ gid: isUnix ? response.gid : null,
+ rdev: isUnix ? response.rdev : null,
+ blksize: isUnix ? response.blksize : null,
+ blocks: isUnix ? response.blocks : null,
+ };
+}
+
export async function lstat(path: string): Promise<FileInfo> {
const res = (await sendAsync("op_stat", {
path,
lstat: true,
})) as StatResponse;
- return new FileInfoImpl(res);
+ return parseFileInfo(res);
}
export function lstatSync(path: string): FileInfo {
@@ -36,7 +80,7 @@ export function lstatSync(path: string): FileInfo {
path,
lstat: true,
}) as StatResponse;
- return new FileInfoImpl(res);
+ return parseFileInfo(res);
}
export async function stat(path: string): Promise<FileInfo> {
@@ -44,7 +88,7 @@ export async function stat(path: string): Promise<FileInfo> {
path,
lstat: false,
})) as StatResponse;
- return new FileInfoImpl(res);
+ return parseFileInfo(res);
}
export function statSync(path: string): FileInfo {
@@ -52,5 +96,5 @@ export function statSync(path: string): FileInfo {
path,
lstat: false,
}) as StatResponse;
- return new FileInfoImpl(res);
+ return parseFileInfo(res);
}
diff --git a/cli/js/tests/files_test.ts b/cli/js/tests/files_test.ts
index f81ed3c47..1f7352afc 100644
--- a/cli/js/tests/files_test.ts
+++ b/cli/js/tests/files_test.ts
@@ -273,7 +273,7 @@ unitTest(
const filename = tempDir + "/test.txt";
const f = await Deno.create(filename);
let fileInfo = Deno.statSync(filename);
- assert(fileInfo.isFile());
+ assert(fileInfo.isFile);
assert(fileInfo.size === 0);
const enc = new TextEncoder();
const data = enc.encode("Hello");
@@ -297,7 +297,7 @@ unitTest(
let file = await Deno.open(filename, "w");
// assert file was created
let fileInfo = Deno.statSync(filename);
- assert(fileInfo.isFile());
+ assert(fileInfo.isFile);
assertEquals(fileInfo.size, 0);
// write some data
await file.write(data);
@@ -335,7 +335,7 @@ unitTest(
const seekPosition = 0;
// assert file was created
let fileInfo = Deno.statSync(filename);
- assert(fileInfo.isFile());
+ assert(fileInfo.isFile);
assertEquals(fileInfo.size, 0);
// write some data
await file.write(data);
diff --git a/cli/js/tests/link_test.ts b/cli/js/tests/link_test.ts
index e9f72ebef..c6ea4901e 100644
--- a/cli/js/tests/link_test.ts
+++ b/cli/js/tests/link_test.ts
@@ -31,8 +31,8 @@ unitTest(
// Remove oldname. File still accessible through newname.
Deno.removeSync(oldName);
const newNameStat = Deno.statSync(newName);
- assert(newNameStat.isFile());
- assert(!newNameStat.isSymlink()); // Not a symlink.
+ assert(newNameStat.isFile);
+ assert(!newNameStat.isSymlink); // Not a symlink.
assertEquals(
newData3,
new TextDecoder().decode(Deno.readFileSync(newName))
@@ -137,8 +137,8 @@ unitTest(
// Remove oldname. File still accessible through newname.
Deno.removeSync(oldName);
const newNameStat = Deno.statSync(newName);
- assert(newNameStat.isFile());
- assert(!newNameStat.isSymlink()); // Not a symlink.
+ assert(newNameStat.isFile);
+ assert(!newNameStat.isSymlink); // Not a symlink.
assertEquals(
newData3,
new TextDecoder().decode(Deno.readFileSync(newName))
diff --git a/cli/js/tests/mkdir_test.ts b/cli/js/tests/mkdir_test.ts
index 5823d6e38..20120f6b3 100644
--- a/cli/js/tests/mkdir_test.ts
+++ b/cli/js/tests/mkdir_test.ts
@@ -3,7 +3,7 @@ import { unitTest, assert, assertEquals, assertThrows } from "./test_util.ts";
function assertDirectory(path: string, mode?: number): void {
const info = Deno.lstatSync(path);
- assert(info.isDirectory());
+ assert(info.isDirectory);
if (Deno.build.os !== "win" && mode !== undefined) {
assertEquals(info.mode! & 0o777, mode & ~Deno.umask());
}
diff --git a/cli/js/tests/read_dir_test.ts b/cli/js/tests/read_dir_test.ts
index 95936c645..2c7f42103 100644
--- a/cli/js/tests/read_dir_test.ts
+++ b/cli/js/tests/read_dir_test.ts
@@ -1,14 +1,12 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { unitTest, assert, assertEquals } from "./test_util.ts";
-type FileInfo = Deno.FileInfo;
-
-function assertSameContent(files: FileInfo[]): void {
+function assertSameContent(files: Deno.DirEntry[]): void {
let counter = 0;
for (const file of files) {
if (file.name === "subdir") {
- assert(file.isDirectory());
+ assert(file.isDirectory);
counter++;
}
@@ -22,7 +20,7 @@ function assertSameContent(files: FileInfo[]): void {
}
unitTest({ perms: { read: true } }, function readdirSyncSuccess(): void {
- const files = Deno.readdirSync("cli/tests/");
+ const files = [...Deno.readdirSync("cli/tests/")];
assertSameContent(files);
});
@@ -68,7 +66,10 @@ unitTest({ perms: { read: true } }, function readdirSyncNotFound(): void {
unitTest({ perms: { read: true } }, async function readdirSuccess(): Promise<
void
> {
- const files = await Deno.readdir("cli/tests/");
+ const files = [];
+ for await (const dirEntry of Deno.readdir("cli/tests/")) {
+ files.push(dirEntry);
+ }
assertSameContent(files);
});
@@ -77,7 +78,7 @@ unitTest({ perms: { read: false } }, async function readdirPerm(): Promise<
> {
let caughtError = false;
try {
- await Deno.readdir("tests/");
+ await Deno.readdir("tests/")[Symbol.asyncIterator]().next();
} catch (e) {
caughtError = true;
assert(e instanceof Deno.errors.PermissionDenied);
diff --git a/cli/js/tests/remove_test.ts b/cli/js/tests/remove_test.ts
index 209558de7..b6f8aa320 100644
--- a/cli/js/tests/remove_test.ts
+++ b/cli/js/tests/remove_test.ts
@@ -10,7 +10,7 @@ unitTest(
const path = Deno.makeTempDirSync() + "/subdir";
Deno.mkdirSync(path);
const pathInfo = Deno.statSync(path);
- assert(pathInfo.isDirectory()); // check exist first
+ assert(pathInfo.isDirectory); // check exist first
Deno.removeSync(path); // remove
// We then check again after remove
let err;
@@ -33,7 +33,7 @@ unitTest(
const filename = Deno.makeTempDirSync() + "/test.txt";
Deno.writeFileSync(filename, data, { mode: 0o666 });
const fileInfo = Deno.statSync(filename);
- assert(fileInfo.isFile()); // check exist first
+ assert(fileInfo.isFile); // check exist first
Deno.removeSync(filename); // remove
// We then check again after remove
let err;
@@ -56,9 +56,9 @@ unitTest(
Deno.mkdirSync(path, { recursive: true });
Deno.mkdirSync(subPath);
const pathInfo = Deno.statSync(path);
- assert(pathInfo.isDirectory()); // check exist first
+ assert(pathInfo.isDirectory); // check exist first
const subPathInfo = Deno.statSync(subPath);
- assert(subPathInfo.isDirectory()); // check exist first
+ assert(subPathInfo.isDirectory); // check exist first
let err;
try {
// Should not be able to recursively remove
@@ -94,7 +94,7 @@ unitTest(
assertEquals(errOnWindows.message, "not implemented");
} else {
const pathInfo = Deno.lstatSync(danglingSymlinkPath);
- assert(pathInfo.isSymlink());
+ assert(pathInfo.isSymlink);
Deno.removeSync(danglingSymlinkPath);
let err;
try {
@@ -127,7 +127,7 @@ unitTest(
assertEquals(errOnWindows.message, "not implemented");
} else {
const symlinkPathInfo = Deno.statSync(validSymlinkPath);
- assert(symlinkPathInfo.isFile());
+ assert(symlinkPathInfo.isFile);
Deno.removeSync(validSymlinkPath);
let err;
try {
@@ -159,7 +159,7 @@ unitTest(
let path = Deno.makeTempDirSync() + "/dir/subdir";
Deno.mkdirSync(path, { recursive: true });
let pathInfo = Deno.statSync(path);
- assert(pathInfo.isDirectory()); // check exist first
+ assert(pathInfo.isDirectory); // check exist first
Deno.removeSync(path, { recursive: true }); // remove
// We then check again after remove
let err;
@@ -177,9 +177,9 @@ unitTest(
Deno.mkdirSync(path, { recursive: true });
Deno.mkdirSync(subPath);
pathInfo = Deno.statSync(path);
- assert(pathInfo.isDirectory()); // check exist first
+ assert(pathInfo.isDirectory); // check exist first
const subPathInfo = Deno.statSync(subPath);
- assert(subPathInfo.isDirectory()); // check exist first
+ assert(subPathInfo.isDirectory); // check exist first
Deno.removeSync(path, { recursive: true }); // remove
// We then check parent directory again after remove
try {
@@ -201,7 +201,7 @@ unitTest(
const filename = Deno.makeTempDirSync() + "/test.txt";
Deno.writeFileSync(filename, data, { mode: 0o666 });
const fileInfo = Deno.statSync(filename);
- assert(fileInfo.isFile()); // check exist first
+ assert(fileInfo.isFile); // check exist first
Deno.removeSync(filename, { recursive: true }); // remove
// We then check again after remove
let err;
@@ -247,7 +247,7 @@ unitTest(
const path = Deno.makeTempDirSync() + "/dir/subdir";
Deno.mkdirSync(path, { recursive: true });
const pathInfo = Deno.statSync(path);
- assert(pathInfo.isDirectory()); // check exist first
+ assert(pathInfo.isDirectory); // check exist first
await Deno.remove(path); // remove
// We then check again after remove
let err;
@@ -270,7 +270,7 @@ unitTest(
const filename = Deno.makeTempDirSync() + "/test.txt";
Deno.writeFileSync(filename, data, { mode: 0o666 });
const fileInfo = Deno.statSync(filename);
- assert(fileInfo.isFile()); // check exist first
+ assert(fileInfo.isFile); // check exist first
await Deno.remove(filename); // remove
// We then check again after remove
let err;
@@ -293,9 +293,9 @@ unitTest(
Deno.mkdirSync(path, { recursive: true });
Deno.mkdirSync(subPath);
const pathInfo = Deno.statSync(path);
- assert(pathInfo.isDirectory()); // check exist first
+ assert(pathInfo.isDirectory); // check exist first
const subPathInfo = Deno.statSync(subPath);
- assert(subPathInfo.isDirectory()); // check exist first
+ assert(subPathInfo.isDirectory); // check exist first
let err;
try {
// Should not be able to recursively remove
@@ -330,7 +330,7 @@ unitTest(
assertEquals(errOnWindows.message, "not implemented");
} else {
const pathInfo = Deno.lstatSync(danglingSymlinkPath);
- assert(pathInfo.isSymlink());
+ assert(pathInfo.isSymlink);
await Deno.remove(danglingSymlinkPath);
let err;
try {
@@ -363,7 +363,7 @@ unitTest(
assertEquals(errOnWindows.message, "not implemented");
} else {
const symlinkPathInfo = Deno.statSync(validSymlinkPath);
- assert(symlinkPathInfo.isFile());
+ assert(symlinkPathInfo.isFile);
await Deno.remove(validSymlinkPath);
let err;
try {
@@ -397,7 +397,7 @@ unitTest(
let path = Deno.makeTempDirSync() + "/dir/subdir";
Deno.mkdirSync(path, { recursive: true });
let pathInfo = Deno.statSync(path);
- assert(pathInfo.isDirectory()); // check exist first
+ assert(pathInfo.isDirectory); // check exist first
await Deno.remove(path, { recursive: true }); // remove
// We then check again after remove
let err;
@@ -415,9 +415,9 @@ unitTest(
Deno.mkdirSync(path, { recursive: true });
Deno.mkdirSync(subPath);
pathInfo = Deno.statSync(path);
- assert(pathInfo.isDirectory()); // check exist first
+ assert(pathInfo.isDirectory); // check exist first
const subPathInfo = Deno.statSync(subPath);
- assert(subPathInfo.isDirectory()); // check exist first
+ assert(subPathInfo.isDirectory); // check exist first
await Deno.remove(path, { recursive: true }); // remove
// We then check parent directory again after remove
try {
@@ -439,7 +439,7 @@ unitTest(
const filename = Deno.makeTempDirSync() + "/test.txt";
Deno.writeFileSync(filename, data, { mode: 0o666 });
const fileInfo = Deno.statSync(filename);
- assert(fileInfo.isFile()); // check exist first
+ assert(fileInfo.isFile); // check exist first
await Deno.remove(filename, { recursive: true }); // remove
// We then check again after remove
let err;
diff --git a/cli/js/tests/rename_test.ts b/cli/js/tests/rename_test.ts
index 45f6d709e..cbb3a55ce 100644
--- a/cli/js/tests/rename_test.ts
+++ b/cli/js/tests/rename_test.ts
@@ -16,12 +16,12 @@ function assertMissing(path: string): void {
function assertFile(path: string): void {
const info = Deno.lstatSync(path);
- assert(info.isFile());
+ assert(info.isFile);
}
function assertDirectory(path: string, mode?: number): void {
const info = Deno.lstatSync(path);
- assert(info.isDirectory());
+ assert(info.isDirectory);
if (Deno.build.os !== "win" && mode !== undefined) {
assertEquals(info.mode! & 0o777, mode & ~Deno.umask());
}
diff --git a/cli/js/tests/stat_test.ts b/cli/js/tests/stat_test.ts
index 78582900e..e4f4ae61e 100644
--- a/cli/js/tests/stat_test.ts
+++ b/cli/js/tests/stat_test.ts
@@ -5,16 +5,16 @@ import { unitTest, assert, assertEquals } from "./test_util.ts";
// to create temp files.
unitTest({ perms: { read: true } }, function statSyncSuccess(): void {
const packageInfo = Deno.statSync("README.md");
- assert(packageInfo.isFile());
- assert(!packageInfo.isSymlink());
+ assert(packageInfo.isFile);
+ assert(!packageInfo.isSymlink);
const modulesInfo = Deno.statSync("cli/tests/symlink_to_subdir");
- assert(modulesInfo.isDirectory());
- assert(!modulesInfo.isSymlink());
+ assert(modulesInfo.isDirectory);
+ assert(!modulesInfo.isSymlink);
const testsInfo = Deno.statSync("cli/tests");
- assert(testsInfo.isDirectory());
- assert(!testsInfo.isSymlink());
+ assert(testsInfo.isDirectory);
+ assert(!testsInfo.isSymlink);
});
unitTest({ perms: { read: false } }, function statSyncPerm(): void {
@@ -45,16 +45,16 @@ unitTest({ perms: { read: true } }, function statSyncNotFound(): void {
unitTest({ perms: { read: true } }, function lstatSyncSuccess(): void {
const packageInfo = Deno.lstatSync("README.md");
- assert(packageInfo.isFile());
- assert(!packageInfo.isSymlink());
+ assert(packageInfo.isFile);
+ assert(!packageInfo.isSymlink);
const modulesInfo = Deno.lstatSync("cli/tests/symlink_to_subdir");
- assert(!modulesInfo.isDirectory());
- assert(modulesInfo.isSymlink());
+ assert(!modulesInfo.isDirectory);
+ assert(modulesInfo.isSymlink);
const coreInfo = Deno.lstatSync("core");
- assert(coreInfo.isDirectory());
- assert(!coreInfo.isSymlink());
+ assert(coreInfo.isDirectory);
+ assert(!coreInfo.isSymlink);
});
unitTest({ perms: { read: false } }, function lstatSyncPerm(): void {
@@ -87,16 +87,16 @@ unitTest({ perms: { read: true } }, async function statSuccess(): Promise<
void
> {
const packageInfo = await Deno.stat("README.md");
- assert(packageInfo.isFile());
- assert(!packageInfo.isSymlink());
+ assert(packageInfo.isFile);
+ assert(!packageInfo.isSymlink);
const modulesInfo = await Deno.stat("cli/tests/symlink_to_subdir");
- assert(modulesInfo.isDirectory());
- assert(!modulesInfo.isSymlink());
+ assert(modulesInfo.isDirectory);
+ assert(!modulesInfo.isSymlink);
const testsInfo = await Deno.stat("cli/tests");
- assert(testsInfo.isDirectory());
- assert(!testsInfo.isSymlink());
+ assert(testsInfo.isDirectory);
+ assert(!testsInfo.isSymlink);
});
unitTest({ perms: { read: false } }, async function statPerm(): Promise<void> {
@@ -131,16 +131,16 @@ unitTest({ perms: { read: true } }, async function lstatSuccess(): Promise<
void
> {
const packageInfo = await Deno.lstat("README.md");
- assert(packageInfo.isFile());
- assert(!packageInfo.isSymlink());
+ assert(packageInfo.isFile);
+ assert(!packageInfo.isSymlink);
const modulesInfo = await Deno.lstat("cli/tests/symlink_to_subdir");
- assert(!modulesInfo.isDirectory());
- assert(modulesInfo.isSymlink());
+ assert(!modulesInfo.isDirectory);
+ assert(modulesInfo.isSymlink);
const coreInfo = await Deno.lstat("core");
- assert(coreInfo.isDirectory());
- assert(!coreInfo.isSymlink());
+ assert(coreInfo.isDirectory);
+ assert(!coreInfo.isSymlink);
});
unitTest({ perms: { read: false } }, async function lstatPerm(): Promise<void> {
diff --git a/cli/js/tests/symlink_test.ts b/cli/js/tests/symlink_test.ts
index 25533fc64..0dde4fbad 100644
--- a/cli/js/tests/symlink_test.ts
+++ b/cli/js/tests/symlink_test.ts
@@ -21,8 +21,8 @@ unitTest(
} else {
const newNameInfoLStat = Deno.lstatSync(newname);
const newNameInfoStat = Deno.statSync(newname);
- assert(newNameInfoLStat.isSymlink());
- assert(newNameInfoStat.isDirectory());
+ assert(newNameInfoLStat.isSymlink);
+ assert(newNameInfoStat.isDirectory);
}
}
);
@@ -79,8 +79,8 @@ unitTest(
} else {
const newNameInfoLStat = Deno.lstatSync(newname);
const newNameInfoStat = Deno.statSync(newname);
- assert(newNameInfoLStat.isSymlink());
- assert(newNameInfoStat.isDirectory());
+ assert(newNameInfoLStat.isSymlink);
+ assert(newNameInfoStat.isDirectory);
}
}
);
diff --git a/cli/js/tests/test_util.ts b/cli/js/tests/test_util.ts
index a3b4b6ce4..fc0b8a390 100644
--- a/cli/js/tests/test_util.ts
+++ b/cli/js/tests/test_util.ts
@@ -327,7 +327,7 @@ unitTest(function permissionsMatches(): void {
unitTest(
{ perms: { read: true } },
function assertAllUnitTestFilesImported(): void {
- const directoryTestFiles = Deno.readdirSync("./cli/js/tests/")
+ const directoryTestFiles = [...Deno.readdirSync("./cli/js/tests/")]
.map((k) => k.name)
.filter(
(file) =>