|
| 1 | +import { dirname, resolve } from 'node:path' |
1 | 2 | import { fileURLToPath } from 'node:url' |
2 | | -import { resolveSync } from 'mlly' |
3 | 3 | import { defineConfig } from 'tsdown' |
4 | 4 |
|
5 | | -// Resolve `ohash/crypto` without the `node` condition so the pure-JS digest |
6 | | -// is bundled. The default resolution honours `node`, which inlines |
7 | | -// `node:crypto.createHash` into outputs that are later shipped to the |
8 | | -// browser via the `client` entry. |
9 | | -const ohashCryptoAgnostic = fileURLToPath( |
10 | | - resolveSync('ohash/crypto', { url: import.meta.url, conditions: ['import'] }), |
11 | | -) |
| 5 | +const here = dirname(fileURLToPath(import.meta.url)) |
| 6 | +const distDir = resolve(here, 'dist') |
12 | 7 |
|
13 | | -export default defineConfig({ |
14 | | - alias: { |
15 | | - 'ohash/crypto': ohashCryptoAgnostic, |
16 | | - }, |
17 | | - entry: { |
18 | | - 'index': 'src/index.ts', |
19 | | - 'rpc/index': 'src/rpc/index.ts', |
20 | | - 'rpc/client': 'src/rpc/client.ts', |
21 | | - 'rpc/server': 'src/rpc/server.ts', |
22 | | - 'rpc/transports/ws-client': 'src/rpc/transports/ws-client.ts', |
23 | | - 'rpc/transports/ws-server': 'src/rpc/transports/ws-server.ts', |
24 | | - 'types/index': 'src/types/index.ts', |
25 | | - 'node/index': 'src/node/index.ts', |
26 | | - 'node/auth': 'src/node/auth/index.ts', |
27 | | - 'node/internal': 'src/node/internal/index.ts', |
28 | | - 'constants': 'src/constants.ts', |
29 | | - 'utils/colors': 'src/utils/colors.ts', |
30 | | - 'utils/events': 'src/utils/events.ts', |
31 | | - 'utils/hash': 'src/utils/hash.ts', |
32 | | - 'utils/human-id': 'src/utils/human-id.ts', |
33 | | - 'utils/launch-editor': 'src/utils/launch-editor.ts', |
34 | | - 'utils/nanoid': 'src/utils/nanoid.ts', |
35 | | - 'utils/open': 'src/utils/open.ts', |
36 | | - 'utils/promise': 'src/utils/promise.ts', |
37 | | - 'utils/serve-static': 'src/utils/serve-static.ts', |
38 | | - 'utils/shared-state': 'src/utils/shared-state.ts', |
39 | | - 'utils/streaming-channel': 'src/utils/streaming-channel.ts', |
40 | | - 'utils/structured-clone': 'src/utils/structured-clone.ts', |
41 | | - 'utils/when': 'src/utils/when.ts', |
42 | | - 'adapters/cli': 'src/adapters/cli.ts', |
43 | | - 'adapters/dev': 'src/adapters/dev.ts', |
44 | | - 'adapters/build': 'src/adapters/build.ts', |
45 | | - 'helpers/vite': 'src/helpers/vite.ts', |
46 | | - 'adapters/embedded': 'src/adapters/embedded.ts', |
47 | | - 'adapters/mcp': 'src/adapters/mcp/index.ts', |
48 | | - 'client/index': 'src/client/index.ts', |
49 | | - 'recipes/open-helpers': 'src/recipes/open-helpers.ts', |
50 | | - }, |
51 | | - tsconfig: '../../tsconfig.base.json', |
52 | | - clean: true, |
53 | | - dts: true, |
54 | | - exports: true, |
| 8 | +const tsconfig = '../../tsconfig.base.json' |
| 9 | + |
| 10 | +const deps = { |
55 | 11 | // Keep transitive external type graphs out of dts bundling. |
56 | 12 | // `vite`/`esbuild`/`postcss` are pulled in via the kit client's |
57 | 13 | // `declare module 'vite'` augmentation and contain |
58 | 14 | // rolldown-incompatible re-exports that would otherwise fail dts |
59 | 15 | // generation with dozens of MISSING_EXPORT errors. |
60 | | - deps: { |
61 | | - neverBundle: [ |
62 | | - 'vite', |
63 | | - 'esbuild', |
64 | | - 'postcss', |
65 | | - 'rolldown', |
66 | | - /^@rolldown\//, |
67 | | - /^@oxc-project\//, |
68 | | - 'terser', |
69 | | - '@jridgewell/trace-mapping', |
70 | | - ], |
71 | | - onlyBundle: [ |
72 | | - 'acorn', |
73 | | - 'bundle-name', |
74 | | - 'default-browser', |
75 | | - 'default-browser-id', |
76 | | - 'define-lazy-prop', |
77 | | - 'get-port-please', |
78 | | - 'immer', |
79 | | - 'is-docker', |
80 | | - 'is-in-ssh', |
81 | | - 'is-inside-container', |
82 | | - 'is-wsl', |
83 | | - 'launch-editor', |
84 | | - 'mlly', |
85 | | - 'obug', |
86 | | - 'ohash', |
87 | | - 'open', |
88 | | - 'p-limit', |
89 | | - 'perfect-debounce', |
90 | | - 'picocolors', |
91 | | - 'powershell-utils', |
92 | | - 'run-applescript', |
93 | | - 'shell-quote', |
94 | | - 'structured-clone-es', |
95 | | - 'tinyexec', |
96 | | - 'ua-parser-modern', |
97 | | - 'whenexpr', |
98 | | - 'wsl-utils', |
99 | | - 'yocto-queue', |
100 | | - ], |
| 16 | + neverBundle: [ |
| 17 | + 'vite', |
| 18 | + 'esbuild', |
| 19 | + 'postcss', |
| 20 | + 'rolldown', |
| 21 | + /^@rolldown\//, |
| 22 | + /^@oxc-project\//, |
| 23 | + 'terser', |
| 24 | + '@jridgewell/trace-mapping', |
| 25 | + ], |
| 26 | + onlyBundle: [ |
| 27 | + 'acorn', |
| 28 | + 'bundle-name', |
| 29 | + 'default-browser', |
| 30 | + 'default-browser-id', |
| 31 | + 'define-lazy-prop', |
| 32 | + 'get-port-please', |
| 33 | + 'immer', |
| 34 | + 'is-docker', |
| 35 | + 'is-in-ssh', |
| 36 | + 'is-inside-container', |
| 37 | + 'is-wsl', |
| 38 | + 'launch-editor', |
| 39 | + 'mlly', |
| 40 | + 'obug', |
| 41 | + 'ohash', |
| 42 | + 'open', |
| 43 | + 'p-limit', |
| 44 | + 'perfect-debounce', |
| 45 | + 'picocolors', |
| 46 | + 'powershell-utils', |
| 47 | + 'run-applescript', |
| 48 | + 'shell-quote', |
| 49 | + 'structured-clone-es', |
| 50 | + 'tinyexec', |
| 51 | + 'ua-parser-modern', |
| 52 | + 'whenexpr', |
| 53 | + 'wsl-utils', |
| 54 | + 'yocto-queue', |
| 55 | + ], |
| 56 | +} |
| 57 | + |
| 58 | +// Split into two configs so client/agnostic and server entries live in |
| 59 | +// independent rolldown chunk graphs. A single combined build lets rolldown |
| 60 | +// hoist shared helpers into chunks that mix server-only imports like |
| 61 | +// `devframe/rpc/transports/ws-server` or `node:crypto`, which then leak into |
| 62 | +// browser-loaded outputs (e.g. `client/index.mjs`, `utils/hash.mjs`). |
| 63 | +export default defineConfig([ |
| 64 | + // Client / agnostic build — runs first; `clean: true` clears dist/ before |
| 65 | + // the server build appends to it. Keep this first in the array. |
| 66 | + { |
| 67 | + clean: true, |
| 68 | + platform: 'browser', |
| 69 | + tsconfig, |
| 70 | + deps, |
| 71 | + dts: true, |
| 72 | + // Force `.mjs` / `.d.mts` extensions to match the server config and the |
| 73 | + // `packages/devframe/package.json` `exports` map. `platform: 'browser'` |
| 74 | + // defaults to `.js`, which would break those entry paths. |
| 75 | + outExtensions: () => ({ js: '.mjs', dts: '.d.mts' }), |
| 76 | + entry: { |
| 77 | + 'client/index': 'src/client/index.ts', |
| 78 | + 'utils/colors': 'src/utils/colors.ts', |
| 79 | + 'utils/events': 'src/utils/events.ts', |
| 80 | + 'utils/hash': 'src/utils/hash.ts', |
| 81 | + 'utils/human-id': 'src/utils/human-id.ts', |
| 82 | + 'utils/nanoid': 'src/utils/nanoid.ts', |
| 83 | + 'utils/promise': 'src/utils/promise.ts', |
| 84 | + 'utils/shared-state': 'src/utils/shared-state.ts', |
| 85 | + 'utils/streaming-channel': 'src/utils/streaming-channel.ts', |
| 86 | + 'utils/structured-clone': 'src/utils/structured-clone.ts', |
| 87 | + 'utils/when': 'src/utils/when.ts', |
| 88 | + }, |
| 89 | + hooks: { |
| 90 | + 'build:done': async () => { |
| 91 | + const { checkClientDist } = await import('./scripts/check-client-dist.ts') |
| 92 | + await checkClientDist({ |
| 93 | + entries: [ |
| 94 | + resolve(distDir, 'client/index.mjs'), |
| 95 | + resolve(distDir, 'utils/colors.mjs'), |
| 96 | + resolve(distDir, 'utils/events.mjs'), |
| 97 | + resolve(distDir, 'utils/hash.mjs'), |
| 98 | + resolve(distDir, 'utils/human-id.mjs'), |
| 99 | + resolve(distDir, 'utils/nanoid.mjs'), |
| 100 | + resolve(distDir, 'utils/promise.mjs'), |
| 101 | + resolve(distDir, 'utils/shared-state.mjs'), |
| 102 | + resolve(distDir, 'utils/streaming-channel.mjs'), |
| 103 | + resolve(distDir, 'utils/structured-clone.mjs'), |
| 104 | + resolve(distDir, 'utils/when.mjs'), |
| 105 | + ], |
| 106 | + cwd: here, |
| 107 | + }) |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | + // Server / node build — `clean: false` so it appends to the client output. |
| 112 | + { |
| 113 | + clean: false, |
| 114 | + platform: 'node', |
| 115 | + tsconfig, |
| 116 | + deps, |
| 117 | + dts: true, |
| 118 | + entry: { |
| 119 | + 'index': 'src/index.ts', |
| 120 | + 'constants': 'src/constants.ts', |
| 121 | + 'types/index': 'src/types/index.ts', |
| 122 | + 'rpc/index': 'src/rpc/index.ts', |
| 123 | + 'rpc/client': 'src/rpc/client.ts', |
| 124 | + 'rpc/server': 'src/rpc/server.ts', |
| 125 | + 'rpc/transports/ws-client': 'src/rpc/transports/ws-client.ts', |
| 126 | + 'rpc/transports/ws-server': 'src/rpc/transports/ws-server.ts', |
| 127 | + 'node/index': 'src/node/index.ts', |
| 128 | + 'node/auth': 'src/node/auth/index.ts', |
| 129 | + 'node/internal': 'src/node/internal/index.ts', |
| 130 | + 'utils/launch-editor': 'src/utils/launch-editor.ts', |
| 131 | + 'utils/open': 'src/utils/open.ts', |
| 132 | + 'utils/serve-static': 'src/utils/serve-static.ts', |
| 133 | + 'adapters/cli': 'src/adapters/cli.ts', |
| 134 | + 'adapters/dev': 'src/adapters/dev.ts', |
| 135 | + 'adapters/build': 'src/adapters/build.ts', |
| 136 | + 'adapters/embedded': 'src/adapters/embedded.ts', |
| 137 | + 'adapters/mcp': 'src/adapters/mcp/index.ts', |
| 138 | + 'helpers/vite': 'src/helpers/vite.ts', |
| 139 | + 'recipes/open-helpers': 'src/recipes/open-helpers.ts', |
| 140 | + }, |
101 | 141 | }, |
102 | | -}) |
| 142 | +]) |
0 commit comments