@@ -2,8 +2,8 @@ import path from 'node:path'
22import colors from 'picocolors'
33import type { RawSourceMap } from '@jridgewell/remapping'
44import type { InternalModuleFormat , SourceMap } from 'rolldown'
5- import type { TSConfckParseResult } from 'tsconfck '
6- import { TSConfckCache , TSConfckParseError , parse } from 'tsconfck '
5+ import { resolveTsconfig } from 'rolldown/experimental '
6+ import { TsconfigCache } from 'rolldown/utils '
77import type {
88 EsbuildLoader ,
99 EsbuildMessage ,
@@ -145,13 +145,19 @@ export async function transformWithEsbuild(
145145 ]
146146 const compilerOptionsForFile : TSCompilerOptions = { }
147147 if ( loader === 'ts' || loader === 'tsx' ) {
148- try {
149- const { tsconfig : loadedTsconfig , tsconfigFile } =
150- await loadTsconfigJsonForFile ( filename , config )
148+ const result = resolveTsconfig (
149+ filename ,
150+ getTSConfigResolutionCache ( config ) ,
151+ )
152+ if ( result ) {
153+ const { tsconfig : loadedTsconfig , tsconfigFilePaths } = result
151154 // tsconfig could be out of root, make sure it is watched on dev
152- if ( watcher && tsconfigFile && config ) {
153- ensureWatchedFile ( watcher , tsconfigFile , config . root )
155+ if ( watcher && config ) {
156+ for ( const tsconfigFile of tsconfigFilePaths ) {
157+ ensureWatchedFile ( watcher , tsconfigFile , config . root )
158+ }
154159 }
160+
155161 const loadedCompilerOptions = loadedTsconfig . compilerOptions ?? { }
156162
157163 for ( const field of meaningfulFields ) {
@@ -160,14 +166,6 @@ export async function transformWithEsbuild(
160166 compilerOptionsForFile [ field ] = loadedCompilerOptions [ field ]
161167 }
162168 }
163- } catch ( e ) {
164- if ( e instanceof TSConfckParseError ) {
165- // tsconfig could be out of root, make sure it is watched on dev
166- if ( watcher && e . tsconfigFile && config ) {
167- ensureWatchedFile ( watcher , e . tsconfigFile , config . root )
168- }
169- }
170- throw e
171169 }
172170 }
173171
@@ -522,47 +520,30 @@ function prettifyMessage(m: EsbuildMessage, code: string): string {
522520 return res + `\n`
523521}
524522
525- let globalTSConfckCache : TSConfckCache < TSConfckParseResult > | undefined
526- const tsconfckCacheMap = new WeakMap <
527- ResolvedConfig ,
528- TSConfckCache < TSConfckParseResult >
529- > ( )
523+ let globalTSConfigResolutionCache : TsconfigCache | undefined
524+ const tsconfigResolutionCacheMap = new WeakMap < ResolvedConfig , TsconfigCache > ( )
530525
531- function getTSConfckCache ( config ?: ResolvedConfig ) {
526+ function getTSConfigResolutionCache ( config ?: ResolvedConfig ) {
532527 if ( ! config ) {
533- return ( globalTSConfckCache ??= new TSConfckCache < TSConfckParseResult > ( ) )
528+ return ( globalTSConfigResolutionCache ??= new TsconfigCache ( ) )
534529 }
535- let cache = tsconfckCacheMap . get ( config )
530+ let cache = tsconfigResolutionCacheMap . get ( config )
536531 if ( ! cache ) {
537- cache = new TSConfckCache < TSConfckParseResult > ( )
538- tsconfckCacheMap . set ( config , cache )
532+ cache = new TsconfigCache ( )
533+ tsconfigResolutionCacheMap . set ( config , cache )
539534 }
540535 return cache
541536}
542537
543- export async function loadTsconfigJsonForFile (
544- filename : string ,
545- config ?: ResolvedConfig ,
546- ) : Promise < { tsconfigFile : string ; tsconfig : TSConfigJSON } > {
547- const { tsconfig, tsconfigFile } = await parse ( filename , {
548- cache : getTSConfckCache ( config ) ,
549- ignoreNodeModules : true ,
550- } )
551- return { tsconfigFile, tsconfig }
552- }
553-
554538export async function reloadOnTsconfigChange (
555539 server : ViteDevServer ,
556540 changedFile : string ,
557541) : Promise < void > {
558542 // any tsconfig.json that's added in the workspace could be closer to a code file than a previously cached one
559543 // any json file in the tsconfig cache could have been used to compile ts
560544 if ( changedFile . endsWith ( '.json' ) ) {
561- const cache = getTSConfckCache ( server . config )
562- if (
563- changedFile . endsWith ( '/tsconfig.json' ) ||
564- cache . hasParseResult ( changedFile )
565- ) {
545+ const cache = getTSConfigResolutionCache ( server . config )
546+ if ( changedFile . endsWith ( '/tsconfig.json' ) || cache . size ( ) > 0 ) {
566547 server . config . logger . info (
567548 `changed tsconfig file detected: ${ changedFile } - Clearing cache and forcing full-reload to ensure TypeScript is compiled with updated config values.` ,
568549 { clear : server . config . clearScreen , timestamp : true } ,
@@ -575,7 +556,7 @@ export async function reloadOnTsconfigChange(
575556 environment . moduleGraph . invalidateAll ( )
576557 }
577558
578- // reset tsconfck cache so that recompile works with up2date configs
559+ // reset the cache so that recompile works with up2date configs
579560 cache . clear ( )
580561
581562 // reload environments
0 commit comments