mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
fix: handle tsconfig watching without watchChange as tsconfig files are not modules that pass through it
This commit is contained in:
parent
a8bf2bc74c
commit
ee6f9c86b4
@ -18,8 +18,9 @@ import {
|
|||||||
createFilter,
|
createFilter,
|
||||||
ensureWatchedFile,
|
ensureWatchedFile,
|
||||||
generateCodeFrame,
|
generateCodeFrame,
|
||||||
|
normalizePath,
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import type { ViteDevServer } from '../server'
|
|
||||||
import type { ResolvedConfig } from '../config'
|
import type { ResolvedConfig } from '../config'
|
||||||
import type { Plugin } from '../plugin'
|
import type { Plugin } from '../plugin'
|
||||||
import { cleanUrl } from '../../shared/utils'
|
import { cleanUrl } from '../../shared/utils'
|
||||||
@ -254,41 +255,45 @@ export function esbuildPlugin(config: ResolvedConfig): Plugin {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let server: ViteDevServer
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'vite:esbuild',
|
name: 'vite:esbuild',
|
||||||
configureServer(_server) {
|
configureServer(server) {
|
||||||
server = _server
|
// we need to watch all files to find changes to previously unknown tsconfig.json files
|
||||||
},
|
server.watcher.on('all', (event, file) => {
|
||||||
watchChange(id) {
|
if (
|
||||||
if (
|
(event === 'add' || event === 'change' || event === 'unlink') &&
|
||||||
path.basename(id) === 'tsconfig.json' ||
|
file.slice(-5) === '.json'
|
||||||
(id.endsWith('.json') && tsconfckCache?.hasParseResult(id))
|
) {
|
||||||
) {
|
const filename = normalizePath(file)
|
||||||
server.config.logger.info(
|
if (
|
||||||
`changed tsconfig file detected: ${id} - Clearing cache and forcing full-reload to ensure TypeScript is compiled with updated config values.`,
|
filename.slice(-14) === '/tsconfig.json' ||
|
||||||
{ clear: server.config.clearScreen, timestamp: true },
|
tsconfckCache?.hasParseResult(filename)
|
||||||
)
|
) {
|
||||||
|
server.config.logger.info(
|
||||||
|
`changed tsconfig file detected: ${filename} - Clearing cache and forcing full-reload to ensure TypeScript is compiled with updated config values.`,
|
||||||
|
{ clear: server.config.clearScreen, timestamp: true },
|
||||||
|
)
|
||||||
|
|
||||||
// TODO: more finegrained invalidation than the nuclear option below
|
// TODO: more finegrained invalidation than the nuclear option below
|
||||||
|
|
||||||
// clear module graph to remove code compiled with outdated config
|
// clear module graph to remove code compiled with outdated config
|
||||||
for (const environment of Object.values(server.environments)) {
|
for (const environment of Object.values(server.environments)) {
|
||||||
environment.moduleGraph.invalidateAll()
|
environment.moduleGraph.invalidateAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset tsconfck cache so that recompile works with up2date configs
|
||||||
|
tsconfckCache?.clear()
|
||||||
|
|
||||||
|
// reload environments
|
||||||
|
for (const environment of Object.values(server.environments)) {
|
||||||
|
environment.hot.send({
|
||||||
|
type: 'full-reload',
|
||||||
|
path: '*',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
// reset tsconfck cache so that recompile works with up2date configs
|
|
||||||
tsconfckCache?.clear()
|
|
||||||
|
|
||||||
// reload environments
|
|
||||||
for (const environment of Object.values(server.environments)) {
|
|
||||||
environment.hot.send({
|
|
||||||
type: 'full-reload',
|
|
||||||
path: '*',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async transform(code, id) {
|
async transform(code, id) {
|
||||||
if (filter(id) || filter(cleanUrl(id))) {
|
if (filter(id) || filter(cleanUrl(id))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user