Skip to content

Commit

Permalink
chore: better validation error message for dts build (#18948)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Dec 13, 2024
1 parent 638de0f commit 63b82f1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/vite/rollup.dts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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('../') &&
Expand All @@ -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
}
}
Expand Down

0 comments on commit 63b82f1

Please sign in to comment.