Skip to content

Commit a66afa3

Browse files
authored
chore: generate dts internally by rolldown-plugin-dts (vitejs#20093)
1 parent c127955 commit a66afa3

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

packages/vite/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@
7070
"dev": "premove dist && pnpm build-bundle -w",
7171
"build": "premove dist && pnpm build-bundle && pnpm build-types",
7272
"build-bundle": "rolldown --config rollup.config.ts",
73-
"build-types": "pnpm build-types-temp && pnpm build-types-roll && pnpm build-types-check",
74-
"build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src/node/tsconfig.build.json",
75-
"build-types-roll": "rolldown --config rollup.dts.config.ts && premove temp",
73+
"build-types": "pnpm build-types-roll && pnpm build-types-check",
74+
"build-types-roll": "rolldown --config rollup.dts.config.ts",
7675
"build-types-check": "tsc --project tsconfig.check.json",
7776
"typecheck": "tsc --noEmit && tsc --noEmit -p src/node",
7877
"lint": "eslint --cache --ext .ts src/**",

packages/vite/rollup.dts.config.ts

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,21 @@ const external = [
3535

3636
export default defineConfig({
3737
input: {
38-
index: './temp/src/node/index.d.ts',
39-
'module-runner': './temp/src/module-runner/index.d.ts',
38+
index: './src/node/index.ts',
39+
'module-runner': './src/module-runner/index.ts',
4040
},
4141
output: {
4242
dir: './dist/node',
4343
format: 'esm',
4444
},
45+
treeshake: {
46+
moduleSideEffects: 'no-external',
47+
},
4548
external,
46-
plugins: [patchTypes(), dts({ dtsInput: true })],
49+
plugins: [
50+
patchTypes(),
51+
dts({ tsconfig: './src/node/tsconfig.build.json', emitDtsOnly: true }),
52+
],
4753
})
4854

4955
// Taken from https://stackoverflow.com/a/36328890
@@ -114,7 +120,7 @@ function patchTypes(): Plugin {
114120
resolveId: {
115121
order: 'pre',
116122
filter: {
117-
id: /^(dep-)*types\//,
123+
id: /^(dep-)?types\//,
118124
},
119125
handler(id) {
120126
// Dep types should be bundled
@@ -134,26 +140,29 @@ function patchTypes(): Plugin {
134140
}
135141
},
136142
},
137-
generateBundle(_opts, bundle) {
138-
for (const chunk of Object.values(bundle)) {
139-
if (chunk.type !== 'chunk') continue
143+
generateBundle: {
144+
order: 'post',
145+
handler(_opts, bundle) {
146+
for (const chunk of Object.values(bundle)) {
147+
if (chunk.type !== 'chunk') continue
140148

141-
const ast = parseAst(chunk.code, { lang: 'ts', sourceType: 'module' })
142-
const importBindings = getAllImportBindings(ast)
143-
if (
144-
chunk.fileName.startsWith('module-runner') ||
145-
// index and moduleRunner have a common chunk "moduleRunnerTransport"
146-
chunk.fileName.startsWith('moduleRunnerTransport') ||
147-
chunk.fileName.startsWith('types.d-')
148-
) {
149-
validateRunnerChunk.call(this, chunk, importBindings)
150-
} else {
151-
validateChunkImports.call(this, chunk, importBindings)
152-
replaceConfusingTypeNames.call(this, chunk, importBindings)
153-
stripInternalTypes.call(this, chunk)
154-
cleanUnnecessaryComments(chunk)
149+
const ast = parseAst(chunk.code, { lang: 'ts', sourceType: 'module' })
150+
const importBindings = getAllImportBindings(ast)
151+
if (
152+
chunk.fileName.startsWith('module-runner') ||
153+
// index and moduleRunner have a common chunk "moduleRunnerTransport"
154+
chunk.fileName.startsWith('moduleRunnerTransport') ||
155+
chunk.fileName.startsWith('types.d-')
156+
) {
157+
validateRunnerChunk.call(this, chunk, importBindings)
158+
} else {
159+
validateChunkImports.call(this, chunk, importBindings)
160+
replaceConfusingTypeNames.call(this, chunk, importBindings)
161+
stripInternalTypes.call(this, chunk)
162+
cleanUnnecessaryComments(chunk)
163+
}
155164
}
156-
}
165+
},
157166
},
158167
}
159168
}

0 commit comments

Comments
 (0)