Skip to content

Commit a72e1c3

Browse files
committed
fix: separate CJS vs ESM type defs
1 parent a8c6820 commit a72e1c3

File tree

7 files changed

+109
-10
lines changed

7 files changed

+109
-10
lines changed

build.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { execSync } from "node:child_process";
2+
import { join, resolve } from "node:path";
3+
import { copyFileSync } from "node:fs";
4+
5+
execSync("npm run build", {
6+
stdio: "inherit",
7+
});
8+
9+
let root = resolve(".");
10+
let input = resolve("src");
11+
12+
copyFileSync(
13+
join(input, "async.d.mts"),
14+
join(root, "index.d.mts"),
15+
);
16+
17+
copyFileSync(
18+
join(input, "async.d.ts"),
19+
join(root, "index.d.ts"),
20+
);
21+
22+
console.log("+ async dts files");
23+
24+
copyFileSync(
25+
join(input, "sync.d.mts"),
26+
join(root, "sync/index.d.mts"),
27+
);
28+
29+
copyFileSync(
30+
join(input, "sync.d.ts"),
31+
join(root, "sync/index.d.ts"),
32+
);
33+
34+
console.log("+ sync dts files");

index.d.mts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type Promisable<T> = T | Promise<T>;
2+
3+
export type Callback = (
4+
directory: string,
5+
files: string[],
6+
) => Promisable<string | false | void>;
7+
8+
export default function (
9+
directory: string,
10+
callback: Callback,
11+
): Promise<string | void>;

package.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,33 @@
1515
"exports": {
1616
".": [
1717
{
18-
"types": "./index.d.ts",
19-
"import": "./dist/index.mjs",
20-
"require": "./dist/index.js"
18+
"import": {
19+
"types": "./index.d.mts",
20+
"default": "./dist/index.mjs"
21+
},
22+
"require": {
23+
"types": "./index.d.ts",
24+
"default": "./dist/index.js"
25+
}
2126
},
2227
"./dist/index.js"
2328
],
2429
"./sync": [
2530
{
26-
"types": "./sync/index.d.ts",
27-
"import": "./sync/index.mjs",
28-
"require": "./sync/index.js"
31+
"import": {
32+
"types": "./sync/index.d.mts",
33+
"default": "./sync/index.mjs"
34+
},
35+
"require": {
36+
"types": "./sync/index.d.ts",
37+
"default": "./sync/index.js"
38+
}
2939
},
3040
"./sync/index.js"
3141
]
3242
},
3343
"files": [
44+
"*.d.mts",
3445
"*.d.ts",
3546
"dist",
3647
"sync"

src/async.d.mts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type Promisable<T> = T | Promise<T>;
2+
3+
export type Callback = (
4+
directory: string,
5+
files: string[],
6+
) => Promisable<string | false | void>;
7+
8+
export default function (
9+
directory: string,
10+
callback: Callback,
11+
): Promise<string | void>;

src/async.d.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
type Promisable<T> = T | Promise<T>;
2-
export type Callback = (directory: string, files: string[]) => Promisable<string | false | void>;
3-
export default function (directory: string, callback: Callback): Promise<string | void>;
2+
3+
declare namespace escalade {
4+
export type Callback = (
5+
directory: string,
6+
files: string[],
7+
) => Promisable<string | false | void>;
8+
}
9+
10+
declare function escalade(
11+
directory: string,
12+
callback: escalade.Callback,
13+
): Promise<string | void>;
14+
15+
export = escalade;

src/sync.d.mts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export type Callback = (
2+
directory: string,
3+
files: string[],
4+
) => string | false | void;
5+
6+
export default function (
7+
directory: string,
8+
callback: Callback,
9+
): string | void;

src/sync.d.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1-
export type Callback = (directory: string, files: string[]) => string | false | void;
2-
export default function (directory: string, callback: Callback): string | void;
1+
declare namespace escalade {
2+
export type Callback = (
3+
directory: string,
4+
files: string[],
5+
) => string | false | void;
6+
}
7+
8+
declare function escalade(
9+
directory: string,
10+
callback: escalade.Callback,
11+
): string | void;
12+
13+
export = escalade;

0 commit comments

Comments
 (0)