Skip to content
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
6 changes: 3 additions & 3 deletions src/tests/tsconfig_project_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ async fn disabled() {
(f.join("app"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
(f.join("app"), "@/../index.ts", Ok(f.join("app/index.ts"))),
// Test project reference
(f.join("project_a"), "@/index.ts", Err(ResolveError::NotFound("@/index.ts".into()))),
(f.join("project_b/src"), "@/index.ts", Err(ResolveError::NotFound("@/index.ts".into()))),
(f.join("project_a"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
(f.join("project_b/src"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
// Does not have paths alias
(f.join("project_a"), "./index.ts", Ok(f.join("project_a/index.ts"))),
(f.join("project_c"), "./index.ts", Ok(f.join("project_c/index.ts"))),
Expand Down Expand Up @@ -88,7 +88,7 @@ async fn manual() {
(f.join("app"), "@/../index.ts", Ok(f.join("app/index.ts"))),
// Test project reference
(f.join("project_a"), "@/index.ts", Ok(f.join("project_a/aliased/index.ts"))),
(f.join("project_b/src"), "@/index.ts", Err(ResolveError::NotFound("@/index.ts".into()))),
(f.join("project_b/src"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
// Does not have paths alias
(f.join("project_a"), "./index.ts", Ok(f.join("project_a/index.ts"))),
(f.join("project_c"), "./index.ts", Ok(f.join("project_c/index.ts"))),
Expand Down
17 changes: 6 additions & 11 deletions src/tsconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,28 @@ impl TsConfig {
self.path.parent().unwrap()
}

pub fn extend_tsconfig(&mut self, tsconfig: &Self) {
pub fn extend_tsconfig(&mut self, other_config: &Self) {
let compiler_options = &mut self.compiler_options;
if compiler_options.paths.is_none() {
compiler_options.paths_base = compiler_options
.base_url
.as_ref()
.map_or_else(|| tsconfig.compiler_options.paths_base.clone(), Clone::clone);
compiler_options.paths.clone_from(&tsconfig.compiler_options.paths);
.map_or_else(|| other_config.compiler_options.paths_base.clone(), Clone::clone);
compiler_options.paths.clone_from(&other_config.compiler_options.paths);
}
if compiler_options.base_url.is_none() {
compiler_options.base_url.clone_from(&tsconfig.compiler_options.base_url);
compiler_options.base_url.clone_from(&other_config.compiler_options.base_url);
}
}

pub fn resolve(&self, path: &Path, specifier: &str) -> Vec<PathBuf> {
if path.starts_with(self.base_path()) {
let paths = self.resolve_path_alias(specifier);
if !paths.is_empty() {
return paths;
}
}
for tsconfig in self.references.iter().filter_map(|reference| reference.tsconfig.as_ref()) {
if path.starts_with(tsconfig.base_path()) {
return tsconfig.resolve_path_alias(specifier);
}
}
vec![]

self.resolve_path_alias(specifier)
}

// Copied from parcel
Expand Down
Loading