Skip to content

Commit

Permalink
fix: Deno.mkdir should conform to style guide (denoland/deno#3617)
Browse files Browse the repository at this point in the history
  • Loading branch information
ry authored and denobot committed Jan 31, 2021
1 parent afdb6ae commit 534c0a6
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions fs/empty_dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function emptyDir(dir: string): Promise<void> {
}

// if not exist. then create it
await mkdir(dir, true);
await mkdir(dir, { recursive: true });
}
}

Expand Down Expand Up @@ -61,7 +61,7 @@ export function emptyDirSync(dir: string): void {
throw err;
}
// if not exist. then create it
mkdirSync(dir, true);
mkdirSync(dir, { recursive: true });
return;
}
}
4 changes: 2 additions & 2 deletions fs/ensure_dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function ensureDir(dir: string): Promise<void> {
} catch (err) {
if (err instanceof Deno.DenoError && err.kind === ErrorKind.NotFound) {
// if dir not exists. then create it.
await mkdir(dir, true);
await mkdir(dir, { recursive: true });
return;
}
throw err;
Expand All @@ -41,7 +41,7 @@ export function ensureDirSync(dir: string): void {
} catch (err) {
if (err instanceof Deno.DenoError && err.kind == ErrorKind.NotFound) {
// if dir not exists. then create it.
mkdirSync(dir, true);
mkdirSync(dir, { recursive: true });
return;
}
throw err;
Expand Down
4 changes: 2 additions & 2 deletions fs/ensure_dir_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test(async function ensureDirIfItExist(): Promise<void> {
const testDir = path.join(baseDir, "test");

// create test directory
await Deno.mkdir(testDir, true);
await Deno.mkdir(testDir, { recursive: true });

await ensureDir(testDir);

Expand All @@ -60,7 +60,7 @@ test(function ensureDirSyncIfItExist(): void {
const testDir = path.join(baseDir, "test");

// create test directory
Deno.mkdirSync(testDir, true);
Deno.mkdirSync(testDir, { recursive: true });

ensureDirSync(testDir);

Expand Down
8 changes: 4 additions & 4 deletions fs/ensure_file_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test(async function ensureFileIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_file_3");
const testFile = path.join(testDir, "test.txt");

await Deno.mkdir(testDir, true);
await Deno.mkdir(testDir, { recursive: true });
await Deno.writeFile(testFile, new Uint8Array());

await ensureFile(testFile);
Expand All @@ -61,7 +61,7 @@ test(function ensureFileSyncIfItExist(): void {
const testDir = path.join(testdataDir, "ensure_file_4");
const testFile = path.join(testDir, "test.txt");

Deno.mkdirSync(testDir, true);
Deno.mkdirSync(testDir, { recursive: true });
Deno.writeFileSync(testFile, new Uint8Array());

ensureFileSync(testFile);
Expand All @@ -77,7 +77,7 @@ test(function ensureFileSyncIfItExist(): void {
test(async function ensureFileIfItExistAsDir(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_file_5");

await Deno.mkdir(testDir, true);
await Deno.mkdir(testDir, { recursive: true });

await assertThrowsAsync(
async (): Promise<void> => {
Expand All @@ -93,7 +93,7 @@ test(async function ensureFileIfItExistAsDir(): Promise<void> {
test(function ensureFileSyncIfItExistAsDir(): void {
const testDir = path.join(testdataDir, "ensure_file_6");

Deno.mkdirSync(testDir, true);
Deno.mkdirSync(testDir, { recursive: true });

assertThrows(
(): void => {
Expand Down
8 changes: 4 additions & 4 deletions fs/ensure_link_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test(async function ensureLinkIfItExist(): Promise<void> {
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");

await Deno.mkdir(testDir, true);
await Deno.mkdir(testDir, { recursive: true });
await Deno.writeFile(testFile, new Uint8Array());

await ensureLink(testFile, linkFile);
Expand Down Expand Up @@ -90,7 +90,7 @@ test(function ensureLinkSyncIfItExist(): void {
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");

Deno.mkdirSync(testDir, true);
Deno.mkdirSync(testDir, { recursive: true });
Deno.writeFileSync(testFile, new Uint8Array());

ensureLinkSync(testFile, linkFile);
Expand Down Expand Up @@ -138,7 +138,7 @@ test(async function ensureLinkDirectoryIfItExist(): Promise<void> {
const linkDir = path.join(testdataDir, "ensure_link_link_3");
const testFile = path.join(testDir, "test.txt");

await Deno.mkdir(testDir, true);
await Deno.mkdir(testDir, { recursive: true });
await Deno.writeFile(testFile, new Uint8Array());

await assertThrowsAsync(
Expand All @@ -158,7 +158,7 @@ test(function ensureLinkSyncDirectoryIfItExist(): void {
const linkDir = path.join(testdataDir, "ensure_link_link_3");
const testFile = path.join(testDir, "test.txt");

Deno.mkdirSync(testDir, true);
Deno.mkdirSync(testDir, { recursive: true });
Deno.writeFileSync(testFile, new Uint8Array());

assertThrows(
Expand Down
8 changes: 4 additions & 4 deletions fs/ensure_symlink_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test(async function ensureSymlinkIfItExist(): Promise<void> {
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");

await Deno.mkdir(testDir, true);
await Deno.mkdir(testDir, { recursive: true });
await Deno.writeFile(testFile, new Uint8Array());

if (isWindows) {
Expand Down Expand Up @@ -79,7 +79,7 @@ test(function ensureSymlinkSyncIfItExist(): void {
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");

Deno.mkdirSync(testDir, true);
Deno.mkdirSync(testDir, { recursive: true });
Deno.writeFileSync(testFile, new Uint8Array());

if (isWindows) {
Expand Down Expand Up @@ -109,7 +109,7 @@ test(async function ensureSymlinkDirectoryIfItExist(): Promise<void> {
const linkDir = path.join(testdataDir, "link_file_link_3");
const testFile = path.join(testDir, "test.txt");

await Deno.mkdir(testDir, true);
await Deno.mkdir(testDir, { recursive: true });
await Deno.writeFile(testFile, new Uint8Array());

if (isWindows) {
Expand Down Expand Up @@ -141,7 +141,7 @@ test(function ensureSymlinkSyncDirectoryIfItExist(): void {
const linkDir = path.join(testdataDir, "link_file_link_3");
const testFile = path.join(testDir, "test.txt");

Deno.mkdirSync(testDir, true);
Deno.mkdirSync(testDir, { recursive: true });
Deno.writeFileSync(testFile, new Uint8Array());

if (isWindows) {
Expand Down
17 changes: 10 additions & 7 deletions fs/move_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test(async function moveDirectoryIfDestNotExists(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_2");
const destDir = path.join(testdataDir, "move_test_dest_2");

await Deno.mkdir(srcDir, true);
await Deno.mkdir(srcDir, { recursive: true });

// if dest directory not exist
await assertThrowsAsync(
Expand Down Expand Up @@ -112,7 +112,7 @@ test(async function moveDirectory(): Promise<void> {
const destFile = path.join(destDir, "test.txt");
const srcContent = new TextEncoder().encode("src");

await Deno.mkdir(srcDir, true);
await Deno.mkdir(srcDir, { recursive: true });
assertEquals(await exists(srcDir), true);
await Deno.writeFile(srcFile, srcContent);

Expand Down Expand Up @@ -140,7 +140,10 @@ test(async function moveIfSrcAndDestDirectoryExistsAndOverwrite(): Promise<
const srcContent = new TextEncoder().encode("src");
const destContent = new TextEncoder().encode("dest");

await Promise.all([Deno.mkdir(srcDir, true), Deno.mkdir(destDir, true)]);
await Promise.all([
Deno.mkdir(srcDir, { recursive: true }),
Deno.mkdir(destDir, { recursive: true })
]);
assertEquals(await exists(srcDir), true);
assertEquals(await exists(destDir), true);
await Promise.all([
Expand Down Expand Up @@ -191,7 +194,7 @@ test(function moveSyncDirectoryIfDestNotExists(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_2");
const destDir = path.join(testdataDir, "move_sync_test_dest_2");

Deno.mkdirSync(srcDir, true);
Deno.mkdirSync(srcDir, { recursive: true });

// if dest directory not exist
assertThrows(
Expand Down Expand Up @@ -270,7 +273,7 @@ test(function moveSyncDirectory(): void {
const destFile = path.join(destDir, "test.txt");
const srcContent = new TextEncoder().encode("src");

Deno.mkdirSync(srcDir, true);
Deno.mkdirSync(srcDir, { recursive: true });
assertEquals(existsSync(srcDir), true);
Deno.writeFileSync(srcFile, srcContent);

Expand All @@ -294,8 +297,8 @@ test(function moveSyncIfSrcAndDestDirectoryExistsAndOverwrite(): void {
const srcContent = new TextEncoder().encode("src");
const destContent = new TextEncoder().encode("dest");

Deno.mkdirSync(srcDir, true);
Deno.mkdirSync(destDir, true);
Deno.mkdirSync(srcDir, { recursive: true });
Deno.mkdirSync(destDir, { recursive: true });
assertEquals(existsSync(srcDir), true);
assertEquals(existsSync(destDir), true);
Deno.writeFileSync(srcFile, srcContent);
Expand Down
2 changes: 1 addition & 1 deletion fs/walk_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ testWalk(

testWalk(
async (d: string): Promise<void> => {
await mkdir(d + "/a/b/c/d", true);
await mkdir(d + "/a/b/c/d", { recursive: true });
await touch(d + "/a/b/c/d/x");
},
async function depth(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion io/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function tempFile(
const filepath = path.resolve(
`${dir}/${opts.prefix || ""}${r}${opts.postfix || ""}`
);
await mkdir(path.dirname(filepath), true);
await mkdir(path.dirname(filepath), { recursive: true });
const file = await open(filepath, "a");
return { file, filepath };
}

0 comments on commit 534c0a6

Please sign in to comment.