diff --git a/types/mkdirp-promise/index.d.ts b/types/mkdirp-promise/index.d.ts deleted file mode 100644 index a4f389bca3..0000000000 --- a/types/mkdirp-promise/index.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Type definitions for mkdirp-promise 5.0 -// Project: https://github.com/ahmadnassri/mkdirp-promise -// Definitions by: Alan Plum -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 - -import mkdirp = require("mkdirp"); - -declare function mkdirpPromise( - path: string, - opts?: mkdirp.Mode | mkdirp.Options -): Promise; -export = mkdirpPromise; diff --git a/types/mkdirp-promise/mkdirp-promise-tests.ts b/types/mkdirp-promise/mkdirp-promise-tests.ts deleted file mode 100644 index 28efeb0766..0000000000 --- a/types/mkdirp-promise/mkdirp-promise-tests.ts +++ /dev/null @@ -1,6 +0,0 @@ -import mkdirpPromise = require("mkdirp-promise"); - -(async () => { - const path = await mkdirpPromise("hello"); - if (path) await mkdirpPromise(path, { mode: 123 }); -})(); diff --git a/types/mkdirp-promise/tsconfig.json b/types/mkdirp-promise/tsconfig.json deleted file mode 100644 index fd526f1aee..0000000000 --- a/types/mkdirp-promise/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": ["es6"], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": ["../"], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": ["index.d.ts", "mkdirp-promise-tests.ts"] -} diff --git a/types/mkdirp-promise/tslint.json b/types/mkdirp-promise/tslint.json deleted file mode 100644 index 3db14f85ea..0000000000 --- a/types/mkdirp-promise/tslint.json +++ /dev/null @@ -1 +0,0 @@ -{ "extends": "dtslint/dt.json" } diff --git a/types/mkdirp/index.d.ts b/types/mkdirp/index.d.ts index f1edeeda8b..3641bfe544 100644 --- a/types/mkdirp/index.d.ts +++ b/types/mkdirp/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for mkdirp 0.5 +// Type definitions for mkdirp 1.0 // Project: https://github.com/substack/node-mkdirp // Definitions by: Bart van der Schoor // mrmlnc @@ -8,12 +8,30 @@ import fs = require('fs'); -declare function mkdirp(dir: string, cb: (err: NodeJS.ErrnoException, made: mkdirp.Made) => void): void; -declare function mkdirp(dir: string, opts: mkdirp.Mode | mkdirp.Options, cb: (err: NodeJS.ErrnoException, made: mkdirp.Made) => void): void; +/** + * Create a new directory and any necessary subdirectories at dir with octal + * permission string `opts.mode`. If opts is a string or number, it will be + * treated as the `opts.mode`. If opts.mode isn't specified, it defaults to + * 0o777 & (~`process.umask()`). + * + * Promise resolves to first directory made that had to be created, or + * undefined if everything already exists. Promise rejects if any errors are + * encountered. Note that, in the case of promise rejection, some directories + * may have been created, as recursive directory creation is not an atomic operation. + * You can optionally pass in an alternate fs implementation by passing in + * opts.fs. + * + * Your implementation should have `opts.fs.mkdir(path, opts, cb)` and + * `opts.fs.stat(path, cb)`. + * + * You can also override just one or the other of mkdir and stat by passing in + * `opts.stat` or `opts.mkdir`, or providing an fs option that only overrides one + * of these. + */ +declare function mkdirp(dir: string, opts?: mkdirp.Mode | mkdirp.Options): Promise; declare namespace mkdirp { - type Made = string | null; - type Mode = number | string | null; + type Mode = number | string | undefined; interface FsImplementation { mkdir: typeof fs.mkdir; @@ -35,6 +53,46 @@ declare namespace mkdirp { fs?: FsImplementationSync; } - function sync(dir: string, opts?: Mode | OptionsSync): Made; + /** + * Synchronously create a new directory and any necessary subdirectories at + * dir with octal permission string `opts.mode`. If opts is a string or number, + * it will be treated as the `opts.mode`. If `opts.mode` isn't specified, it + * defaults to 0o777 & (~`process.umask()`). + * You can optionally pass in an alternate fs implementation by passing in + * `opts.fs`. Your implementation should have `opts.fs.mkdirSync(path, mode)` + * and `opts.fs.statSync(path)`. You can also override just one or the other + * of `mkdirSync` and `statSync` by passing in `opts.statSync` or `opts.mkdirSync`, + * or providing an fs option that only overrides one of these. + * @returns Returns the first directory that had to be created, or undefined if everything already exists. + */ + function sync(dir: string, opts?: Mode | Options): string|undefined; + + /** + * Use the manual implementation (not the native one). This is the default + * when the native implementation is not available or the stat/mkdir + * implementation is overridden. + */ + function manual(dir: string, opts?: Mode | Options): Promise; + + /** + * Use the manual implementation (not the native one). This is the default + * when the native implementation is not available or the stat/mkdir + * implementation is overridden. + */ + function manualSync(dir: string, opts?: Mode | Options): string|undefined; + + /** + * Use the native implementation (not the manual one). This is the default + * when the native implementation is available and stat/mkdir are not + * overridden. + */ + function native(dir: string, opts?: Mode | Options): Promise; + + /** + * Use the native implementation (not the manual one). This is the default + * when the native implementation is available and stat/mkdir are not + * overridden. + */ + function nativeSync(dir: string, opts?: Mode | Options): string|undefined; } export = mkdirp; diff --git a/types/mkdirp/mkdirp-tests.ts b/types/mkdirp/mkdirp-tests.ts index 3c09001925..49607a8af4 100644 --- a/types/mkdirp/mkdirp-tests.ts +++ b/types/mkdirp/mkdirp-tests.ts @@ -1,11 +1,11 @@ import mkdirp = require('mkdirp'); -mkdirp('str', (err, made) => { - const str: string = made; +mkdirp('str').then(made => { + const str: string = made; }); -mkdirp('str', '0777', (err, made) => {}); -mkdirp('str', {}, (err, made) => {}); -mkdirp('str', { mode: '0777' }, (err, made) => {}); +mkdirp('str', '0777').then(made => {}); +mkdirp('str', {}).then(made => {}); +mkdirp('str', { mode: '0777' }).then(made => {}); // $ExpectType string mkdirp.sync('str'); @@ -13,5 +13,7 @@ mkdirp.sync('str', '0777'); mkdirp.sync('str', {}); mkdirp.sync('str', { mode: '0777' }); -// $ExpectError -mkdirp.sync('str', { mode: '0777', fs: {} }); +mkdirp.native('str').then(m => {}); +mkdirp.manual('str').then(m => {}); +mkdirp.manualSync('str').indexOf('a'); +mkdirp.nativeSync('str').indexOf('a');