Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: tsconfig#extends must be a string #80

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,9 @@ impl<Fs: FileSystem + Default> ResolverGeneric<Fs> {
self.cache.tsconfig(path, |tsconfig| {
let directory = self.cache.value(tsconfig.directory());
tracing::trace!(tsconfig = ?tsconfig, "load_tsconfig");

// Extend tsconfig
let mut extended_tsconfig_paths = vec![];
for tsconfig_extend_specifier in &tsconfig.extends {
if let Some(tsconfig_extend_specifier) = &tsconfig.extends {
let extended_tsconfig_path = match tsconfig_extend_specifier.as_bytes().first() {
None => {
return Err(ResolveError::Specifier(SpecifierError::Empty(
Expand Down Expand Up @@ -1004,13 +1004,12 @@ impl<Fs: FileSystem + Default> ResolverGeneric<Fs> {
})?
.to_path_buf(),
};
extended_tsconfig_paths.push(extended_tsconfig_path);
}
for extended_tsconfig_path in extended_tsconfig_paths {

let extended_tsconfig =
self.load_tsconfig(&extended_tsconfig_path, &TsconfigReferences::Disabled)?;
tsconfig.extend_tsconfig(&extended_tsconfig);
}

// Load project references
match references {
TsconfigReferences::Disabled => {
Expand Down
22 changes: 4 additions & 18 deletions src/tsconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ pub struct TsConfig {
#[serde(skip)]
path: PathBuf,

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

#[serde(default)]
pub references: Vec<ProjectReference>,
Expand Down Expand Up @@ -50,22 +52,6 @@ pub struct CompilerOptions {
paths_base: PathBuf,
}

fn deserialize_extends<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(serde::Deserialize)]
#[serde(untagged)]
enum StringOrArray {
String(String),
Array(Vec<String>),
}
Ok(match StringOrArray::deserialize(deserializer)? {
StringOrArray::String(s) => vec![s],
StringOrArray::Array(a) => a,
})
}

impl TsConfig {
pub fn parse(path: &Path, json: &mut str) -> Result<Self, serde_json::Error> {
_ = json_strip_comments::strip(json);
Expand Down
Loading