Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TypeScript definition to CommonJS compatible export #82

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 76 additions & 55 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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"
}
}