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

Function reloadOnTsconfigChange

packages/vite/src/node/plugins/esbuild.ts:540–573  ·  view source on GitHub ↗
(
  server: ViteDevServer,
  changedFile: string,
)

Source from the content-addressed store, hash-verified

538}
539
540export function reloadOnTsconfigChange(
541 server: ViteDevServer,
542 changedFile: string,
543): void {
544 // any tsconfig.json that's added in the workspace could be closer to a code file than a previously cached one
545 // any json file in the tsconfig cache could have been used to compile ts
546 if (changedFile.endsWith('.json')) {
547 const cache = getTSConfigResolutionCache(server.config)
548 if (changedFile.endsWith('/tsconfig.json')) {
549 server.config.logger.info(
550 `changed tsconfig file detected: ${changedFile} - Clearing cache and forcing full-reload to ensure TypeScript is compiled with updated config values.`,
551 { clear: server.config.clearScreen, timestamp: true },
552 )
553
554 // TODO: more finegrained invalidation than the nuclear option below
555
556 // clear module graph to remove code compiled with outdated config
557 for (const environment of Object.values(server.environments)) {
558 environment.moduleGraph.invalidateAll()
559 }
560
561 // reset the cache so that recompile works with up2date configs
562 cache.clear()
563
564 // reload environments
565 for (const environment of Object.values(server.environments)) {
566 environment.hot.send({
567 type: 'full-reload',
568 path: '*',
569 })
570 }
571 }
572 }
573}

Callers 2

onFileAddUnlinkFunction · 0.90
onFileChangeFunction · 0.90

Calls 5

infoMethod · 0.65
sendMethod · 0.65
invalidateAllMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected