From bdfbd071e491df63c2e59bb4d72ebfac6c60ef10 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 31 Mar 2019 19:15:07 +0000 Subject: [PATCH] Refactor TypeScript definition to CommonJS compatible export (#82) --- index.d.ts | 52 ++++++++++++++++++++++++++++++++++--------------- index.js | 1 + index.test-d.ts | 4 ++-- package.json | 14 ++++++------- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/index.d.ts b/index.d.ts index 203e012..6548c4c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,18 +1,38 @@ -export interface Options { - /** - * Enable globbing when matching file paths. - * - * @default true - */ - readonly glob?: boolean; +declare namespace trash { + interface Options { + /** + Enable globbing when matching file paths. + + @default true + */ + readonly glob?: boolean; + } } -/** - * Move files and folders to the trash. - * - * @param input - Accepts paths and [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). - */ -export default function trash( - input: string | string[], - options?: Options -): Promise; +declare const trash: { + /** + Move files and folders to the trash. + + @param input - Accepts paths and [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). + + @example + ``` + import trash = require('trash'); + + (async () => { + await trash(['*.png', '!rainbow.png']); + })(); + ``` + */ + (input: string | string[], options?: trash.Options): Promise; + + // TODO: Remove this for the next major release, refactor the whole definition to: + // declare function trash( + // input: string | string[], + // options?: Options + // ): Promise; + // export = trash; + default: typeof trash; +}; + +export = trash; diff --git a/index.js b/index.js index 97077a0..7a26349 100644 --- a/index.js +++ b/index.js @@ -53,4 +53,5 @@ const trash = (paths, options) => pTry(() => { }); module.exports = trash; +// TODO: Remove this for the next major release module.exports.default = trash; diff --git a/index.test-d.ts b/index.test-d.ts index b55a268..695941d 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ -import {expectType} from 'tsd-check'; -import trash from '.'; +import {expectType} from 'tsd'; +import trash = require('.'); expectType>(trash('/path/to/item1')); expectType>(trash(['/path/to/item1', '/path/to/item2'])); diff --git a/package.json b/package.json index d515789..45eb101 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "node": ">=8" }, "scripts": { - "test": "xo && ava && tsd-check" + "test": "xo && ava && tsd" }, "files": [ "index.js", @@ -43,17 +43,17 @@ "escape-string-applescript": "^2.0.0", "globby": "^7.1.1", "make-dir": "^1.3.0", - "move-file": "^1.0.0", + "move-file": "^1.1.0", "p-map": "^2.0.0", - "p-try": "^2.0.0", - "run-applescript": "^3.0.0", - "uuid": "^3.1.0", + "p-try": "^2.2.0", + "run-applescript": "^3.2.0", + "uuid": "^3.3.2", "xdg-trashdir": "^2.1.1" }, "devDependencies": { - "ava": "^1.0.0-rc.1", + "ava": "^1.4.1", "tempfile": "^2.0.0", - "tsd-check": "^0.3.0", + "tsd": "^0.7.1", "xo": "^0.24.0" } }