Skip to content

Commit 63b82f1

Browse files
authoredDec 13, 2024··
chore: better validation error message for dts build (#18948)
1 parent 638de0f commit 63b82f1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed
 

‎packages/vite/rollup.dts.config.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,15 @@ function patchTypes(): Plugin {
112112
* Runner chunk should only import local dependencies to stay lightweight
113113
*/
114114
function validateRunnerChunk(this: PluginContext, chunk: RenderedChunk) {
115-
for (const id of chunk.imports) {
115+
for (const [id, bindings] of Object.entries(chunk.importedBindings)) {
116116
if (
117117
!id.startsWith('./') &&
118118
!id.startsWith('../') &&
119119
!id.startsWith('types.d')
120120
) {
121-
this.warn(`${chunk.fileName} imports "${id}" which is not allowed`)
121+
this.warn(
122+
`${chunk.fileName} imports "${bindings.join(', ')}" from "${id}" which is not allowed`,
123+
)
122124
process.exitCode = 1
123125
}
124126
}
@@ -129,7 +131,7 @@ function validateRunnerChunk(this: PluginContext, chunk: RenderedChunk) {
129131
*/
130132
function validateChunkImports(this: PluginContext, chunk: RenderedChunk) {
131133
const deps = Object.keys(pkg.dependencies)
132-
for (const id of chunk.imports) {
134+
for (const [id, bindings] of Object.entries(chunk.importedBindings)) {
133135
if (
134136
!id.startsWith('./') &&
135137
!id.startsWith('../') &&
@@ -141,7 +143,9 @@ function validateChunkImports(this: PluginContext, chunk: RenderedChunk) {
141143
) {
142144
// If validation failed, only warn and set exit code 1 so that files
143145
// are written to disk for inspection, but the build will fail
144-
this.warn(`${chunk.fileName} imports "${id}" which is not allowed`)
146+
this.warn(
147+
`${chunk.fileName} imports "${bindings.join(', ')}" from "${id}" which is not allowed`,
148+
)
145149
process.exitCode = 1
146150
}
147151
}

0 commit comments

Comments
 (0)
Please sign in to comment.