1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

Remove mkdirp - deno.mkdir is already recursive (denoland/deno_std#118)

Original: 4283c26b89
This commit is contained in:
Ryan Dahl 2019-01-17 13:14:48 -05:00 committed by GitHub
parent b2e54bad61
commit 15f372c549
3 changed files with 0 additions and 74 deletions

View file

@ -1,43 +0,0 @@
/**
* # deno-mkdirp
*
* `mkdir -p` 4 `deno`.
*
* ## Import
*
* ```ts
* import { mkdirp } from "https://deno.land/x/std/fs/mkdirp.ts";
* ```
*
* ## API
*
* Same as [`deno.mkdir`](https://deno.land/typedoc/index.html#mkdir).
*
* ### `mkdirp(path: string, mode?: number) : Promise<void>`
*
* Creates directories if they do not already exist and makes parent directories as needed.
*/
import { ErrorKind, FileInfo, lstat, mkdir, platform } from "deno";
const PATH_SEPARATOR: string = platform.os === "win" ? "\\" : "/";
export async function mkdirp(path: string, mode?: number): Promise<void> {
for (
let parts: string[] = path.split(/\/|\\/),
parts_len: number = parts.length,
level: string,
info: FileInfo,
i: number = 0;
i < parts_len;
i++
) {
level = parts.slice(0, i + 1).join(PATH_SEPARATOR);
try {
info = await lstat(level);
if (!info.isDirectory()) throw Error(`${level} is not a directory`);
} catch (err) {
if (err.kind !== ErrorKind.NotFound) throw err;
await mkdir(level, mode);
}
}
}

View file

@ -1,30 +0,0 @@
import { cwd, lstat, makeTempDirSync, removeAll, FileInfo } from "deno";
import { test, assert } from "../testing/mod.ts";
import { mkdirp } from "./mkdirp.ts";
let root: string = `${cwd()}/${Date.now()}`; //makeTempDirSync();
test(async function createsNestedDirs(): Promise<void> {
const leaf: string = `${root}/levelx/levely`;
await mkdirp(leaf);
const info: FileInfo = await lstat(leaf);
assert(info.isDirectory());
await removeAll(root);
});
test(async function handlesAnyPathSeparator(): Promise<void> {
const leaf: string = `${root}\\levelx\\levely`;
await mkdirp(leaf);
const info: FileInfo = await lstat(leaf.replace(/\\/g, "/"));
assert(info.isDirectory());
await removeAll(root);
});
test(async function failsNonDir(): Promise<void> {
try {
await mkdirp("./test.ts/fest.fs");
} catch (err) {
// TODO: assert caught DenoError of kind NOT_A_DIRECTORY or similar
assert(err);
}
});

View file

@ -3,7 +3,6 @@ import "colors/test.ts";
import "datetime/test.ts";
import "examples/test.ts";
import "flags/test.ts";
import "fs/mkdirp_test.ts";
import "fs/path/basename_test.ts";
import "fs/path/dirname_test.ts";
import "fs/path/extname_test.ts";