From 98e85fd5409c4b0b9cc37db91ee55873f077895a Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 3 Apr 2019 18:11:48 +0200 Subject: [PATCH] Refactor TypeScript definition to CommonJS compatible export --- index.d.ts | 73 ++++++++++++++++++++++++++++--------------------- index.js | 1 + index.test-d.ts | 10 ++++--- package.json | 14 +++++----- 4 files changed, 56 insertions(+), 42 deletions(-) diff --git a/index.d.ts b/index.d.ts index de15181..13fe517 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,33 +1,44 @@ -export interface Options { - /** - * Overwrite existing destination file. - * - * @default true - */ - readonly overwrite?: boolean; +declare namespace moveFile { + interface Options { + /** + Overwrite existing destination file. + + @default true + */ + readonly overwrite?: boolean; + } } -/** - * Move a file. - * - * @param source - File you want to move. - * @param destination - Where you want the file moved. - * @returns A `Promise` that resolves when the file has been moved. - */ -export default function moveFile( - source: string, - destination: string, - options?: Options -): Promise; - -/** - * Move a file synchronously. - * - * @param source - File you want to move. - * @param destination - Where you want the file moved. - */ -export function sync( - source: string, - destination: string, - options?: Options -): void; +declare const moveFile: { + /** + Move a file. + + @param source - File you want to move. + @param destination - Where you want the file moved. + @returns A `Promise` that resolves when the file has been moved. + + @example + ``` + import moveFile = require('move-file'); + + (async () => { + await moveFile('source/unicorn.png', 'destination/unicorn.png'); + console.log('The file has been moved'); + })(); + ``` + */ + (source: string, destination: string, options?: moveFile.Options): Promise; + + /** + Move a file synchronously. + + @param source - File you want to move. + @param destination - Where you want the file moved. + */ + sync(source: string, destination: string, options?: moveFile.Options): void; + + // TODO: Remove this for the next major release + default: typeof moveFile; +}; + +export = moveFile; diff --git a/index.js b/index.js index f81e8e5..9053b18 100644 --- a/index.js +++ b/index.js @@ -38,6 +38,7 @@ const moveFile = async (source, destination, options) => { }; module.exports = moveFile; +// TODO: Remove this for the next major release module.exports.default = moveFile; module.exports.sync = (source, destination, options) => { diff --git a/index.test-d.ts b/index.test-d.ts index 85f624a..5e36281 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ -import {expectType} from 'tsd-check'; -import moveFile, {sync as moveFileSync} from '.'; +import {expectType} from 'tsd'; +import moveFile = require('.'); expectType>( moveFile('source/unicorn.png', 'destination/unicorn.png') @@ -7,9 +7,11 @@ expectType>( expectType>( moveFile('source/unicorn.png', 'destination/unicorn.png', {overwrite: false}) ); -expectType(moveFileSync('source/unicorn.png', 'destination/unicorn.png')); expectType( - moveFileSync('source/unicorn.png', 'destination/unicorn.png', { + moveFile.sync('source/unicorn.png', 'destination/unicorn.png') +); +expectType( + moveFile.sync('source/unicorn.png', 'destination/unicorn.png', { overwrite: false }) ); diff --git a/package.json b/package.json index 244a22c..e9cbb4e 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", @@ -36,16 +36,16 @@ "partitions" ], "dependencies": { - "cp-file": "^6.0.0", - "make-dir": "^2.1.0", + "cp-file": "^6.1.0", + "make-dir": "^3.0.0", "path-exists": "^3.0.0" }, "devDependencies": { - "ava": "^1.2.1", - "sinon": "^7.2.6", - "temp-write": "^3.3.0", + "ava": "^1.4.1", + "sinon": "^7.3.1", + "temp-write": "^3.4.0", "tempy": "^0.2.1", - "tsd-check": "^0.3.0", + "tsd": "^0.7.2", "xo": "^0.24.0" } }