-
-
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.
Refactor TypeScript definition to CommonJS compatible export (#14)
- Loading branch information
1 parent
1c36213
commit 379001f
Showing
4 changed files
with
73 additions
and
41 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 |
---|---|---|
@@ -1,39 +1,69 @@ | ||
/// <reference types="node"/> | ||
import * as fs from 'fs'; | ||
|
||
export interface Options { | ||
declare namespace makeDir { | ||
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; | ||
} | ||
} | ||
|
||
declare const makeDir: { | ||
/** | ||
* Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/). | ||
* | ||
* @default 0o777 & (~process.umask()) | ||
*/ | ||
readonly mode?: number; | ||
Make a directory and its parents if needed - Think `mkdir -p`. | ||
@param path - Directory to create. | ||
@returns The path to the created directory. | ||
@example | ||
``` | ||
import makeDir = require('make-dir'); | ||
(async () => { | ||
const path = await makeDir('unicorn/rainbow/cake'); | ||
console.log(path); | ||
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake' | ||
// Multiple directories: | ||
const paths = await Promise.all([ | ||
makeDir('unicorn/rainbow'), | ||
makeDir('foo/bar') | ||
]); | ||
console.log(paths); | ||
// [ | ||
// '/Users/sindresorhus/fun/unicorn/rainbow', | ||
// '/Users/sindresorhus/fun/foo/bar' | ||
// ] | ||
})(); | ||
``` | ||
*/ | ||
(path: string, options?: makeDir.Options): Promise<string>; | ||
|
||
/** | ||
* 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; | ||
} | ||
Synchronously make a directory and its parents if needed - Think `mkdir -p`. | ||
@param path - Directory to create. | ||
@returns The path to the created directory. | ||
*/ | ||
sync(path: string, options?: makeDir.Options): string; | ||
|
||
// TODO: Remove this for the next major release | ||
default: typeof makeDir; | ||
}; | ||
|
||
/** | ||
* 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; | ||
export = makeDir; |
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
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