Skip to content

Commit

Permalink
fix: separate CJS vs ESM type defs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Aug 29, 2024
1 parent a8c6820 commit a72e1c3
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 10 deletions.
34 changes: 34 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -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");
11 changes: 11 additions & 0 deletions index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Promisable<T> = T | Promise<T>;

export type Callback = (
directory: string,
files: string[],
) => Promisable<string | false | void>;

export default function (
directory: string,
callback: Callback,
): Promise<string | void>;
23 changes: 17 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions src/async.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Promisable<T> = T | Promise<T>;

export type Callback = (
directory: string,
files: string[],
) => Promisable<string | false | void>;

export default function (
directory: string,
callback: Callback,
): Promise<string | void>;
16 changes: 14 additions & 2 deletions src/async.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
type Promisable<T> = T | Promise<T>;
export type Callback = (directory: string, files: string[]) => Promisable<string | false | void>;
export default function (directory: string, callback: Callback): Promise<string | void>;

declare namespace escalade {
export type Callback = (
directory: string,
files: string[],
) => Promisable<string | false | void>;
}

declare function escalade(
directory: string,
callback: escalade.Callback,
): Promise<string | void>;

export = escalade;
9 changes: 9 additions & 0 deletions src/sync.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type Callback = (
directory: string,
files: string[],
) => string | false | void;

export default function (
directory: string,
callback: Callback,
): string | void;
15 changes: 13 additions & 2 deletions src/sync.d.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit a72e1c3

Please sign in to comment.