Skip to content

Commit eacbfc1

Browse files
authored
fix: tsconfig#extends must be a string (#80)
closes #66
1 parent bf08a0e commit eacbfc1

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,9 @@ impl<Fs: FileSystem + Default> ResolverGeneric<Fs> {
973973
self.cache.tsconfig(path, |tsconfig| {
974974
let directory = self.cache.value(tsconfig.directory());
975975
tracing::trace!(tsconfig = ?tsconfig, "load_tsconfig");
976+
976977
// Extend tsconfig
977-
let mut extended_tsconfig_paths = vec![];
978-
for tsconfig_extend_specifier in &tsconfig.extends {
978+
if let Some(tsconfig_extend_specifier) = &tsconfig.extends {
979979
let extended_tsconfig_path = match tsconfig_extend_specifier.as_bytes().first() {
980980
None => {
981981
return Err(ResolveError::Specifier(SpecifierError::Empty(
@@ -1004,13 +1004,12 @@ impl<Fs: FileSystem + Default> ResolverGeneric<Fs> {
10041004
})?
10051005
.to_path_buf(),
10061006
};
1007-
extended_tsconfig_paths.push(extended_tsconfig_path);
1008-
}
1009-
for extended_tsconfig_path in extended_tsconfig_paths {
1007+
10101008
let extended_tsconfig =
10111009
self.load_tsconfig(&extended_tsconfig_path, &TsconfigReferences::Disabled)?;
10121010
tsconfig.extend_tsconfig(&extended_tsconfig);
10131011
}
1012+
10141013
// Load project references
10151014
match references {
10161015
TsconfigReferences::Disabled => {

src/tsconfig.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ pub struct TsConfig {
1818
#[serde(skip)]
1919
path: PathBuf,
2020

21-
#[serde(default, deserialize_with = "deserialize_extends")]
22-
pub extends: Vec<String>,
21+
/// The value of extends must be a string containing a path to another configuration file to inherit from.
22+
/// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#configuration-inheritance
23+
#[serde(default)]
24+
pub extends: Option<String>,
2325

2426
#[serde(default)]
2527
pub references: Vec<ProjectReference>,
@@ -50,22 +52,6 @@ pub struct CompilerOptions {
5052
paths_base: PathBuf,
5153
}
5254

53-
fn deserialize_extends<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
54-
where
55-
D: serde::Deserializer<'de>,
56-
{
57-
#[derive(serde::Deserialize)]
58-
#[serde(untagged)]
59-
enum StringOrArray {
60-
String(String),
61-
Array(Vec<String>),
62-
}
63-
Ok(match StringOrArray::deserialize(deserializer)? {
64-
StringOrArray::String(s) => vec![s],
65-
StringOrArray::Array(a) => a,
66-
})
67-
}
68-
6955
impl TsConfig {
7056
pub fn parse(path: &Path, json: &mut str) -> Result<Self, serde_json::Error> {
7157
_ = json_strip_comments::strip(json);

0 commit comments

Comments
 (0)