Skip to content

Commit 1ec161a

Browse files
authoredFeb 11, 2023
fix(es/module): Fix jsc.paths on Windows (#6930)
**Related issue:** - Reverts #6716. - Closes #6782.
1 parent e332dff commit 1ec161a

File tree

7 files changed

+36
-7
lines changed

7 files changed

+36
-7
lines changed
 

‎crates/swc/src/config/mod.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1327,12 +1327,10 @@ impl ModuleConfig {
13271327
available_features: FeatureFlag,
13281328
) -> Box<dyn swc_ecma_visit::Fold + 'cmt> {
13291329
let base = match base {
1330-
FileName::Real(path) if !paths.is_empty() && !path.is_absolute() => FileName::Real(
1331-
std::env::current_dir()
1332-
.map(|v| v.join(path))
1333-
.unwrap_or_else(|_| path.to_path_buf()),
1334-
),
1335-
_ => base.to_owned(),
1330+
FileName::Real(v) if !paths.is_empty() => {
1331+
FileName::Real(v.canonicalize().unwrap_or_else(|_| v.to_path_buf()))
1332+
}
1333+
_ => base.clone(),
13361334
};
13371335

13381336
match config {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"minify": true,
3+
"jsc": {
4+
"parser": {
5+
"syntax": "typescript",
6+
"tsx": true,
7+
"dynamicImport": true
8+
},
9+
"target": "es2020",
10+
"baseUrl": "./",
11+
"paths": {
12+
"@/config": [
13+
"config"
14+
],
15+
"@/config/*": [
16+
"config/*"
17+
]
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const config = () => console.log("\n\n--> all good!\n\n");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { config } from "@/config";
2+
3+
const main = () => config();
4+
5+
main();
6+
7+
// See https://github.com/swc-project/swc/issues/6782
8+
// See https://github.com/swc-project/swc/issues/6858
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const config=()=>console.log("\n\n--> all good!\n\n");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import{config}from"../config";const main=()=>config();main();

‎crates/swc_ecma_transforms_module/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ where
116116
let mut p = PathBuf::from(target_path);
117117

118118
if cfg!(debug_assertions) {
119-
trace!("to_specifier: orig_ext={:?}", orig_ext);
119+
trace!("to_specifier({target_path}): orig_ext={:?}", orig_ext);
120120
}
121121

122122
if let Some(orig_ext) = orig_ext {

0 commit comments

Comments
 (0)
Please sign in to comment.