MCPcopy
hub / github.com/vitejs/vite / validateChunkImports

Function validateChunkImports

packages/vite/rolldown.dts.config.ts:234–261  ·  view source on GitHub ↗

* Validate that chunk imports do not import dev deps

(
  this: PluginContext,
  chunk: RenderedChunk,
  importBindings: ImportBindings[],
)

Source from the content-addressed store, hash-verified

232 * Validate that chunk imports do not import dev deps
233 */
234function validateChunkImports(
235 this: PluginContext,
236 chunk: RenderedChunk,
237 importBindings: ImportBindings[],
238) {
239 const deps = Object.keys(pkg.dependencies)
240 for (const { id, bindings } of importBindings) {
241 if (
242 !id.startsWith('./') &&
243 !id.startsWith('../') &&
244 !id.startsWith('#') &&
245 !id.startsWith('node:') &&
246 !id.startsWith('types.d') &&
247 !id.startsWith('vite/') &&
248 // index and moduleRunner have a common chunk
249 !id.startsWith('chunks/') &&
250 !deps.includes(id) &&
251 !deps.some((name) => id.startsWith(name + '/'))
252 ) {
253 // If validation failed, only warn and set exit code 1 so that files
254 // are written to disk for inspection, but the build will fail
255 this.warn(
256 `${chunk.fileName} imports "${bindings.join(', ')}" from "${id}" which is not allowed`,
257 )
258 process.exitCode = 1
259 }
260 }
261}
262
263/**
264 * Rollup deduplicate type names with a trailing `$1` or `$2`, which can be

Callers

nothing calls this directly

Calls 1

warnMethod · 0.65

Tested by

no test coverage detected