2022-05-22 23:12:22 +03:00
|
|
|
import swc from "../../..";
|
2023-08-09 07:58:45 +03:00
|
|
|
import { dirname, join, resolve } from "path";
|
2022-05-22 23:12:22 +03:00
|
|
|
import { platform } from "os";
|
|
|
|
import { fileURLToPath } from "url";
|
|
|
|
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
|
|
|
it("should work", async () => {
|
2022-05-24 17:39:08 +03:00
|
|
|
if (process.platform === "win32") {
|
|
|
|
expect(true).toBeTruthy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-22 23:12:22 +03:00
|
|
|
const dir = join(__dirname, "..", "..", "tests", "issue-4730");
|
|
|
|
const filename = join(dir, "src", "index.ts");
|
|
|
|
console.log(filename);
|
|
|
|
const { code } = await swc.transformFile(filename, {
|
|
|
|
jsc: {
|
|
|
|
parser: {
|
|
|
|
syntax: "typescript",
|
|
|
|
dynamicImport: true,
|
|
|
|
},
|
|
|
|
target: "es2020",
|
2023-08-25 09:05:43 +03:00
|
|
|
baseUrl: resolve("."),
|
2022-05-22 23:12:22 +03:00
|
|
|
paths: {
|
|
|
|
"@print/a": [join(dir, "./packages/a/src/index.ts")],
|
|
|
|
"@print/b": [join(dir, "./packages/b/src/index.ts")],
|
|
|
|
},
|
|
|
|
externalHelpers: true,
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
type: "commonjs",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(code).toMatchInlineSnapshot(`
|
2022-11-16 07:51:59 +03:00
|
|
|
"\\"use strict\\";
|
|
|
|
Object.defineProperty(exports, \\"__esModule\\", {
|
|
|
|
value: true
|
|
|
|
});
|
2023-08-25 16:46:53 +03:00
|
|
|
const _interop_require_wildcard = require(\\"@swc/helpers/_/_interop_require_wildcard\\");
|
2023-09-01 08:24:50 +03:00
|
|
|
const _b = require(\\"../packages/b/src\\");
|
2022-11-16 07:51:59 +03:00
|
|
|
async function display() {
|
2023-09-01 08:24:50 +03:00
|
|
|
const displayA = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require(\\"../packages/a/src\\"))).then((c)=>c.displayA);
|
2022-11-16 07:51:59 +03:00
|
|
|
console.log(displayA());
|
|
|
|
console.log((0, _b.displayB)());
|
|
|
|
}
|
|
|
|
display();
|
|
|
|
"
|
|
|
|
`);
|
2022-05-22 23:12:22 +03:00
|
|
|
});
|