-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbuild.config.ts
More file actions
56 lines (53 loc) · 1.67 KB
/
build.config.ts
File metadata and controls
56 lines (53 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { mkdir, writeFile, glob, rm } from "node:fs/promises";
import { dirname, join } from "node:path";
import { defineBuildConfig } from "obuild/config";
const adapters = ["bun", "cloudflare", "deno", "node", "sse", "uws"];
const servers = ["bun", "cloudflare", "default", "deno", "node"];
export default defineBuildConfig({
entries: [
{
type: "bundle",
input: [
"src/index.ts",
"src/websocket/native.ts",
"src/websocket/node.ts",
"src/websocket/sse.ts",
...adapters.map((id) => `src/adapters/${id}.ts`),
...servers.map((id) => `src/server/${id}.ts`),
],
rolldown: {
external: [
"@cloudflare/workers-types",
"bun",
"@deno/types",
"uWebSockets.js",
"cloudflare:workers",
],
},
},
],
hooks: {
async end(ctx) {
// Generate declaration files for each entry point (old TS compatibility)
const entries = Object.keys(ctx.pkg.exports || {})
.filter((key) => key.startsWith("./"))
.map((key) => key.slice(2));
for (const entry of entries) {
const dst = join(ctx.pkgDir, entry + ".d.ts");
await mkdir(dirname(dst), { recursive: true });
let relativePath =
("..".repeat(entry.split("/").length - 1) || ".") + `/dist/${entry}`;
if (entry === "websocket") {
relativePath += "/native";
} else if (entry === "server") {
relativePath += "/node";
}
await writeFile(
dst,
`export * from "${relativePath}.mjs";\nexport { default } from "${relativePath}.mjs";\n`,
"utf8",
);
}
},
},
});