-
-
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
57aa7aa
commit 120a81e
Showing
10 changed files
with
193 additions
and
204 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,66 +1,67 @@ | ||
/// <reference types="node"/> | ||
import * as fs from 'fs'; | ||
import type * as fs from 'node:fs'; | ||
|
||
declare namespace makeDir { | ||
interface Options { | ||
/** | ||
Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/). | ||
@default 0o777 | ||
*/ | ||
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: { | ||
export type Options = { | ||
/** | ||
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' | ||
// ] | ||
})(); | ||
``` | ||
The directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/). | ||
@default 0o777 | ||
*/ | ||
(path: string, options?: makeDir.Options): Promise<string>; | ||
readonly mode?: number; | ||
|
||
/** | ||
Synchronously make a directory and its parents if needed - Think `mkdir -p`. | ||
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. | ||
@param path - Directory to create. | ||
@returns The path to the created directory. | ||
Default: `import fs from 'node:fs'` | ||
*/ | ||
sync(path: string, options?: makeDir.Options): string; | ||
readonly fs?: typeof fs; | ||
}; | ||
|
||
export = makeDir; | ||
/** | ||
Make a directory and its parents if needed - Think `mkdir -p`. | ||
@param path - The directory to create. | ||
@returns The path to the created directory. | ||
@example | ||
``` | ||
import {makeDirectory} from 'make-dir'; | ||
const path = await makeDirectory('unicorn/rainbow/cake'); | ||
console.log(path); | ||
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake' | ||
// Multiple directories: | ||
const paths = await Promise.all([ | ||
makeDirectory('unicorn/rainbow'), | ||
makeDirectory('foo/bar') | ||
]); | ||
console.log(paths); | ||
// [ | ||
// '/Users/sindresorhus/fun/unicorn/rainbow', | ||
// '/Users/sindresorhus/fun/foo/bar' | ||
// ] | ||
``` | ||
*/ | ||
export function makeDirectory(path: string, options?: Options): Promise<string>; | ||
|
||
/** | ||
Synchronously make a directory and its parents if needed - Think `mkdir -p`. | ||
@param path - The directory to create. | ||
@returns The path to the created directory. | ||
@example | ||
``` | ||
import {makeDirectorySync} from 'make-dir'; | ||
const path = makeDirectorySync('unicorn/rainbow/cake'); | ||
console.log(path); | ||
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake' | ||
``` | ||
*/ | ||
export function makeDirectorySync(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 |
---|---|---|
@@ -1,23 +1,22 @@ | ||
import * as fs from 'node:fs'; | ||
import {expectType} from 'tsd'; | ||
import makeDir = require('.'); | ||
import {sync as makeDirSync} from '.'; | ||
import * as fs from 'fs'; | ||
import * as gfs from 'graceful-fs'; | ||
import {makeDirectory, makeDirectorySync} from './index.js'; | ||
|
||
// MakeDir | ||
expectType<Promise<string>>(makeDir('path/to/somewhere')); | ||
expectType<Promise<string>>(makeDirectory('path/to/somewhere')); | ||
|
||
expectType<Promise<string>>( | ||
makeDir('path/to/somewhere', {mode: 0o777}) | ||
makeDirectory('path/to/somewhere', {mode: 0o777}), | ||
); | ||
expectType<Promise<string>>(makeDir('path/to/somewhere', {fs})); | ||
expectType<Promise<string>>(makeDir('path/to/somewhere', {fs: gfs})); | ||
expectType<Promise<string>>(makeDirectory('path/to/somewhere', {fs})); | ||
expectType<Promise<string>>(makeDirectory('path/to/somewhere', {fs: gfs})); | ||
|
||
// MakeDir (sync) | ||
expectType<string>(makeDirSync('path/to/somewhere')); | ||
expectType<string>(makeDirectorySync('path/to/somewhere')); | ||
|
||
expectType<string>( | ||
makeDirSync('path/to/somewhere', {mode: 0o777}) | ||
makeDirectorySync('path/to/somewhere', {mode: 0o777}), | ||
); | ||
expectType<string>(makeDirSync('path/to/somewhere', {fs})); | ||
expectType<string>(makeDirSync('path/to/somewhere', {fs: gfs})); | ||
expectType<string>(makeDirectorySync('path/to/somewhere', {fs})); | ||
expectType<string>(makeDirectorySync('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
Oops, something went wrong.