-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
73 lines (70 loc) · 2.3 KB
/
tsdown.config.ts
File metadata and controls
73 lines (70 loc) · 2.3 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
import { defineConfig } from 'tsdown';
/**
* Rewrite `../versions.js` → `./versions.js` at resolve time.
*
* `src/migration/migrator.ts` dynamically imports `../versions.js` (one directory up
* from `src/migration/`). After bundling, all output lands in `dist/`, so the correct
* runtime path is `./versions.js`. Using `resolveId` rewrites the specifier during
* resolution rather than doing post-hoc string surgery on rendered chunks.
*/
const fixVersionsPathPlugin = {
name: 'fix-versions-path',
resolveId(source: string) {
if (source === '../versions.js') {
return { id: './versions.js', external: true };
}
return undefined;
},
};
export default defineConfig([
// ESM — all entry points bundled to dist/
{
name: 'cli',
entry: {
bin: './src/bin.ts',
index: './src/index.ts',
'define-config': './src/define-config.ts',
fmt: './src/fmt.ts',
lint: './src/lint.ts',
pack: './src/pack.ts',
'pack-bin': './src/pack-bin.ts',
// Global commands — explicit entries ensure lazy loading via dynamic import in bin.ts.
// Without these, tsdown inlines them into bin.js, breaking on-demand loading.
'create/bin': './src/create/bin.ts',
'migration/bin': './src/migration/bin.ts',
version: './src/version.ts',
'config/bin': './src/config/bin.ts',
'mcp/bin': './src/mcp/bin.ts',
'staged/bin': './src/staged/bin.ts',
},
outDir: 'dist',
format: 'esm',
fixedExtension: false,
shims: true,
dts: true,
clean: true,
// NAPI binding uses a relative path that tsdown can't auto-detect from package.json
deps: { neverBundle: [/\.\.\/binding\/index\.(js|cjs)/] },
inputOptions: {
resolve: {
// Prefer ESM entry (module field) over CJS/UMD (main field) for bundled deps.
// Without this, packages like jsonc-parser resolve to their UMD entry which
// has internal require('./impl/...') calls that break in bundled ESM output.
mainFields: ['module', 'main'],
},
},
plugins: [fixVersionsPathPlugin],
},
// CJS — dual-format entries
{
name: 'cli-cjs',
entry: {
'define-config': './src/define-config.ts',
index: './src/index.cts',
},
outDir: 'dist',
format: 'cjs',
dts: false,
clean: false,
},
]);