mirror of
https://github.com/swc-project/swc.git
synced 2024-12-29 00:23:10 +03:00
44 lines
1.0 KiB
JavaScript
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,
|
||
|
};
|