-
-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
167 lines (163 loc) · 4.49 KB
/
Copy pathtsdown.config.ts
File metadata and controls
167 lines (163 loc) · 4.49 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
import path from 'node:path';
import process from 'node:process';
import { defineConfig } from 'tsdown';
import { buildTemplates } from './packages/sv/src/create/scripts/build-templates.js';
/**
* Throwaway output dir for the single-entry DTS builds that feed
* `scripts/generate-api-surface.js`. Gitignored; never published.
*/
const API_SURFACE_DIR = 'dts-api-surface';
/** Shared `deps` settings for every `sv` build (runtime + DTS-only api-surface). */
const svDeps = {
// These are root-level devDependencies used only by testing.ts.
// Without this, the DTS plugin inlines their entire type trees
// (vitest pulls in postcss, vite, chai, etc.) bloating testing.d.mts.
neverBundle: [/^vitest/, /^@vitest\//, /^@playwright\//, /^vite$/, /^postcss$/],
onlyBundle: [
'@clack/core',
'@clack/prompts',
'commander',
'duplexer',
'empathic',
'event-stream',
'fast-string-truncated-width',
'fast-string-width',
'fast-wrap-ansi',
'from',
'map-stream',
'modern-tar',
'pause-stream',
'ps-tree',
'sisteransi',
'split',
'stream-combiner',
'through',
'tinyexec',
'valibot'
]
};
export default defineConfig([
{
cwd: path.resolve('packages/sv'),
entry: ['src/index.ts', 'src/testing.ts', 'bin.ts'],
sourcemap: !process.env.CI,
dts: {
oxc: true
},
failOnWarn: true,
deps: svDeps,
plugins: [],
inputOptions: {
experimental: {
resolveNewUrlToAsset: false
},
// rolldown-plugin-dts:fake-js transforms the dts entry without emitting a
// sourcemap, which rolldown >=1.1 flags as SOURCEMAP_BROKEN. The warning is
// spurious (it only concerns the generated .d.mts), so ignore just that code;
// failOnWarn: true still applies to every other warning.
onLog(level, log, defaultHandler) {
if (log.code === 'SOURCEMAP_BROKEN') return;
defaultHandler(level, log);
}
},
hooks: {
async 'build:before'() {
await buildCliTemplates();
}
}
},
// sv: DTS-only single-entry builds for the api-surface snapshots.
// The runtime build above code-splits shared declarations into an `engine-*.d.mts`
// chunk, so its entry `.d.mts` files only re-export names without signatures.
// Building each public entry on its own emits a self-contained `.d.ts` with every
// referenced declaration inlined (no shared chunk), which `generate-api-surface.js`
// reads instead. Output goes to a throwaway, gitignored dir.
{
cwd: path.resolve('packages/sv'),
entry: ['src/index.ts'],
outDir: `${API_SURFACE_DIR}/index`,
dts: {
oxc: true,
emitDtsOnly: true
},
failOnWarn: true,
deps: svDeps,
inputOptions: {
experimental: {
resolveNewUrlToAsset: false
}
}
},
{
cwd: path.resolve('packages/sv'),
entry: ['src/testing.ts'],
outDir: `${API_SURFACE_DIR}/testing`,
dts: {
oxc: true,
emitDtsOnly: true
},
failOnWarn: true,
deps: svDeps,
inputOptions: {
experimental: {
resolveNewUrlToAsset: false
}
}
},
// sv-utils: runtime build (bundles everything including svelte)
{
cwd: path.resolve('packages/sv-utils'),
entry: ['src/index.ts'],
sourcemap: !process.env.CI,
dts: false,
failOnWarn: true,
deps: {
onlyBundle: [
'@jridgewell/gen-mapping',
'@jridgewell/remapping',
'@jridgewell/sourcemap-codec',
'@jridgewell/trace-mapping',
'@sveltejs/acorn-typescript',
'acorn',
'aria-query',
'axobject-query',
'decircular',
'dedent',
'diff',
'esrap',
'locate-character',
'package-manager-detector',
'silver-fleece',
'smol-toml',
'svelte',
'verkit',
'yaml',
'zimmerframe'
]
}
},
// sv-utils: DTS-only build (svelte externalized)
// Svelte uses `declare module 'svelte/compiler'` which rolldown-plugin-dts
// v0.21+ cannot inline. This is a known issue: https://github.com/sveltejs/svelte/issues/17520
// Once svelte ships separate .d.ts files per entry point, this split can be removed.
{
cwd: path.resolve('packages/sv-utils'),
entry: ['src/index.ts'],
dts: {
oxc: true,
emitDtsOnly: true
},
failOnWarn: true,
deps: {
neverBundle: [/^svelte/, '@types/estree', 'estree', 'yaml', 'package-manager-detector'],
onlyBundle: ['smol-toml', 'zimmerframe', 'dedent']
}
}
]);
export async function buildCliTemplates() {
const start = performance.now();
await buildTemplates(path.resolve('packages/sv/dist'));
await buildTemplates(path.resolve('packages/sv/src/create/dist'));
const [green, reset] = ['\x1b[32m', '\x1b[0m'];
console.log(`${green}✔${reset} Templates built in ${Math.round(performance.now() - start)}ms`);
}