Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 1, 2019
1 parent 49e955b commit 3f0d604
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 62 deletions.
131 changes: 76 additions & 55 deletions index.d.ts
@@ -1,62 +1,83 @@
import {IOptions as GlobOptions} from 'glob';

interface Options extends Readonly<GlobOptions> {
/**
* Allow deleting the current working directory and outside.
*
* @default false
*/
readonly force?: boolean;
declare namespace del {
interface Options extends Readonly<GlobOptions> {
/**
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<string>,
options?: del.Options
): Promise<string[]>;

/**
* 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<string>,
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<string>,
options?: Options
): Promise<string[]>;

/**
* 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<string>,
options?: Options
): string[];
export = del;
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -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) => {
Expand Down
5 changes: 3 additions & 2 deletions 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'];

Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand Down Expand Up @@ -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"
}
}

0 comments on commit 3f0d604

Please sign in to comment.