|
1 | 1 | import { mkdir, writeFile, glob, rm } from "node:fs/promises"; |
2 | 2 | import { dirname, join } from "node:path"; |
3 | | -import { defineBuildConfig } from "unbuild"; |
| 3 | +import { defineBuildConfig } from "obuild/config"; |
| 4 | + |
| 5 | +const adapters = ["bun", "cloudflare", "deno", "node", "sse", "uws"]; |
| 6 | + |
| 7 | +const servers = ["bun", "cloudflare", "default", "deno", "node"]; |
4 | 8 |
|
5 | 9 | export default defineBuildConfig({ |
6 | | - rollup: { |
7 | | - inlineDependencies: true, |
8 | | - }, |
9 | | - externals: [ |
10 | | - "@cloudflare/workers-types", |
11 | | - "bun", |
12 | | - "@deno/types", |
13 | | - "uWebSockets.js", |
14 | | - "cloudflare:workers", |
| 10 | + entries: [ |
| 11 | + { |
| 12 | + type: "bundle", |
| 13 | + input: [ |
| 14 | + "src/index.ts", |
| 15 | + "src/websocket/native.ts", |
| 16 | + "src/websocket/node.ts", |
| 17 | + "src/websocket/sse.ts", |
| 18 | + ...adapters.map((id) => `src/adapters/${id}.ts`), |
| 19 | + ...servers.map((id) => `src/server/${id}.ts`), |
| 20 | + ], |
| 21 | + rolldown: { |
| 22 | + external: [ |
| 23 | + "@cloudflare/workers-types", |
| 24 | + "bun", |
| 25 | + "@deno/types", |
| 26 | + "uWebSockets.js", |
| 27 | + "cloudflare:workers", |
| 28 | + ], |
| 29 | + }, |
| 30 | + }, |
15 | 31 | ], |
16 | 32 | hooks: { |
17 | | - async "build:done"(ctx) { |
18 | | - for await (const file of glob("dist/**/*.d.ts")) { |
19 | | - await rm(file); |
20 | | - } |
21 | | - |
| 33 | + async end(ctx) { |
| 34 | + // Generate declaration files for each entry point (old TS compatibility) |
22 | 35 | const entries = Object.keys(ctx.pkg.exports || {}) |
23 | 36 | .filter((key) => key.startsWith("./")) |
24 | 37 | .map((key) => key.slice(2)); |
25 | 38 | for (const entry of entries) { |
26 | | - const dst = join(ctx.options.rootDir, entry + ".d.ts"); |
| 39 | + const dst = join(ctx.pkgDir, entry + ".d.ts"); |
27 | 40 | await mkdir(dirname(dst), { recursive: true }); |
28 | 41 | let relativePath = |
29 | 42 | ("..".repeat(entry.split("/").length - 1) || ".") + `/dist/${entry}`; |
|
0 commit comments