fix(es/module): Fix logic for exact matches in jsc.paths (#7860)

**Related issue:**

 - Closes #7829
This commit is contained in:
Donny/강동윤 2023-08-25 16:23:19 +09:00 committed by GitHub
parent e47f1c2bf7
commit 52a1ee78da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 65 additions and 20 deletions

View File

@ -0,0 +1,24 @@
{
"module": {
"type": "es6"
},
"jsc": {
"baseUrl": ".",
"target": "es2020",
"parser": {
"syntax": "typescript",
"decorators": true,
"importMeta": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true,
"paths": {
"@my/pkg": [
"libs/pkg/src/index.ts"
],
}
}
}

View File

@ -0,0 +1,4 @@
import { fn } from '@my/pkg';
console.log(fn)

View File

@ -0,0 +1,2 @@
import { fn } from "./libs/pkg/src";
console.log(fn);

View File

@ -0,0 +1,24 @@
{
"module": {
"type": "es6"
},
"jsc": {
"baseUrl": ".",
"target": "es2020",
"parser": {
"syntax": "typescript",
"decorators": true,
"importMeta": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true,
"paths": {
"@my/pkg": [
"libs/pkg/src/index.js"
],
}
}
}

View File

@ -0,0 +1,4 @@
import { fn } from '@my/pkg';
console.log(fn)

View File

@ -0,0 +1,2 @@
import { fn } from "./libs/pkg/src/index.js";
console.log(fn);

View File

@ -259,27 +259,12 @@ where
return Ok(FileName::Real(tp.into()));
}
if self.base_url_filename == *base {
// Prevent infinite loop
let replaced = self.base_url.join(&to[0]);
if replaced.exists() {
return Ok(FileName::Real(replaced));
}
return self
.invoke_inner_resolver(base, &format!("./{}", &to[0]))
.with_context(|| {
format!(
"tried to resolve `{}` because `{}` was exactly matched",
to[0], from
)
});
} else {
return self
.resolve(&self.base_url_filename, &format!("./{}", &to[0]))
.context("failed to resolve using jsc.baseUrl as base");
if let Ok(res) = self.resolve(&self.base_url_filename, &format!("./{}", &to[0]))
{
return Ok(res);
}
return Ok(FileName::Real(self.base_url.join(&to[0])));
}
}
}