summaryrefslogtreecommitdiff
path: root/std/fs
diff options
context:
space:
mode:
Diffstat (limited to 'std/fs')
-rw-r--r--std/fs/empty_dir.ts14
-rw-r--r--std/fs/ensure_dir.ts9
-rw-r--r--std/fs/ensure_file.ts9
-rw-r--r--std/fs/exists.ts5
-rw-r--r--std/fs/expand_glob.ts10
-rw-r--r--std/fs/expand_glob_test.ts7
-rw-r--r--std/fs/walk.ts9
-rw-r--r--std/fs/walk_test.ts34
8 files changed, 44 insertions, 53 deletions
diff --git a/std/fs/empty_dir.ts b/std/fs/empty_dir.ts
index 2f5d2deeb..dea09b5c0 100644
--- a/std/fs/empty_dir.ts
+++ b/std/fs/empty_dir.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { join } from "../path/mod.ts";
-const { readDir, readDirSync, mkdir, mkdirSync, remove, removeSync } = Deno;
+
/**
* Ensures that a directory is empty.
* Deletes directory contents if the directory is not empty.
@@ -11,7 +11,7 @@ const { readDir, readDirSync, mkdir, mkdirSync, remove, removeSync } = Deno;
export async function emptyDir(dir: string): Promise<void> {
try {
const items = [];
- for await (const dirEntry of readDir(dir)) {
+ for await (const dirEntry of Deno.readDir(dir)) {
items.push(dirEntry);
}
@@ -19,7 +19,7 @@ export async function emptyDir(dir: string): Promise<void> {
const item = items.shift();
if (item && item.name) {
const filepath = join(dir, item.name);
- await remove(filepath, { recursive: true });
+ await Deno.remove(filepath, { recursive: true });
}
}
} catch (err) {
@@ -28,7 +28,7 @@ export async function emptyDir(dir: string): Promise<void> {
}
// if not exist. then create it
- await mkdir(dir, { recursive: true });
+ await Deno.mkdir(dir, { recursive: true });
}
}
@@ -41,14 +41,14 @@ export async function emptyDir(dir: string): Promise<void> {
*/
export function emptyDirSync(dir: string): void {
try {
- const items = [...readDirSync(dir)];
+ const items = [...Deno.readDirSync(dir)];
// If the directory exists, remove all entries inside it.
while (items.length) {
const item = items.shift();
if (item && item.name) {
const filepath = join(dir, item.name);
- removeSync(filepath, { recursive: true });
+ Deno.removeSync(filepath, { recursive: true });
}
}
} catch (err) {
@@ -56,7 +56,7 @@ export function emptyDirSync(dir: string): void {
throw err;
}
// if not exist. then create it
- mkdirSync(dir, { recursive: true });
+ Deno.mkdirSync(dir, { recursive: true });
return;
}
}
diff --git a/std/fs/ensure_dir.ts b/std/fs/ensure_dir.ts
index 43b230ae1..961476028 100644
--- a/std/fs/ensure_dir.ts
+++ b/std/fs/ensure_dir.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { getFileInfoType } from "./_util.ts";
-const { lstat, lstatSync, mkdir, mkdirSync } = Deno;
/**
* Ensures that the directory exists.
@@ -9,7 +8,7 @@ const { lstat, lstatSync, mkdir, mkdirSync } = Deno;
*/
export async function ensureDir(dir: string): Promise<void> {
try {
- const fileInfo = await lstat(dir);
+ const fileInfo = await Deno.lstat(dir);
if (!fileInfo.isDirectory) {
throw new Error(
`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`
@@ -18,7 +17,7 @@ export async function ensureDir(dir: string): Promise<void> {
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
// if dir not exists. then create it.
- await mkdir(dir, { recursive: true });
+ await Deno.mkdir(dir, { recursive: true });
return;
}
throw err;
@@ -32,7 +31,7 @@ export async function ensureDir(dir: string): Promise<void> {
*/
export function ensureDirSync(dir: string): void {
try {
- const fileInfo = lstatSync(dir);
+ const fileInfo = Deno.lstatSync(dir);
if (!fileInfo.isDirectory) {
throw new Error(
`Ensure path exists, expected 'dir', got '${getFileInfoType(fileInfo)}'`
@@ -41,7 +40,7 @@ export function ensureDirSync(dir: string): void {
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
// if dir not exists. then create it.
- mkdirSync(dir, { recursive: true });
+ Deno.mkdirSync(dir, { recursive: true });
return;
}
throw err;
diff --git a/std/fs/ensure_file.ts b/std/fs/ensure_file.ts
index a1476b657..b36379b3d 100644
--- a/std/fs/ensure_file.ts
+++ b/std/fs/ensure_file.ts
@@ -2,7 +2,6 @@
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { getFileInfoType } from "./_util.ts";
-const { lstat, lstatSync, writeFile, writeFileSync } = Deno;
/**
* Ensures that the file exists.
@@ -15,7 +14,7 @@ const { lstat, lstatSync, writeFile, writeFileSync } = Deno;
export async function ensureFile(filePath: string): Promise<void> {
try {
// if file exists
- const stat = await lstat(filePath);
+ const stat = await Deno.lstat(filePath);
if (!stat.isFile) {
throw new Error(
`Ensure path exists, expected 'file', got '${getFileInfoType(stat)}'`
@@ -27,7 +26,7 @@ export async function ensureFile(filePath: string): Promise<void> {
// ensure dir exists
await ensureDir(path.dirname(filePath));
// create file
- await writeFile(filePath, new Uint8Array());
+ await Deno.writeFile(filePath, new Uint8Array());
return;
}
@@ -46,7 +45,7 @@ export async function ensureFile(filePath: string): Promise<void> {
export function ensureFileSync(filePath: string): void {
try {
// if file exists
- const stat = lstatSync(filePath);
+ const stat = Deno.lstatSync(filePath);
if (!stat.isFile) {
throw new Error(
`Ensure path exists, expected 'file', got '${getFileInfoType(stat)}'`
@@ -58,7 +57,7 @@ export function ensureFileSync(filePath: string): void {
// ensure dir exists
ensureDirSync(path.dirname(filePath));
// create file
- writeFileSync(filePath, new Uint8Array());
+ Deno.writeFileSync(filePath, new Uint8Array());
return;
}
throw err;
diff --git a/std/fs/exists.ts b/std/fs/exists.ts
index f9e5a0925..a79455b2d 100644
--- a/std/fs/exists.ts
+++ b/std/fs/exists.ts
@@ -1,11 +1,10 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { lstat, lstatSync } = Deno;
/**
* Test whether or not the given path exists by checking with the file system
*/
export async function exists(filePath: string): Promise<boolean> {
try {
- await lstat(filePath);
+ await Deno.lstat(filePath);
return true;
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
@@ -21,7 +20,7 @@ export async function exists(filePath: string): Promise<boolean> {
*/
export function existsSync(filePath: string): boolean {
try {
- lstatSync(filePath);
+ Deno.lstatSync(filePath);
return true;
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
diff --git a/std/fs/expand_glob.ts b/std/fs/expand_glob.ts
index 4b7b11885..949f58f92 100644
--- a/std/fs/expand_glob.ts
+++ b/std/fs/expand_glob.ts
@@ -15,8 +15,6 @@ import {
walkSync,
} from "./walk.ts";
import { assert } from "../_util/assert.ts";
-const { cwd } = Deno;
-type FileInfo = Deno.FileInfo;
const isWindows = Deno.build.os == "windows";
@@ -68,7 +66,7 @@ function comparePath(a: WalkEntry, b: WalkEntry): number {
export async function* expandGlob(
glob: string,
{
- root = cwd(),
+ root = Deno.cwd(),
exclude = [],
includeDirs = true,
extended = false,
@@ -78,7 +76,7 @@ export async function* expandGlob(
const globOptions: GlobOptions = { extended, globstar };
const absRoot = isAbsolute(root)
? normalize(root)
- : joinGlobs([cwd(), root], globOptions);
+ : joinGlobs([Deno.cwd(), root], globOptions);
const resolveFromRoot = (path: string): string =>
isAbsolute(path)
? normalize(path)
@@ -167,7 +165,7 @@ export async function* expandGlob(
export function* expandGlobSync(
glob: string,
{
- root = cwd(),
+ root = Deno.cwd(),
exclude = [],
includeDirs = true,
extended = false,
@@ -177,7 +175,7 @@ export function* expandGlobSync(
const globOptions: GlobOptions = { extended, globstar };
const absRoot = isAbsolute(root)
? normalize(root)
- : joinGlobs([cwd(), root], globOptions);
+ : joinGlobs([Deno.cwd(), root], globOptions);
const resolveFromRoot = (path: string): string =>
isAbsolute(path)
? normalize(path)
diff --git a/std/fs/expand_glob_test.ts b/std/fs/expand_glob_test.ts
index 7d60d024e..1eec4df42 100644
--- a/std/fs/expand_glob_test.ts
+++ b/std/fs/expand_glob_test.ts
@@ -1,4 +1,3 @@
-const { cwd, execPath, run } = Deno;
import { decode } from "../encoding/utf8.ts";
import {
assert,
@@ -32,7 +31,7 @@ async function expandGlobArray(
);
pathsSync.sort();
assertEquals(paths, pathsSync);
- const root = normalize(options.root || cwd());
+ const root = normalize(options.root || Deno.cwd());
for (const path of paths) {
assert(path.startsWith(root));
}
@@ -118,8 +117,8 @@ Deno.test("expandGlobIncludeDirs", async function (): Promise<void> {
Deno.test("expandGlobPermError", async function (): Promise<void> {
const exampleUrl = new URL("testdata/expand_wildcard.js", import.meta.url);
- const p = run({
- cmd: [execPath(), "run", "--unstable", exampleUrl.toString()],
+ const p = Deno.run({
+ cmd: [Deno.execPath(), "run", "--unstable", exampleUrl.toString()],
stdin: "null",
stdout: "piped",
stderr: "piped",
diff --git a/std/fs/walk.ts b/std/fs/walk.ts
index 553e52b2e..0292b77ef 100644
--- a/std/fs/walk.ts
+++ b/std/fs/walk.ts
@@ -3,12 +3,11 @@
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
import { assert } from "../_util/assert.ts";
import { basename, join, normalize } from "../path/mod.ts";
-const { readDir, readDirSync, stat, statSync } = Deno;
export function createWalkEntrySync(path: string): WalkEntry {
path = normalize(path);
const name = basename(path);
- const info = statSync(path);
+ const info = Deno.statSync(path);
return {
path,
name,
@@ -21,7 +20,7 @@ export function createWalkEntrySync(path: string): WalkEntry {
export async function createWalkEntry(path: string): Promise<WalkEntry> {
path = normalize(path);
const name = basename(path);
- const info = await stat(path);
+ const info = await Deno.stat(path);
return {
path,
name,
@@ -103,7 +102,7 @@ export async function* walk(
if (maxDepth < 1 || !include(root, undefined, undefined, skip)) {
return;
}
- for await (const entry of readDir(root)) {
+ for await (const entry of Deno.readDir(root)) {
if (entry.isSymlink) {
if (followSymlinks) {
// TODO(ry) Re-enable followSymlinks.
@@ -156,7 +155,7 @@ export function* walkSync(
if (maxDepth < 1 || !include(root, undefined, undefined, skip)) {
return;
}
- for (const entry of readDirSync(root)) {
+ for (const entry of Deno.readDirSync(root)) {
if (entry.isSymlink) {
if (followSymlinks) {
throw new Error("unimplemented");
diff --git a/std/fs/walk_test.ts b/std/fs/walk_test.ts
index 8bd4577b9..e992aebcf 100644
--- a/std/fs/walk_test.ts
+++ b/std/fs/walk_test.ts
@@ -1,5 +1,3 @@
-const { cwd, chdir, makeTempDir, mkdir, create, symlink } = Deno;
-const { remove } = Deno;
import { walk, walkSync, WalkOptions, WalkEntry } from "./walk.ts";
import { assert, assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
@@ -10,15 +8,15 @@ export function testWalk(
): void {
const name = t.name;
async function fn(): Promise<void> {
- const origCwd = cwd();
- const d = await makeTempDir();
- chdir(d);
+ const origCwd = Deno.cwd();
+ const d = await Deno.makeTempDir();
+ Deno.chdir(d);
try {
await setup(d);
await t();
} finally {
- chdir(origCwd);
- await remove(d, { recursive: true });
+ Deno.chdir(origCwd);
+ await Deno.remove(d, { recursive: true });
}
}
Deno.test({ ignore, name: `[walk] ${name}`, fn });
@@ -44,7 +42,7 @@ export async function walkArray(
}
export async function touch(path: string): Promise<void> {
- const f = await create(path);
+ const f = await Deno.create(path);
f.close();
}
@@ -56,7 +54,7 @@ function assertReady(expectedLength: number): void {
testWalk(
async (d: string): Promise<void> => {
- await mkdir(d + "/empty");
+ await Deno.mkdir(d + "/empty");
},
async function emptyDir(): Promise<void> {
const arr = await walkArray(".");
@@ -93,7 +91,7 @@ testWalk(
testWalk(
async (d: string): Promise<void> => {
- await mkdir(d + "/a");
+ await Deno.mkdir(d + "/a");
await touch(d + "/a/x");
},
async function nestedSingleFile(): Promise<void> {
@@ -104,7 +102,7 @@ testWalk(
testWalk(
async (d: string): Promise<void> => {
- await mkdir(d + "/a/b/c/d", { recursive: true });
+ await Deno.mkdir(d + "/a/b/c/d", { recursive: true });
await touch(d + "/a/b/c/d/x");
},
async function depth(): Promise<void> {
@@ -119,7 +117,7 @@ testWalk(
testWalk(
async (d: string): Promise<void> => {
await touch(d + "/a");
- await mkdir(d + "/b");
+ await Deno.mkdir(d + "/b");
await touch(d + "/b/c");
},
async function includeDirs(): Promise<void> {
@@ -132,7 +130,7 @@ testWalk(
testWalk(
async (d: string): Promise<void> => {
await touch(d + "/a");
- await mkdir(d + "/b");
+ await Deno.mkdir(d + "/b");
await touch(d + "/b/c");
},
async function includeFiles(): Promise<void> {
@@ -219,8 +217,8 @@ testWalk(
testWalk(
async (d: string): Promise<void> => {
- await mkdir(d + "/a");
- await mkdir(d + "/b");
+ await Deno.mkdir(d + "/a");
+ await Deno.mkdir(d + "/b");
await touch(d + "/a/x");
await touch(d + "/a/y");
await touch(d + "/b/z");
@@ -244,13 +242,13 @@ testWalk(
// TODO(ry) Re-enable followSymlinks
testWalk(
async (d: string): Promise<void> => {
- await mkdir(d + "/a");
- await mkdir(d + "/b");
+ await Deno.mkdir(d + "/a");
+ await Deno.mkdir(d + "/b");
await touch(d + "/a/x");
await touch(d + "/a/y");
await touch(d + "/b/z");
try {
- await symlink(d + "/b", d + "/a/bb");
+ await Deno.symlink(d + "/b", d + "/a/bb");
} catch (err) {
assert(Deno.build.os == "windows");
assertEquals(err.message, "Not implemented");