2022-09-07 05:05:42 +03:00
|
|
|
/// <reference types="jest" />
|
|
|
|
const { getPkgRoot } = require("../utils");
|
|
|
|
const path = require("path");
|
|
|
|
const { readFileSync } = require("fs");
|
|
|
|
|
|
|
|
const { platform, arch } = process;
|
|
|
|
|
|
|
|
const isMusl = () =>
|
|
|
|
(() => {
|
|
|
|
function isMusl() {
|
|
|
|
if (
|
|
|
|
!process.report ||
|
|
|
|
typeof process.report.getReport !== "function"
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
return readFileSync("/usr/bin/ldd", "utf8").includes(
|
|
|
|
"musl"
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const { glibcVersionRuntime } =
|
|
|
|
process.report.getReport().header;
|
|
|
|
return !glibcVersionRuntime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return isMusl();
|
|
|
|
})();
|
|
|
|
|
|
|
|
const platformPackagesMap = {
|
|
|
|
win32: {
|
|
|
|
x64: "swc.win32-x64-msvc.node",
|
|
|
|
ia32: "swc.win32-ia32-msvc.node",
|
|
|
|
arm64: "swc.win32-arm64-msvc.node",
|
|
|
|
},
|
|
|
|
darwin: {
|
|
|
|
x64: "swc.darwin-x64.node",
|
|
|
|
arm64: "swc.darwin-arm64.node",
|
|
|
|
},
|
|
|
|
linux: {
|
|
|
|
x64: `swc.linux-x64-${isMusl() ? "musl" : "gnu"}.node`,
|
|
|
|
arm64: `swc.linux-arm64-${isMusl() ? "musl" : "gnu"}.node`,
|
|
|
|
arm: "swc.linux-arm64-gnu.node",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const inferBinaryName = () => {
|
|
|
|
const packageName = platformPackagesMap[platform][arch];
|
|
|
|
|
|
|
|
if (!packageName) {
|
|
|
|
throw new Error(
|
|
|
|
`Unsupported platform: binary for '${platform} ${arch}' is not available`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return path.join(
|
|
|
|
path.dirname(require.resolve(packageName)),
|
|
|
|
platform === "win32" ? "swc.exe" : "swc"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-04-10 10:01:56 +03:00
|
|
|
describe("Published plugins", () => {
|
2022-09-07 05:05:42 +03:00
|
|
|
const packageName = platformPackagesMap[platform][arch];
|
|
|
|
|
|
|
|
if (!!packageName) {
|
|
|
|
it("should compile without seg fault", () => {
|
|
|
|
const { transformSync } = require(path.resolve(
|
|
|
|
getPkgRoot(),
|
|
|
|
packageName
|
|
|
|
));
|
2023-03-30 11:06:02 +03:00
|
|
|
console.log(`Package name: ${packageName}`);
|
2022-09-07 05:05:42 +03:00
|
|
|
|
|
|
|
const options = {
|
|
|
|
jsc: {
|
|
|
|
target: "es5",
|
|
|
|
parser: {
|
|
|
|
syntax: "typescript",
|
|
|
|
},
|
|
|
|
experimental: {
|
|
|
|
plugins: [
|
|
|
|
["@swc/plugin-jest", {}],
|
2022-10-06 10:36:01 +03:00
|
|
|
// Disabled because this plugin is broken
|
2022-09-30 06:47:00 +03:00
|
|
|
// ["swc-plugin-coverage-instrument", {}],
|
2022-09-07 05:05:42 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-03-30 11:06:02 +03:00
|
|
|
console.log("Before transformSync");
|
|
|
|
|
2022-09-07 05:05:42 +03:00
|
|
|
const { code } = transformSync(
|
|
|
|
'console.log("hello world")',
|
|
|
|
false,
|
|
|
|
Buffer.from(JSON.stringify(options))
|
|
|
|
);
|
|
|
|
|
2023-03-30 11:06:02 +03:00
|
|
|
console.log("After transformSync");
|
|
|
|
|
2022-09-07 05:05:42 +03:00
|
|
|
expect(code).toMatchInlineSnapshot(`
|
2022-09-30 06:47:00 +03:00
|
|
|
"console.log(\\"hello world\\");
|
2022-09-07 05:05:42 +03:00
|
|
|
"
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|