-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsup.config.ts
More file actions
88 lines (86 loc) · 2.83 KB
/
Copy pathtsup.config.ts
File metadata and controls
88 lines (86 loc) · 2.83 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
import { defineConfig } from 'tsup'
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
// esbuild strips module-level "use client" directives during bundling, so we
// re-add them to the emitted client-only bundles after each build. Required for
// Next.js App Router / RSC consumers importing the hooks/components directly.
function prependUseClient(files: string[]) {
return async () => {
for (const file of files) {
if (!existsSync(file)) continue
const content = readFileSync(file, 'utf8')
if (/^(['"])use client\1/.test(content)) continue
writeFileSync(file, `'use client';\n${content}`)
}
}
}
export default defineConfig([
// Core (framework-agnostic, zero deps)
{
entry: { 'core/index': 'src/core/index.ts' },
format: ['esm', 'cjs'],
dts: true,
clean: true,
treeshake: true,
splitting: false,
sourcemap: false,
external: ['react', 'react-dom'],
},
// React hooks (client-only — needs the 'use client' directive so
// Next.js App Router / RSC consumers can import the hooks directly)
{
entry: { 'react/index': 'src/react/index.ts' },
format: ['esm', 'cjs'],
dts: true,
treeshake: true,
splitting: false,
sourcemap: false,
onSuccess: prependUseClient(['dist/react/index.js', 'dist/react/index.cjs']),
external: ['react', 'react-dom'],
},
// cmdk adapter (client-only — renders React components + hooks)
{
entry: { 'adapters/cmdk/index': 'src/adapters/cmdk/index.ts' },
format: ['esm', 'cjs'],
dts: true,
treeshake: true,
splitting: false,
sourcemap: false,
onSuccess: prependUseClient(['dist/adapters/cmdk/index.js', 'dist/adapters/cmdk/index.cjs']),
external: ['react', 'react-dom', 'cmdk'],
},
// React Router adapter
{
entry: { 'adapters/react-router/index': 'src/adapters/react-router/index.ts' },
format: ['esm', 'cjs'],
dts: true,
treeshake: true,
splitting: false,
sourcemap: false,
external: ['react', 'react-dom', 'react-router', 'react-router-dom'],
},
// match-sorter search backend
{
entry: { 'core/search-match-sorter': 'src/core/search-match-sorter.ts' },
format: ['esm', 'cjs'],
dts: true,
treeshake: true,
splitting: false,
sourcemap: false,
external: ['match-sorter'],
},
// CLI tool — emit CJS and bundle commander so the bin is fully self-contained.
// commander is a devDependency (not shipped to consumers) and does internal
// require()s of Node built-ins; CJS output lets those resolve natively without
// the ESM dynamic-require shim that would otherwise throw.
{
entry: { 'cli/index': 'src/cli/index.ts' },
format: ['cjs'],
dts: false,
treeshake: true,
splitting: false,
sourcemap: false,
banner: { js: '#!/usr/bin/env node' },
noExternal: ['commander'],
external: [],
},
])