-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1294d7
commit 3e54190
Showing
4 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/// <reference types="node"/> | ||
import * as fs from 'fs'; | ||
|
||
interface Options { | ||
/** | ||
* Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/). | ||
* | ||
* @default 0o777 & (~process.umask()) | ||
*/ | ||
readonly mode?: number; | ||
|
||
/** | ||
* Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs). | ||
* | ||
* Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function. | ||
* | ||
* @default require('fs') | ||
*/ | ||
readonly fs?: typeof fs; | ||
} | ||
|
||
/** | ||
* Make a directory and its parents if needed - Think `mkdir -p`. | ||
* | ||
* @param path - Directory to create. | ||
* @returns A `Promise` for the path to the created directory. | ||
*/ | ||
export default function makeDir( | ||
path: string, | ||
options?: Options | ||
): Promise<string>; | ||
|
||
/** | ||
* Synchronously make a directory and its parents if needed - Think `mkdir -p`. | ||
* | ||
* @param path - Directory to create. | ||
* @returns The path to the created directory. | ||
*/ | ||
export function sync(path: string, options?: Options): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {expectType} from 'tsd-check'; | ||
import makeDir, {sync as makeDirSync} from '.'; | ||
import * as fs from 'fs'; | ||
import * as gfs from 'graceful-fs'; | ||
|
||
// MakeDir | ||
expectType<Promise<string>>(makeDir('path/to/somewhere')); | ||
|
||
expectType<Promise<string>>( | ||
makeDir('path/to/somewhere', {mode: parseInt('777', 8)}) | ||
); | ||
expectType<Promise<string>>(makeDir('path/to/somewhere', {fs})); | ||
expectType<Promise<string>>(makeDir('path/to/somewhere', {fs: gfs})); | ||
|
||
// MakeDir (sync) | ||
expectType<string>(makeDirSync('path/to/somewhere')); | ||
|
||
expectType<string>( | ||
makeDirSync('path/to/somewhere', {mode: parseInt('777', 8)}) | ||
); | ||
expectType<string>(makeDirSync('path/to/somewhere', {fs})); | ||
expectType<string>(makeDirSync('path/to/somewhere', {fs: gfs})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters