mirror of
https://github.com/swc-project/swc.git
synced 2024-09-11 16:55:27 +03:00
fix(es/module): Fix jsc.paths
with resolveFully
(#8784)
**Related issue:** - Closes #8782
This commit is contained in:
parent
5a619ebf0a
commit
4961bb055d
@ -1,6 +1,7 @@
|
||||
{
|
||||
"module": {
|
||||
"type": "es6"
|
||||
"type": "es6",
|
||||
"resolveFully": true
|
||||
},
|
||||
"jsc": {
|
||||
"baseUrl": ".",
|
||||
|
@ -1,2 +1,2 @@
|
||||
import { fn } from "./libs/pkg/src/index.ts";
|
||||
import { fn } from "./libs/pkg/src/index.js";
|
||||
console.log(fn);
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"module": {
|
||||
"type": "es6"
|
||||
"type": "es6",
|
||||
"resolveFully": true
|
||||
},
|
||||
"jsc": {
|
||||
"baseUrl": ".",
|
||||
|
@ -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)()}`);
|
||||
|
23
crates/swc/tests/fixture/issues-8xxx/8782/input/.swcrc
Normal file
23
crates/swc/tests/fixture/issues-8xxx/8782/input/.swcrc
Normal 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
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
export const commonStuff = 'common string';
|
@ -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;
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
// import { commonStuff } from '../../common/index.js';
|
||||
import { commonStuff } from '@foo/common';
|
||||
console.log(commonStuff)
|
||||
|
||||
export const foo = 'foo';
|
@ -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));
|
@ -0,0 +1,3 @@
|
||||
export const models = {
|
||||
foo: 'foo'
|
||||
}
|
@ -0,0 +1 @@
|
||||
export const commonStuff = 'common string';
|
@ -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;
|
||||
};
|
@ -0,0 +1,4 @@
|
||||
// import { commonStuff } from '../../common/index.js';
|
||||
import { commonStuff } from "../../common/main.js";
|
||||
console.log(commonStuff);
|
||||
export const foo = 'foo';
|
@ -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));
|
@ -0,0 +1,3 @@
|
||||
export const models = {
|
||||
foo: 'foo'
|
||||
};
|
@ -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 {
|
||||
|
@ -41,7 +41,7 @@ fn exact() {
|
||||
resolved,
|
||||
Resolution {
|
||||
filename: FileName::Custom("success".into()),
|
||||
slug: None
|
||||
slug: Some("jquery".into())
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import o from ".";
|
||||
import o from "./index.js";
|
||||
export default function bar() {
|
||||
console.log(o);
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ it("should work", async () => {
|
||||
},
|
||||
module: {
|
||||
type: "commonjs",
|
||||
resolveFully: true,
|
||||
},
|
||||
});
|
||||
expect(code).toMatchInlineSnapshot(`
|
||||
|
Loading…
Reference in New Issue
Block a user