Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(es/module): Fix jsc.paths on Windows #6930

Merged
merged 9 commits into from
Feb 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"minify": true,
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"dynamicImport": true
},
"target": "es2020",
"baseUrl": "./",
"paths": {
"@/config": [
"config"
],
"@/config/*": [
"config/*"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const config = () => console.log("\n\n--> all good!\n\n");
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const config=()=>console.log("\n\n--> all good!\n\n");
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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