@@ -33,7 +33,6 @@ use crate::UrlToFilePathError;
33
33
34
34
mod ts;
35
35
36
- pub use ts:: CompilerOptions ;
37
36
pub use ts:: EmitConfigOptions ;
38
37
pub use ts:: IgnoredCompilerOptions ;
39
38
pub use ts:: JsxImportSourceConfig ;
@@ -64,6 +63,15 @@ pub enum IntoResolvedErrorKind {
64
63
InvalidExclude ( crate :: glob:: FromExcludeRelativePathOrPatternsError ) ,
65
64
}
66
65
66
+ #[ derive( Debug , Error , JsError ) ]
67
+ #[ class( generic) ]
68
+ #[ error( "Failed deserilaizing \" compilerOptions\" .\" types\" in {}" , self . specifier) ]
69
+ pub struct CompilerOptionTypesDeserializeError {
70
+ specifier : Url ,
71
+ #[ source]
72
+ source : serde_json:: Error ,
73
+ }
74
+
67
75
#[ derive( Clone , Debug , Default , Deserialize , PartialEq ) ]
68
76
#[ serde( default , deny_unknown_fields) ]
69
77
struct SerializedFilesConfig {
@@ -705,11 +713,20 @@ pub trait DenoJsonCache {
705
713
fn set ( & self , path : PathBuf , deno_json : ConfigFileRc ) ;
706
714
}
707
715
716
+ #[ derive( Debug , Error , JsError ) ]
717
+ #[ class( type ) ]
718
+ #[ error( "compilerOptions should be an object at '{specifier}'" ) ]
719
+ pub struct CompilerOptionsParseError {
720
+ pub specifier : Url ,
721
+ #[ source]
722
+ pub source : serde_json:: Error ,
723
+ }
724
+
708
725
#[ derive( Debug , Error , JsError ) ]
709
726
pub enum ConfigFileError {
710
- #[ class( type ) ]
711
- #[ error( "compilerOptions should be an object: {0}" ) ]
712
- CompilerOptionsShouldBeObject ( serde_json :: Error ) ,
727
+ #[ class( inherit ) ]
728
+ #[ error( transparent ) ]
729
+ CompilerOptionsParseError ( CompilerOptionsParseError ) ,
713
730
#[ class( type ) ]
714
731
#[ error( "Only file: specifiers are supported for security reasons in import maps stored in a deno.json. To use a remote import map, use the --import-map flag and \" deno.importMap\" in the language server config" ) ]
715
732
OnlyFileSpecifiersSupported ,
@@ -1014,26 +1031,29 @@ impl ConfigFile {
1014
1031
. to_path_buf ( )
1015
1032
}
1016
1033
1017
- /// Returns true if the configuration indicates that JavaScript should be
1018
- /// type checked, otherwise false .
1019
- pub fn get_check_js ( & self ) -> bool {
1034
+ /// Returns if the configuration indicates that JavaScript should be
1035
+ /// type checked, otherwise None if not set .
1036
+ pub fn check_js ( & self ) -> Option < bool > {
1020
1037
self
1021
1038
. json
1022
1039
. compiler_options
1023
1040
. as_ref ( )
1024
1041
. and_then ( |co| co. get ( "checkJs" ) . and_then ( |v| v. as_bool ( ) ) )
1025
- . unwrap_or ( false )
1026
1042
}
1027
1043
1028
1044
/// Parse `compilerOptions` and return a serde `Value`.
1029
1045
/// The result also contains any options that were ignored.
1030
1046
pub fn to_compiler_options (
1031
1047
& self ,
1032
- ) -> Result < ParsedTsConfigOptions , ConfigFileError > {
1048
+ ) -> Result < ParsedTsConfigOptions , CompilerOptionsParseError > {
1033
1049
if let Some ( compiler_options) = self . json . compiler_options . clone ( ) {
1034
1050
let options: serde_json:: Map < String , Value > =
1035
- serde_json:: from_value ( compiler_options)
1036
- . map_err ( ConfigFileError :: CompilerOptionsShouldBeObject ) ?;
1051
+ serde_json:: from_value ( compiler_options) . map_err ( |source| {
1052
+ CompilerOptionsParseError {
1053
+ specifier : self . specifier . clone ( ) ,
1054
+ source,
1055
+ }
1056
+ } ) ?;
1037
1057
Ok ( parse_compiler_options ( options, Some ( & self . specifier ) ) )
1038
1058
} else {
1039
1059
Ok ( Default :: default ( ) )
@@ -1580,20 +1600,27 @@ impl ConfigFile {
1580
1600
1581
1601
pub fn to_compiler_option_types (
1582
1602
& self ,
1583
- ) -> Result < Vec < ( Url , Vec < String > ) > , serde_json:: Error > {
1603
+ ) -> Result < Option < ( Url , Vec < String > ) > , CompilerOptionTypesDeserializeError >
1604
+ {
1584
1605
let Some ( compiler_options_value) = self . json . compiler_options . as_ref ( )
1585
1606
else {
1586
- return Ok ( Vec :: new ( ) ) ;
1607
+ return Ok ( None ) ;
1587
1608
} ;
1588
1609
let Some ( types) = compiler_options_value. get ( "types" ) else {
1589
- return Ok ( Vec :: new ( ) ) ;
1610
+ return Ok ( None ) ;
1590
1611
} ;
1591
- let imports: Vec < String > = serde_json:: from_value ( types. clone ( ) ) ?;
1612
+ let imports: Vec < String > =
1613
+ serde_json:: from_value ( types. clone ( ) ) . map_err ( |source| {
1614
+ CompilerOptionTypesDeserializeError {
1615
+ specifier : self . specifier . clone ( ) ,
1616
+ source,
1617
+ }
1618
+ } ) ?;
1592
1619
if !imports. is_empty ( ) {
1593
1620
let referrer = self . specifier . clone ( ) ;
1594
- Ok ( vec ! [ ( referrer, imports) ] )
1621
+ Ok ( Some ( ( referrer, imports) ) )
1595
1622
} else {
1596
- Ok ( Vec :: new ( ) )
1623
+ Ok ( None )
1597
1624
}
1598
1625
}
1599
1626
@@ -1603,14 +1630,22 @@ impl ConfigFile {
1603
1630
& self ,
1604
1631
) -> Result < Option < JsxImportSourceConfig > , ToMaybeJsxImportSourceConfigError >
1605
1632
{
1633
+ #[ derive( Debug , Deserialize ) ]
1634
+ #[ serde( rename_all = "camelCase" ) ]
1635
+ struct JsxCompilerOptions {
1636
+ pub jsx : Option < String > ,
1637
+ pub jsx_import_source : Option < String > ,
1638
+ pub jsx_import_source_types : Option < String > ,
1639
+ }
1640
+
1606
1641
let Some ( compiler_options_value) = self . json . compiler_options . as_ref ( )
1607
1642
else {
1608
1643
return Ok ( None ) ;
1609
1644
} ;
1610
- let Some ( compiler_options) =
1611
- serde_json :: from_value :: < CompilerOptions > ( compiler_options_value. clone ( ) )
1612
- . ok ( )
1613
- else {
1645
+ let Some ( compiler_options) = serde_json :: from_value :: < JsxCompilerOptions > (
1646
+ compiler_options_value. clone ( ) ,
1647
+ )
1648
+ . ok ( ) else {
1614
1649
return Ok ( None ) ;
1615
1650
} ;
1616
1651
let module = match compiler_options. jsx . as_deref ( ) {
@@ -1745,6 +1780,7 @@ impl Serialize for TsTypeLib {
1745
1780
}
1746
1781
1747
1782
/// An enum that represents the base tsc configuration to return.
1783
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
1748
1784
pub enum TsConfigType {
1749
1785
/// Return a configuration for bundling, using swc to emit the bundle. This is
1750
1786
/// independent of type checking.
@@ -1757,19 +1793,15 @@ pub enum TsConfigType {
1757
1793
}
1758
1794
1759
1795
#[ derive( Debug , Clone , PartialEq , Eq ) ]
1760
- pub struct TsConfigForEmit {
1796
+ pub struct TsConfigWithIgnoredOptions {
1761
1797
pub ts_config : TsConfig ,
1762
- pub maybe_ignored_options : Option < IgnoredCompilerOptions > ,
1798
+ pub ignored_options : Vec < IgnoredCompilerOptions > ,
1763
1799
}
1764
1800
1765
- /// For a given configuration type and optionally a configuration file,
1766
- /// return a `TsConfig` struct and optionally any user configuration
1767
- /// options that were ignored.
1768
- pub fn get_ts_config_for_emit (
1769
- config_type : TsConfigType ,
1770
- maybe_config_file : Option < & ConfigFile > ,
1771
- ) -> Result < TsConfigForEmit , ConfigFileError > {
1772
- let mut ts_config = match config_type {
1801
+ /// For a given configuration type get the starting point TsConfig
1802
+ /// used that can then be merged with user specified tsconfigs.
1803
+ pub fn get_base_ts_config_for_emit ( config_type : TsConfigType ) -> TsConfig {
1804
+ match config_type {
1773
1805
TsConfigType :: Bundle => TsConfig :: new ( json ! ( {
1774
1806
"allowImportingTsExtensions" : true ,
1775
1807
"checkJs" : false ,
@@ -1827,13 +1859,7 @@ pub fn get_ts_config_for_emit(
1827
1859
"moduleResolution" : "NodeNext" ,
1828
1860
"resolveJsonModule" : true ,
1829
1861
} ) ) ,
1830
- } ;
1831
- let maybe_ignored_options =
1832
- ts_config. merge_tsconfig_from_config_file ( maybe_config_file) ?;
1833
- Ok ( TsConfigForEmit {
1834
- ts_config,
1835
- maybe_ignored_options,
1836
- } )
1862
+ }
1837
1863
}
1838
1864
1839
1865
#[ cfg( test) ]
0 commit comments