@@ -15,6 +15,14 @@ const TEMPLATE_VARIABLE: &str = "${configDir}";
1515
1616pub type CompilerOptionsPathsMap = IndexMap < String , Vec < String > , BuildHasherDefault < FxHasher > > ;
1717
18+ /// Project Reference
19+ ///
20+ /// <https://www.typescriptlang.org/docs/handbook/project-references.html>
21+ #[ derive( Debug , Deserialize ) ]
22+ pub struct ProjectReference {
23+ pub path : PathBuf ,
24+ }
25+
1826#[ derive( Debug , Deserialize ) ]
1927#[ serde( rename_all = "camelCase" ) ]
2028pub struct TsConfig {
@@ -42,9 +50,14 @@ pub struct TsConfig {
4250 #[ serde( default ) ]
4351 pub compiler_options : CompilerOptions ,
4452
45- /// Bubbled up project references with a reference to their tsconfig.
4653 #[ serde( default ) ]
4754 pub references : Vec < ProjectReference > ,
55+
56+ /// Resolved project references.
57+ ///
58+ /// Corresponds to each item in [TsConfig::references].
59+ #[ serde( skip) ]
60+ pub references_resolved : Vec < Arc < TsConfig > > ,
4861}
4962
5063impl TsConfig {
@@ -111,26 +124,14 @@ impl TsConfig {
111124 }
112125 TsconfigReferences :: Auto => { }
113126 TsconfigReferences :: Paths ( paths) => {
114- self . references = paths
115- . iter ( )
116- . map ( |path| ProjectReference { path : path. clone ( ) , tsconfig : None } )
117- . collect ( ) ;
127+ self . references =
128+ paths. iter ( ) . map ( |path| ProjectReference { path : path. clone ( ) } ) . collect ( ) ;
118129 }
119130 }
120131
121132 !self . references . is_empty ( )
122133 }
123134
124- /// Returns references to other tsconfig files.
125- pub ( crate ) fn references ( & self ) -> impl Iterator < Item = & ProjectReference > {
126- self . references . iter ( )
127- }
128-
129- /// Returns mutable references to other tsconfig files.
130- pub ( crate ) fn references_mut ( & mut self ) -> impl Iterator < Item = & mut ProjectReference > {
131- self . references . iter_mut ( )
132- }
133-
134135 /// Returns the base path from which to resolve aliases.
135136 ///
136137 /// The base path can be configured by the user as part of the
@@ -348,7 +349,7 @@ impl TsConfig {
348349 #[ must_use]
349350 pub ( crate ) fn resolve ( & self , path : & Path , specifier : & str ) -> Vec < PathBuf > {
350351 let paths = self . resolve_path_alias ( specifier) ;
351- for tsconfig in self . references ( ) . filter_map ( ProjectReference :: tsconfig ) {
352+ for tsconfig in & self . references_resolved {
352353 if path. starts_with ( tsconfig. base_path ( ) ) {
353354 return [ tsconfig. resolve_path_alias ( specifier) , paths] . concat ( ) ;
354355 }
@@ -668,36 +669,6 @@ pub enum ExtendsField {
668669 Multiple ( Vec < String > ) ,
669670}
670671
671- /// Project Reference
672- ///
673- /// <https://www.typescriptlang.org/docs/handbook/project-references.html>
674- #[ derive( Debug , Deserialize ) ]
675- pub struct ProjectReference {
676- pub path : PathBuf ,
677-
678- #[ serde( skip) ]
679- pub tsconfig : Option < Arc < TsConfig > > ,
680- }
681-
682- impl ProjectReference {
683- /// Returns the path to a directory containing a `tsconfig.json` file, or to
684- /// the config file itself (which may have any name).
685- #[ must_use]
686- pub fn path ( & self ) -> & Path {
687- & self . path
688- }
689- /// Returns the resolved tsconfig, if one has been set.
690- #[ must_use]
691- pub fn tsconfig ( & self ) -> Option < Arc < TsConfig > > {
692- self . tsconfig . clone ( )
693- }
694-
695- /// Sets the resolved tsconfig.
696- pub fn set_tsconfig ( & mut self , tsconfig : Arc < TsConfig > ) {
697- self . tsconfig . replace ( tsconfig) ;
698- }
699- }
700-
701672impl TsConfig {
702673 /// Parses the tsconfig from a JSON string.
703674 ///
0 commit comments