Skip to content

Commit ab961d2

Browse files
authored
fix!: paths match align with tsconfig-paths-webpack-plugin (#74)
1 parent 1ab1bd9 commit ab961d2

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

src/tests/tsconfig_project_references.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ async fn disabled() {
5656
(f.join("app"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
5757
(f.join("app"), "@/../index.ts", Ok(f.join("app/index.ts"))),
5858
// Test project reference
59-
(f.join("project_a"), "@/index.ts", Err(ResolveError::NotFound("@/index.ts".into()))),
60-
(f.join("project_b/src"), "@/index.ts", Err(ResolveError::NotFound("@/index.ts".into()))),
59+
(f.join("project_a"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
60+
(f.join("project_b/src"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
6161
// Does not have paths alias
6262
(f.join("project_a"), "./index.ts", Ok(f.join("project_a/index.ts"))),
6363
(f.join("project_c"), "./index.ts", Ok(f.join("project_c/index.ts"))),
@@ -88,7 +88,7 @@ async fn manual() {
8888
(f.join("app"), "@/../index.ts", Ok(f.join("app/index.ts"))),
8989
// Test project reference
9090
(f.join("project_a"), "@/index.ts", Ok(f.join("project_a/aliased/index.ts"))),
91-
(f.join("project_b/src"), "@/index.ts", Err(ResolveError::NotFound("@/index.ts".into()))),
91+
(f.join("project_b/src"), "@/index.ts", Ok(f.join("app/aliased/index.ts"))),
9292
// Does not have paths alias
9393
(f.join("project_a"), "./index.ts", Ok(f.join("project_a/index.ts"))),
9494
(f.join("project_c"), "./index.ts", Ok(f.join("project_c/index.ts"))),

src/tsconfig.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,33 +134,28 @@ impl TsConfig {
134134
self.path.parent().unwrap()
135135
}
136136

137-
pub fn extend_tsconfig(&mut self, tsconfig: &Self) {
137+
pub fn extend_tsconfig(&mut self, other_config: &Self) {
138138
let compiler_options = &mut self.compiler_options;
139139
if compiler_options.paths.is_none() {
140140
compiler_options.paths_base = compiler_options
141141
.base_url
142142
.as_ref()
143-
.map_or_else(|| tsconfig.compiler_options.paths_base.clone(), Clone::clone);
144-
compiler_options.paths.clone_from(&tsconfig.compiler_options.paths);
143+
.map_or_else(|| other_config.compiler_options.paths_base.clone(), Clone::clone);
144+
compiler_options.paths.clone_from(&other_config.compiler_options.paths);
145145
}
146146
if compiler_options.base_url.is_none() {
147-
compiler_options.base_url.clone_from(&tsconfig.compiler_options.base_url);
147+
compiler_options.base_url.clone_from(&other_config.compiler_options.base_url);
148148
}
149149
}
150150

151151
pub fn resolve(&self, path: &Path, specifier: &str) -> Vec<PathBuf> {
152-
if path.starts_with(self.base_path()) {
153-
let paths = self.resolve_path_alias(specifier);
154-
if !paths.is_empty() {
155-
return paths;
156-
}
157-
}
158152
for tsconfig in self.references.iter().filter_map(|reference| reference.tsconfig.as_ref()) {
159153
if path.starts_with(tsconfig.base_path()) {
160154
return tsconfig.resolve_path_alias(specifier);
161155
}
162156
}
163-
vec![]
157+
158+
self.resolve_path_alias(specifier)
164159
}
165160

166161
// Copied from parcel

0 commit comments

Comments
 (0)