Fix getLinuxName usage of fs-extra in shared
This commit is contained in:
parent
52fa2ddb03
commit
b5f77a23dd
2 changed files with 19 additions and 18 deletions
|
@ -2,8 +2,26 @@
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
import { readFileSync } from 'fs-extra';
|
||||||
import { getOSFunctions } from './shared';
|
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;
|
export default OS;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
import { readFileSync } from 'fs-extra';
|
|
||||||
|
|
||||||
function createIsPlatform(
|
function createIsPlatform(
|
||||||
platform: typeof process.platform,
|
platform: typeof process.platform,
|
||||||
|
@ -27,7 +26,6 @@ export type OSType = {
|
||||||
isLinux: (minVersion?: string) => boolean;
|
isLinux: (minVersion?: string) => boolean;
|
||||||
isMacOS: (minVersion?: string) => boolean;
|
isMacOS: (minVersion?: string) => boolean;
|
||||||
isWindows: (minVersion?: string) => boolean;
|
isWindows: (minVersion?: string) => boolean;
|
||||||
getLinuxName: () => string | undefined;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getOSFunctions(osRelease: string): OSType {
|
export function getOSFunctions(osRelease: string): OSType {
|
||||||
|
@ -59,20 +57,6 @@ export function getOSFunctions(osRelease: string): OSType {
|
||||||
return 'os-linux';
|
return 'os-linux';
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLinuxName = (): string | undefined => {
|
|
||||||
if (!isLinux()) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const etcOsRelease = readFileSync('/etc/os-release', 'utf-8');
|
|
||||||
const match = etcOsRelease.match(/^PRETTY_NAME=(.+?)$/m);
|
|
||||||
if (!match) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return match[1];
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getClassName,
|
getClassName,
|
||||||
getName,
|
getName,
|
||||||
|
@ -80,6 +64,5 @@ export function getOSFunctions(osRelease: string): OSType {
|
||||||
isLinux,
|
isLinux,
|
||||||
isMacOS,
|
isMacOS,
|
||||||
isWindows,
|
isWindows,
|
||||||
getLinuxName,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue