swc/packages/core/e2e/utils.js
Donny/강동윤 f960d52364
refactor(bindings): Make @swc/core a subpackage (#8625)
**Description:**

This is for consistency and future extensions.
2024-05-18 09:23:06 +09:00

44 lines
1.0 KiB
JavaScript

const assert = require("assert");
const glob = require("glob");
const fs = require("fs");
const path = require("path");
const { promisify } = require("util");
const getPkgRoot = (() => () => {
let ret;
if (!ret) {
ret = path.resolve(__dirname, "..");
}
return ret;
})();
/**
* Temporarily move out existing napi bindings to avoid test fixture setup overwrite it.
*/
const preserveBinaries = async (fromExt, toExt) => {
const existingBinary = glob.sync(`${getPkgRoot()}/*.${fromExt}`);
assert.equal(
existingBinary.length <= 1,
true,
"There are more than one prebuilt binaries, current test fixture setup cannot handle this"
);
const binaryPath = existingBinary[0];
if (!binaryPath) {
return;
}
const tmpBinaryPath = path.join(
path.dirname(binaryPath),
`${path.basename(binaryPath, `.${fromExt}`)}.${toExt}`
);
await promisify(fs.rename)(binaryPath, tmpBinaryPath);
};
module.exports = {
getPkgRoot,
preserveBinaries,
};