cn-font-split
Version:
划时代的字体切割工具,CJK与任何字符!支持 otf、ttf、woff2 字体多线程切割,完美地细颗粒度地进行包大小控制。A revolutionary font subetter that supports CJK and any characters! It enables multi-threaded subset of otf, ttf, and woff2 fonts, allowing for precise control over package size.
58 lines (54 loc) • 1.52 kB
text/typescript
import { readFileSync } from 'fs';
import { execSync } from 'child_process';
import path from 'path';
export const isMusl = () => {
let musl: boolean | null = false;
if (process.platform === 'linux') {
musl = isMuslFromFilesystem();
if (musl === null) {
musl = isMuslFromReport();
}
if (musl === null) {
musl = isMuslFromChildProcess();
}
}
return !!musl;
};
export const isMuslFromFilesystem = () => {
try {
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl');
} catch {
return null;
}
};
export const isMuslFromReport = () => {
const report: any =
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(
(f: string) =>
f.includes('libc.musl-') || f.includes('ld-musl-'),
)
) {
return true;
}
}
return false;
};
export const isMuslFromChildProcess = () => {
try {
return 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;
}
};