( server: ViteDevServer, changedFile: string, )
| 538 | } |
| 539 | |
| 540 | export 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 | } |
no test coverage detected