Fix getLinuxName usage of fs-extra in shared

This commit is contained in:
ayumi-signal 2023-09-06 11:38:54 -07:00 committed by GitHub
parent 52fa2ddb03
commit b5f77a23dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 18 deletions

View file

@ -2,8 +2,26 @@
// SPDX-License-Identifier: AGPL-3.0-only
import os from 'os';
import { readFileSync } from 'fs-extra';
import { getOSFunctions } from './shared';
const OS = getOSFunctions(os.release());
function getLinuxName(): string | undefined {
if (os.platform() !== 'linux') {
return undefined;
}
const etcOsRelease = readFileSync('/etc/os-release', 'utf-8');
const match = etcOsRelease.match(/^PRETTY_NAME=(.+?)$/m);
if (!match) {
return undefined;
}
return match[1];
}
const OS = {
...getOSFunctions(os.release()),
getLinuxName,
};
export default OS;