mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 06:05:02 +03:00
56bdacc72d
**Description:** This PR reattempts https://github.com/swc-project/swc/pull/5456. Most of the changes are for the breaking changes of wasmer@3, as well as enabling rkyv's strict mode (https://github.com/swc-project/swc/pull/6922). This could not be seperated since wasmer@3 enables strict mode by default without a way to turn it off. There are a couple of changes worth noting: - Disabling in-memory module lookup: https://github.com/swc-project/swc/pull/7197/files#diff-3bda5def6ce2b7553c3b3a5ad241c0bdb7021e67b7de1e594df4cd5a54d403b3R154-R159 - Disabling plugin_runner in bindings_wasm: https://github.com/swc-project/swc/pull/7197/files#diff-dc3ded556a1fd709a129acd588e5eda651b842c6acc3f5340d40088a1f927facR310-R312 - Skipping plugin compat test: https://github.com/swc-project/swc/pull/7197/files#diff-531197dfcefba05faca53f0cf442ecc2dc6b59d5ead01979f5ffb912aa36249aR64-R66
110 lines
3.1 KiB
JavaScript
110 lines
3.1 KiB
JavaScript
/// <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"
|
|
);
|
|
};
|
|
|
|
// [TODO]: It is expected to have a breaking changes to the plugin,
|
|
// disabling the test for now.
|
|
describe.skip("Published plugins", () => {
|
|
const packageName = platformPackagesMap[platform][arch];
|
|
|
|
if (!!packageName) {
|
|
it("should compile without seg fault", () => {
|
|
const { transformSync } = require(path.resolve(
|
|
getPkgRoot(),
|
|
packageName
|
|
));
|
|
console.log(`Package name: ${packageName}`);
|
|
|
|
const options = {
|
|
jsc: {
|
|
target: "es5",
|
|
parser: {
|
|
syntax: "typescript",
|
|
},
|
|
experimental: {
|
|
plugins: [
|
|
["@swc/plugin-jest", {}],
|
|
// Disabled because this plugin is broken
|
|
// ["swc-plugin-coverage-instrument", {}],
|
|
],
|
|
},
|
|
},
|
|
};
|
|
|
|
console.log("Before transformSync");
|
|
|
|
const { code } = transformSync(
|
|
'console.log("hello world")',
|
|
false,
|
|
Buffer.from(JSON.stringify(options))
|
|
);
|
|
|
|
console.log("After transformSync");
|
|
|
|
expect(code).toMatchInlineSnapshot(`
|
|
"console.log(\\"hello world\\");
|
|
"
|
|
`);
|
|
});
|
|
}
|
|
});
|