fix(es/module): Fix jsc.paths with resolveFully (#8784)

**Related issue:**

 - Closes #8782
This commit is contained in:
Donny/강동윤 2024-03-28 11:42:07 +09:00 committed by GitHub
parent 5a619ebf0a
commit 4961bb055d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 83 additions and 19 deletions

View File

@ -1,6 +1,7 @@
{
"module": {
"type": "es6"
"type": "es6",
"resolveFully": true
},
"jsc": {
"baseUrl": ".",

View File

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

View File

@ -1,6 +1,7 @@
{
"module": {
"type": "es6"
"type": "es6",
"resolveFully": true
},
"jsc": {
"baseUrl": ".",

View File

@ -2,5 +2,5 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
const _a = require("./packages/a/src/index.ts");
const _a = require("./packages/a/src/index.js");
console.log(`${(0, _a.displayA)()}`);

View File

@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"isModule": true,
"jsc": {
"target": "es2022",
"keepClassNames": true,
"loose": false,
"baseUrl": ".",
"paths": {
"@foo/math": ["libs/math/index.js"],
"@foo/math/*": ["libs/math/*"],
"@foo/common": ["libs/common/main.js"]
},
"parser": {
"syntax": "typescript"
}
},
"minify": false,
"module": {
"type": "es6",
"resolveFully": true
}
}

View File

@ -0,0 +1 @@
export const commonStuff = 'common string';

View File

@ -0,0 +1,9 @@
import { models } from "../../projects/api/models.js";
console.log(models);
export { foo } from "./src/foo.js";
export const sum = function(a, b) {
return a + b;
};

View File

@ -0,0 +1,5 @@
// import { commonStuff } from '../../common/index.js';
import { commonStuff } from '@foo/common';
console.log(commonStuff)
export const foo = 'foo';

View File

@ -0,0 +1,6 @@
import { sum } from "@foo/math";
// import { foo } from "@foo/math/src/foo";
import { foo } from "@foo/math/src/foo.js";
console.log(foo);
console.log(sum(1, 2));

View File

@ -0,0 +1,3 @@
export const models = {
foo: 'foo'
}

View File

@ -0,0 +1 @@
export const commonStuff = 'common string';

View File

@ -0,0 +1,6 @@
import { models } from "../../projects/api/models.js";
console.log(models);
export { foo } from "./src/foo.js";
export const sum = function(a, b) {
return a + b;
};

View File

@ -0,0 +1,4 @@
// import { commonStuff } from '../../common/index.js';
import { commonStuff } from "../../common/main.js";
console.log(commonStuff);
export const foo = 'foo';

View File

@ -0,0 +1,5 @@
import { sum } from "../../libs/math/index.js";
// import { foo } from "@foo/math/src/foo";
import { foo } from "../../libs/math/src/foo.js";
console.log(foo);
console.log(sum(1, 2));

View File

@ -0,0 +1,3 @@
export const models = {
foo: 'foo'
};

View File

@ -289,7 +289,10 @@ where
let slug = to[0]
.split([std::path::MAIN_SEPARATOR, '/'])
.last()
.map(|v| v.into());
.filter(|&slug| slug != "index.ts" && slug != "index.tsx")
.map(|v| v.split_once('.').map(|v| v.0).unwrap_or(v))
.map(From::from);
if tp.is_absolute() {
return Ok(Resolution {
filename: FileName::Real(tp.into()),
@ -297,18 +300,10 @@ where
});
}
if let Ok(res) = self.resolve(&self.base_url_filename, &format!("./{}", &to[0]))
if let Ok(res) = self
.invoke_inner_resolver(&self.base_url_filename, &format!("./{}", &to[0]))
{
return Ok(Resolution {
slug: match &res.filename {
FileName::Real(p) => p
.file_stem()
.filter(|&s| s != "index")
.map(|v| v.to_string_lossy().into()),
_ => None,
},
..res
});
return Ok(Resolution { slug, ..res });
}
return Ok(Resolution {

View File

@ -41,7 +41,7 @@ fn exact() {
resolved,
Resolution {
filename: FileName::Custom("success".into()),
slug: None
slug: Some("jquery".into())
}
);
}

View File

@ -99,7 +99,7 @@ fn paths_resolver(base_dir: &Path, rules: Vec<(String, Vec<String>)>) -> JscPath
),
swc_ecma_transforms_module::path::Config {
base_dir: Some(base_dir),
resolve_fully: false,
resolve_fully: true,
},
)
}

View File

@ -1,4 +1,4 @@
import o from ".";
import o from "./index.js";
export default function bar() {
console.log(o);
}

View File

@ -30,6 +30,7 @@ it("should work", async () => {
},
module: {
type: "commonjs",
resolveFully: true,
},
});
expect(code).toMatchInlineSnapshot(`