From 3f0d6045f8b3cb2a66df4ef542e95925361c145e Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 1 Apr 2019 09:06:13 +0000 Subject: [PATCH] Refactor TypeScript definition to CommonJS compatible export (#82) --- index.d.ts | 131 ++++++++++++++++++++++++++++-------------------- index.js | 1 + index.test-d.ts | 5 +- package.json | 10 ++-- 4 files changed, 85 insertions(+), 62 deletions(-) diff --git a/index.d.ts b/index.d.ts index 5e7e7ba..11fdc2c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,62 +1,83 @@ import {IOptions as GlobOptions} from 'glob'; -interface Options extends Readonly { - /** - * Allow deleting the current working directory and outside. - * - * @default false - */ - readonly force?: boolean; +declare namespace del { + interface Options extends Readonly { + /** + Allow deleting the current working directory and outside. + + @default false + */ + readonly force?: boolean; + + /** + See what would be deleted. + + @default false + + @example + ``` + import del = require('del'); + (async () => { + const deletedPaths = await del(['tmp/*.js'], {dryRun: true}); + + console.log('Files and folders that would be deleted:\n', deletedPaths.join('\n')); + })(); + ``` + */ + readonly dryRun?: boolean; + + /** + Concurrency limit. Minimum: `1`. + + @default Infinity + */ + readonly concurrency?: number; + } +} + +declare const del: { /** - * See what would be deleted. - * - * @default false - * - * @example - * - * import del from 'del'; - * - * (async () => { - * const deletedPaths = await del(['tmp/*.js'], {dryRun: true}); - * - * console.log('Files and folders that would be deleted:\n', deletedPaths.join('\n')); - * })(); - */ - readonly dryRun?: boolean; + Delete files and folders using glob patterns. + + @param patterns - See supported minimatch [patterns](https://github.com/isaacs/minimatch#usage). + - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) + - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) + @param options - See the [`glob` options](https://github.com/isaacs/node-glob#options). + @returns A promise for an array of deleted paths. + + @example + ``` + import del = require('del'); + + (async () => { + const deletedPaths = await del(['tmp/*.js', '!tmp/unicorn.js']); + + console.log('Deleted files and folders:\n', deletedPaths.join('\n')); + })(); + ``` + */ + ( + patterns: string | ReadonlyArray, + options?: del.Options + ): Promise; /** - * Concurrency limit. Minimum: `1`. - * - * @default Infinity - */ - readonly concurrency?: number; -} + Synchronously delete files and folders using glob patterns. + + @param patterns - See supported minimatch [patterns](https://github.com/isaacs/minimatch#usage). + - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) + - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) + @param options - See the [`glob` options](https://github.com/isaacs/node-glob#options). + @returns An array of deleted paths. + */ + sync( + patterns: string | ReadonlyArray, + options?: del.Options + ): string[]; + + // TODO: Remove this for the next major release + default: typeof del; +}; -/** - * Delete files and folders using glob patterns. - * - * @param patterns - See supported minimatch [patterns](https://github.com/isaacs/minimatch#usage). - * - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) - * - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) - * @param options - See the [`glob` options](https://github.com/isaacs/node-glob#options). - * @returns A promise for an array of deleted paths. - */ -export default function del( - patterns: string | ReadonlyArray, - options?: Options -): Promise; - -/** - * Synchronously delete files and folders using glob patterns. - * - * @param patterns - See supported minimatch [patterns](https://github.com/isaacs/minimatch#usage). - * - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) - * - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) - * @param options - See the [`glob` options](https://github.com/isaacs/node-glob#options). - * @returns An array of deleted paths. - */ -export function sync( - patterns: string | ReadonlyArray, - options?: Options -): string[]; +export = del; diff --git a/index.js b/index.js index 248b92b..e953403 100644 --- a/index.js +++ b/index.js @@ -44,6 +44,7 @@ const del = (patterns, options) => { }; module.exports = del; +// TODO: Remove this for the next major release module.exports.default = del; module.exports.sync = (patterns, options) => { diff --git a/index.test-d.ts b/index.test-d.ts index d2ea883..e41d5b7 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,6 @@ -import {expectType} from 'tsd-check'; -import del, {sync as delSync} from '.'; +import {expectType} from 'tsd'; +import del = require('.'); +import {sync as delSync} from '.'; let paths = ['tmp/*.js', '!tmp/unicorn.js']; diff --git a/package.json b/package.json index 359b325..a82dfaf 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "node": ">=6" }, "scripts": { - "test": "xo && ava && tsd-check" + "test": "xo && ava && tsd" }, "files": [ "index.js", @@ -51,13 +51,13 @@ "is-path-in-cwd": "^2.0.0", "p-map": "^2.0.0", "pify": "^4.0.1", - "rimraf": "^2.6.2" + "rimraf": "^2.6.3" }, "devDependencies": { - "ava": "^1.2.1", - "make-dir": "^2.0.0", + "ava": "^1.4.1", + "make-dir": "^2.1.0", "tempy": "^0.2.1", - "tsd-check": "^0.3.0", + "tsd": "^0.7.1", "xo": "^0.24.0" } }