From 63b82f1e29a00d06a82144fd03ea8d6eff114290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Fri, 13 Dec 2024 21:02:06 +0900 Subject: [PATCH] chore: better validation error message for dts build (#18948) --- packages/vite/rollup.dts.config.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/vite/rollup.dts.config.ts b/packages/vite/rollup.dts.config.ts index e622053ba156ba..46306f0a22d6b5 100644 --- a/packages/vite/rollup.dts.config.ts +++ b/packages/vite/rollup.dts.config.ts @@ -112,13 +112,15 @@ function patchTypes(): Plugin { * Runner chunk should only import local dependencies to stay lightweight */ function validateRunnerChunk(this: PluginContext, chunk: RenderedChunk) { - for (const id of chunk.imports) { + for (const [id, bindings] of Object.entries(chunk.importedBindings)) { if ( !id.startsWith('./') && !id.startsWith('../') && !id.startsWith('types.d') ) { - this.warn(`${chunk.fileName} imports "${id}" which is not allowed`) + this.warn( + `${chunk.fileName} imports "${bindings.join(', ')}" from "${id}" which is not allowed`, + ) process.exitCode = 1 } } @@ -129,7 +131,7 @@ function validateRunnerChunk(this: PluginContext, chunk: RenderedChunk) { */ function validateChunkImports(this: PluginContext, chunk: RenderedChunk) { const deps = Object.keys(pkg.dependencies) - for (const id of chunk.imports) { + for (const [id, bindings] of Object.entries(chunk.importedBindings)) { if ( !id.startsWith('./') && !id.startsWith('../') && @@ -141,7 +143,9 @@ function validateChunkImports(this: PluginContext, chunk: RenderedChunk) { ) { // If validation failed, only warn and set exit code 1 so that files // are written to disk for inspection, but the build will fail - this.warn(`${chunk.fileName} imports "${id}" which is not allowed`) + this.warn( + `${chunk.fileName} imports "${bindings.join(', ')}" from "${id}" which is not allowed`, + ) process.exitCode = 1 } }