Skip to content

Commit

Permalink
fix(es/module): Fix jsc.paths on Windows (#6930)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Reverts #6716.
 - Closes #6782.
  • Loading branch information
kdy1 committed Feb 11, 2023
1 parent e332dff commit 1ec161a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
10 changes: 4 additions & 6 deletions crates/swc/src/config/mod.rs
Expand Up @@ -1327,12 +1327,10 @@ impl ModuleConfig {
available_features: FeatureFlag,
) -> Box<dyn swc_ecma_visit::Fold + 'cmt> {
let base = match base {
FileName::Real(path) if !paths.is_empty() && !path.is_absolute() => FileName::Real(
std::env::current_dir()
.map(|v| v.join(path))
.unwrap_or_else(|_| path.to_path_buf()),
),
_ => base.to_owned(),
FileName::Real(v) if !paths.is_empty() => {
FileName::Real(v.canonicalize().unwrap_or_else(|_| v.to_path_buf()))
}
_ => base.clone(),
};

match config {
Expand Down
20 changes: 20 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6782/1/input/.swcrc
@@ -0,0 +1,20 @@
{
"minify": true,
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"dynamicImport": true
},
"target": "es2020",
"baseUrl": "./",
"paths": {
"@/config": [
"config"
],
"@/config/*": [
"config/*"
]
}
}
}
@@ -0,0 +1 @@
export const config = () => console.log("\n\n--> all good!\n\n");
@@ -0,0 +1,8 @@
import { config } from "@/config";

const main = () => config();

main();

// See https://github.com/swc-project/swc/issues/6782
// See https://github.com/swc-project/swc/issues/6858
@@ -0,0 +1 @@
export const config=()=>console.log("\n\n--> all good!\n\n");
@@ -0,0 +1 @@
import{config}from"../config";const main=()=>config();main();
2 changes: 1 addition & 1 deletion crates/swc_ecma_transforms_module/src/path.rs
Expand Up @@ -116,7 +116,7 @@ where
let mut p = PathBuf::from(target_path);

if cfg!(debug_assertions) {
trace!("to_specifier: orig_ext={:?}", orig_ext);
trace!("to_specifier({target_path}): orig_ext={:?}", orig_ext);
}

if let Some(orig_ext) = orig_ext {
Expand Down

0 comments on commit 1ec161a

Please sign in to comment.