Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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