update at 2026-10-12 18:55:48
This commit is contained in:
149
figma/node_modules/oxfmt/bin/oxfmt
generated
vendored
Executable file
149
figma/node_modules/oxfmt/bin/oxfmt
generated
vendored
Executable file
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const isMusl = () => {
|
||||
let musl = false;
|
||||
if (process.platform === "linux") {
|
||||
musl = isMuslFromFilesystem();
|
||||
if (musl === null) {
|
||||
musl = isMuslFromReport();
|
||||
}
|
||||
if (musl === null) {
|
||||
musl = isMuslFromChildProcess();
|
||||
}
|
||||
}
|
||||
return musl;
|
||||
};
|
||||
|
||||
const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
|
||||
|
||||
const isMuslFromFilesystem = () => {
|
||||
const { readFileSync } = require("fs");
|
||||
try {
|
||||
return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
|
||||
} catch(_error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const isMuslFromReport = () => {
|
||||
const report =
|
||||
typeof process.report.getReport === "function"
|
||||
? process.report.getReport()
|
||||
: null;
|
||||
if (!report) {
|
||||
return null;
|
||||
}
|
||||
if (report.header && report.header.glibcVersionRuntime) {
|
||||
return false;
|
||||
}
|
||||
if (Array.isArray(report.sharedObjects)) {
|
||||
if (report.sharedObjects.some(isFileMusl)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const isMuslFromChildProcess = () => {
|
||||
try {
|
||||
return require("child_process")
|
||||
.execSync("ldd --version", { encoding: "utf8" })
|
||||
.includes("musl");
|
||||
} catch (e) {
|
||||
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const { platform, arch, env, version, release } = process;
|
||||
|
||||
const PLATFORMS = {
|
||||
win32: {
|
||||
x64: {
|
||||
musl: "@oxfmt/win32-x64/oxfmt.exe",
|
||||
gnu: "@oxfmt/win32-x64/oxfmt.exe",
|
||||
},
|
||||
arm64: {
|
||||
musl: "@oxfmt/win32-arm64/oxfmt.exe",
|
||||
gnu: "@oxfmt/win32-arm64/oxfmt.exe",
|
||||
},
|
||||
},
|
||||
darwin: {
|
||||
x64: {
|
||||
musl: "@oxfmt/darwin-x64/oxfmt",
|
||||
gnu: "@oxfmt/darwin-x64/oxfmt",
|
||||
},
|
||||
arm64: {
|
||||
musl: "@oxfmt/darwin-arm64/oxfmt",
|
||||
gnu: "@oxfmt/darwin-arm64/oxfmt",
|
||||
},
|
||||
},
|
||||
linux: {
|
||||
x64: {
|
||||
musl: "@oxfmt/linux-x64-musl/oxfmt",
|
||||
gnu: "@oxfmt/linux-x64-gnu/oxfmt",
|
||||
},
|
||||
arm64: {
|
||||
musl: "@oxfmt/linux-arm64-musl/oxfmt",
|
||||
gnu: "@oxfmt/linux-arm64-gnu/oxfmt",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let binPath = (
|
||||
PLATFORMS &&
|
||||
PLATFORMS[platform] &&
|
||||
PLATFORMS[platform][arch] &&
|
||||
PLATFORMS[platform][arch][isMusl() ? "musl" : "gnu"]
|
||||
) || null;
|
||||
|
||||
if (binPath) {
|
||||
const result = require("child_process").spawnSync(
|
||||
require.resolve(binPath),
|
||||
process.argv.slice(2),
|
||||
{
|
||||
shell: false,
|
||||
stdio: "inherit",
|
||||
env: Object.assign({}, env, {
|
||||
JS_RUNTIME_VERSION: version,
|
||||
JS_RUNTIME_NAME: release.name,
|
||||
NODE_PACKAGE_MANAGER: detectPackageManager(),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
if (result.error) {
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
process.exitCode = result.status;
|
||||
} else {
|
||||
let target = `${platform}-${arch}`;
|
||||
if (isMusl()) {
|
||||
target = `${target}-musl`;
|
||||
}
|
||||
console.error(
|
||||
`The oxfmt CLI package doesn't ship with prebuilt binaries for your platform (${target}) yet. ` +
|
||||
"You can create an issue at https://github.com/oxc-project/oxc/issues for support."
|
||||
);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* NPM, Yarn, and other package manager set the `npm_config_user_agent`. It has the following format:
|
||||
*
|
||||
* ```
|
||||
* "npm/8.3.0 node/v16.13.2 win32 x64 workspaces/false
|
||||
* ```
|
||||
*
|
||||
* @returns The package manager string (`npm/8.3.0`) or null if the user agent string isn't set.
|
||||
*/
|
||||
function detectPackageManager() {
|
||||
const userAgent = env.npm_config_user_agent;
|
||||
|
||||
if (userAgent == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return userAgent.split(" ")[0];
|
||||
}
|
||||
Reference in New Issue
Block a user