Repository navigation
Expand file tree
/
Copy pathtsup.shared.js
More file actions
275 lines (274 loc) · 8.51 KB
/
Copy pathtsup.shared.js
File metadata and controls
275 lines (274 loc) · 8.51 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// Shared tsup build configuration (sphere-sdk#548).
//
// Single source of truth for the per-entry tsup configs, consumed by BOTH
// `tsup.config.ts` (for `tsup --watch` dev use — parallel is fine locally) and
// `scripts/build.mjs` (the publish/CI build, which runs these SEQUENTIALLY).
//
// Why split this out: tsup runs an array of configs under `Promise.all`
// (parallel), and with this many `dts: true` entries the concurrent declaration
// passes intermittently drop an output (notably `dist/token-engine/index.d.ts`)
// ~50% of the time — there is no sequential option in tsup 8.x (egoist/tsup#577,
// #670, #1270; vercel/ai#10662). `scripts/build.mjs` imports these and builds
// them one at a time via the programmatic API, which removes the race while
// preserving every per-entry option here byte-for-byte. Plain ESM (no
// TypeScript) so Node can import it directly from the build script.
/** @type {import('tsup').Options[]} */
export const configs = [
// Main entry - universal (works in browser with bundler, and Node.js)
{
entry: { 'index': 'index.ts' },
format: ['esm', 'cjs'],
dts: true,
clean: true,
splitting: false,
sourcemap: true,
platform: 'node',
target: 'es2022',
noExternal: [/^@noble\//],
external: [
/^@unicitylabs\//,
'bip39',
'buffer',
'crypto-js',
'elliptic',
'ws',
],
},
// Core only — for Node.js projects
{
entry: { 'core/index': 'core/index.ts' },
format: ['esm', 'cjs'],
dts: true,
clean: false,
splitting: false,
sourcemap: true,
platform: 'node',
target: 'es2022',
noExternal: [/^@noble\//],
external: [
/^@unicitylabs\//,
'bip39',
'buffer',
'crypto-js',
'elliptic',
'ws',
],
},
// Token-engine (incl. the SpherePaymentData codec) — for server-side
// consumers (wallet-api validation) that must not pull browser/Nostr
{
entry: { 'token-engine/index': 'token-engine/index.ts' },
format: ['esm', 'cjs'],
dts: true,
clean: false,
splitting: false,
sourcemap: true,
platform: 'node',
target: 'es2022',
noExternal: [/^@noble\//],
external: [
/^@unicitylabs\//,
'bip39',
'buffer',
'crypto-js',
'elliptic',
'ws',
],
},
// payments-v2 vertical (docs/PAYMENTS-V2-DESIGN.md) — platform-neutral
{
entry: { 'modules/payments-v2/index': 'modules/payments-v2/index.ts' },
format: ['esm', 'cjs'],
dts: true,
clean: false,
splitting: false,
sourcemap: true,
platform: 'node',
target: 'es2022',
noExternal: [/^@noble\//],
external: [
/^@unicitylabs\//,
'bip39',
'buffer',
'crypto-js',
'elliptic',
'ws',
],
},
// wallet-api-v2 session/client/ports (payments-v2 impl) — platform-neutral (fetch/WS injected)
{
entry: { 'impl/wallet-api-v2/index': 'impl/wallet-api-v2/index.ts' },
format: ['esm', 'cjs'],
dts: true,
clean: false,
splitting: false,
sourcemap: true,
platform: 'node',
target: 'es2022',
noExternal: [/^@noble\//],
external: [
/^@unicitylabs\//,
'bip39',
'buffer',
'crypto-js',
'elliptic',
'ws',
],
},
// Browser implementation
{
entry: { 'impl/browser/index': 'impl/browser/index.ts' },
format: ['esm', 'cjs'],
dts: false,
clean: false,
splitting: false,
sourcemap: true,
platform: 'browser',
target: 'es2022',
noExternal: [/^@noble\//],
external: [
/^@unicitylabs\//,
],
},
// Shared wallet-api providers (S4 composition presets) — platform-neutral,
// consumed by the Sphere frontend; ships dts (unlike impl/browser, whose
// missing types forced a consumer-side shim — sphere-sdk#511).
{
entry: { 'impl/shared/wallet-api/index': 'impl/shared/wallet-api/index.ts' },
format: ['esm', 'cjs'],
dts: true,
clean: false,
splitting: false,
sourcemap: true,
platform: 'browser',
target: 'es2022',
noExternal: [/^@noble\//],
external: [
/^@unicitylabs\//,
],
},
// Node.js implementation
{
entry: { 'impl/nodejs/index': 'impl/nodejs/index.ts' },
format: ['esm', 'cjs'],
dts: true,
clean: false,
splitting: false,
sourcemap: true,
platform: 'node',
target: 'es2022',
noExternal: [/^@noble\//],
external: [
/^@unicitylabs\//,
'ws',
],
},
// Sphere Connect — ESM: ./connect, ./connect/browser and ./connect/nodejs
// built as ONE code-split graph (was: one `splitting: false` config per
// entry, sphere-sdk#789).
//
// Why: with a bundle per entry, ./connect/browser inlined its own copy of
// ConnectClient/ConnectError (and, through the '../../../connect' barrel,
// dead ConnectHost leftovers), so a dApp importing both ./connect and
// ./connect/browser got two ConnectError classes and `err instanceof
// ConnectError` was false for autoConnect errors. With splitting, a module
// reached from several entries is emitted ONCE in dist/connect/chunks/ and
// every entry imports it; the public entry files keep their paths.
//
// The two `connect/internal/*` entries are NOT package exports. They exist
// only to give the wallet host and the NFT wire codec a chunk of their own
// (esbuild groups code by the set of entries that reach it), so
// dist/connect/index.js is a pure re-export file. A dApp that imports
// ConnectClient/ERROR_CODES from ./connect then uses nothing from the host
// chunk, and because package.json "sideEffects" does not list the Connect
// outputs, a bundler that honours "sideEffects" (esbuild, webpack) drops
// that file whole. Rollup/Vite already removed the host statement by
// statement.
//
// `platform: 'neutral'`: the graph uses no Node built-ins and touches no
// browser globals at module scope, so one build serves both runtimes. `ws`
// is reached only through a dynamic import inside WebSocketTransport and
// stays external.
//
// NOTE: entry files must never import each other — only non-entry chunks.
// An entry that imported dist/connect/index.js would let a consumer's
// vi.mock('@unicitylabs/sphere-sdk/connect') leak into autoConnect.
{
entry: {
'connect/index': 'connect/index.ts',
'connect/internal/host': 'connect/host/index.ts',
'connect/internal/nft-wire': 'connect/nft-wire.ts',
'impl/browser/connect/index': 'impl/browser/connect/index.ts',
'impl/nodejs/connect/index': 'impl/nodejs/connect/index.ts',
},
format: ['esm'],
dts: true,
clean: false,
splitting: true,
sourcemap: true,
platform: 'neutral',
target: 'es2022',
external: [
/^@unicitylabs\//,
'ws',
],
esbuildOptions(options) {
// Shared chunks live under dist/connect/, not in the dist/ root.
options.chunkNames = 'connect/chunks/[name]-[hash]';
},
},
// Sphere Connect — CJS: deliberately still one unsplit bundle per entry,
// byte-for-byte the 0.17.2 build shape (minus the dead host code the
// transports' barrel import used to drag in).
//
// Why not split these too: tsup implements CJS splitting by running every
// emitted chunk through sucrase, which renames ConnectClient/ConnectHost and
// the WS transports to `_class` (`.name` is part of our public surface in
// logs and error reporting), switches class fields to assignment semantics
// and degrades the .cjs.map files. No consumer loads the .cjs Connect files,
// so the duplicate-class fix is shipped for ESM only and CJS keeps today's
// behaviour. If a CJS consumer ever needs one ConnectError across entries,
// revisit with `keepNames` plus CJS class-identity tests.
//
// These three also emit the .d.cts declarations package.json points at.
{
entry: { 'connect/index': 'connect/index.ts' },
format: ['cjs'],
dts: true,
clean: false,
splitting: false,
sourcemap: true,
platform: 'neutral',
target: 'es2022',
external: [
/^@unicitylabs\//,
],
},
{
entry: { 'impl/browser/connect/index': 'impl/browser/connect/index.ts' },
format: ['cjs'],
dts: true,
clean: false,
splitting: false,
sourcemap: true,
platform: 'browser',
target: 'es2022',
external: [
/^@unicitylabs\//,
],
},
{
entry: { 'impl/nodejs/connect/index': 'impl/nodejs/connect/index.ts' },
format: ['cjs'],
dts: true,
clean: false,
splitting: false,
sourcemap: true,
platform: 'node',
target: 'es2022',
external: [
/^@unicitylabs\//,
'ws',
],
},
];