From a72e1c3b049f9ce770a3ae07b48f340530950ea3 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Thu, 29 Aug 2024 15:57:35 -0700 Subject: [PATCH] fix: separate CJS vs ESM type defs --- build.ts | 34 ++++++++++++++++++++++++++++++++++ index.d.mts | 11 +++++++++++ package.json | 23 +++++++++++++++++------ src/async.d.mts | 11 +++++++++++ src/async.d.ts | 16 ++++++++++++++-- src/sync.d.mts | 9 +++++++++ src/sync.d.ts | 15 +++++++++++++-- 7 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 build.ts create mode 100644 index.d.mts create mode 100644 src/async.d.mts create mode 100644 src/sync.d.mts diff --git a/build.ts b/build.ts new file mode 100644 index 0000000..f7adfcc --- /dev/null +++ b/build.ts @@ -0,0 +1,34 @@ +import { execSync } from "node:child_process"; +import { join, resolve } from "node:path"; +import { copyFileSync } from "node:fs"; + +execSync("npm run build", { + stdio: "inherit", +}); + +let root = resolve("."); +let input = resolve("src"); + +copyFileSync( + join(input, "async.d.mts"), + join(root, "index.d.mts"), +); + +copyFileSync( + join(input, "async.d.ts"), + join(root, "index.d.ts"), +); + +console.log("+ async dts files"); + +copyFileSync( + join(input, "sync.d.mts"), + join(root, "sync/index.d.mts"), +); + +copyFileSync( + join(input, "sync.d.ts"), + join(root, "sync/index.d.ts"), +); + +console.log("+ sync dts files"); diff --git a/index.d.mts b/index.d.mts new file mode 100644 index 0000000..550699c --- /dev/null +++ b/index.d.mts @@ -0,0 +1,11 @@ +type Promisable = T | Promise; + +export type Callback = ( + directory: string, + files: string[], +) => Promisable; + +export default function ( + directory: string, + callback: Callback, +): Promise; diff --git a/package.json b/package.json index e0f5271..5d524c0 100644 --- a/package.json +++ b/package.json @@ -15,22 +15,33 @@ "exports": { ".": [ { - "types": "./index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.js" + "import": { + "types": "./index.d.mts", + "default": "./dist/index.mjs" + }, + "require": { + "types": "./index.d.ts", + "default": "./dist/index.js" + } }, "./dist/index.js" ], "./sync": [ { - "types": "./sync/index.d.ts", - "import": "./sync/index.mjs", - "require": "./sync/index.js" + "import": { + "types": "./sync/index.d.mts", + "default": "./sync/index.mjs" + }, + "require": { + "types": "./sync/index.d.ts", + "default": "./sync/index.js" + } }, "./sync/index.js" ] }, "files": [ + "*.d.mts", "*.d.ts", "dist", "sync" diff --git a/src/async.d.mts b/src/async.d.mts new file mode 100644 index 0000000..550699c --- /dev/null +++ b/src/async.d.mts @@ -0,0 +1,11 @@ +type Promisable = T | Promise; + +export type Callback = ( + directory: string, + files: string[], +) => Promisable; + +export default function ( + directory: string, + callback: Callback, +): Promise; diff --git a/src/async.d.ts b/src/async.d.ts index 283e398..26c58f2 100644 --- a/src/async.d.ts +++ b/src/async.d.ts @@ -1,3 +1,15 @@ type Promisable = T | Promise; -export type Callback = (directory: string, files: string[]) => Promisable; -export default function (directory: string, callback: Callback): Promise; + +declare namespace escalade { + export type Callback = ( + directory: string, + files: string[], + ) => Promisable; +} + +declare function escalade( + directory: string, + callback: escalade.Callback, +): Promise; + +export = escalade; diff --git a/src/sync.d.mts b/src/sync.d.mts new file mode 100644 index 0000000..c023d37 --- /dev/null +++ b/src/sync.d.mts @@ -0,0 +1,9 @@ +export type Callback = ( + directory: string, + files: string[], +) => string | false | void; + +export default function ( + directory: string, + callback: Callback, +): string | void; diff --git a/src/sync.d.ts b/src/sync.d.ts index 746ddd3..9d5b589 100644 --- a/src/sync.d.ts +++ b/src/sync.d.ts @@ -1,2 +1,13 @@ -export type Callback = (directory: string, files: string[]) => string | false | void; -export default function (directory: string, callback: Callback): string | void; +declare namespace escalade { + export type Callback = ( + directory: string, + files: string[], + ) => string | false | void; +} + +declare function escalade( + directory: string, + callback: escalade.Callback, +): string | void; + +export = escalade;