Refactor install dir computation

This commit is contained in:
Nikolai Laevskii 2023-05-12 14:07:46 +02:00
parent dd32dd730c
commit 6d92b9bd53
3 changed files with 35 additions and 43 deletions

37
dist/index.js vendored
View File

@ -419,24 +419,15 @@ class DotnetCoreInstaller {
exports.DotnetCoreInstaller = DotnetCoreInstaller;
_a = DotnetCoreInstaller;
(() => {
const installationDirectoryWindows = path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet');
const installationDirectoryLinux = '/usr/share/dotnet';
const installationDirectoryMac = path_1.default.join(process.env['HOME'] + '', '.dotnet');
const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR'];
if (dotnetInstallDir) {
process.env['DOTNET_INSTALL_DIR'] =
_a.convertInstallPathToAbsolute(dotnetInstallDir);
}
else {
if (utils_1.IS_WINDOWS) {
process.env['DOTNET_INSTALL_DIR'] = installationDirectoryWindows;
}
else {
process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX
? installationDirectoryLinux
: installationDirectoryMac;
}
}
const dotnetInstallDirDefault = {
linux: '/usr/share/dotnet',
mac: path_1.default.join(process.env['HOME'] + '', '.dotnet'),
windows: path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet')
}[(0, utils_1.getPlatform)()];
const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR']
? _a.convertInstallPathToAbsolute(process.env['DOTNET_INSTALL_DIR'])
: dotnetInstallDirDefault;
process.env['DOTNET_INSTALL_DIR'] = dotnetInstallDir;
})();
@ -591,9 +582,17 @@ run();
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.IS_LINUX = exports.IS_WINDOWS = void 0;
exports.getPlatform = exports.IS_LINUX = exports.IS_WINDOWS = void 0;
exports.IS_WINDOWS = process.platform === 'win32';
exports.IS_LINUX = process.platform === 'linux';
const getPlatform = () => {
if (exports.IS_WINDOWS)
return 'windows';
if (exports.IS_LINUX)
return 'linux';
return 'mac';
};
exports.getPlatform = getPlatform;
/***/ }),

View File

@ -8,7 +8,7 @@ import {readdir} from 'fs/promises';
import path from 'path';
import os from 'os';
import semver from 'semver';
import {IS_LINUX, IS_WINDOWS} from './utils';
import {IS_WINDOWS, getPlatform} from './utils';
import {QualityOptions} from './setup-dotnet';
export interface DotnetVersion {
@ -115,29 +115,17 @@ export class DotnetCoreInstaller {
private quality: QualityOptions;
static {
const installationDirectoryWindows = path.join(
process.env['PROGRAMFILES'] + '',
'dotnet'
);
const installationDirectoryLinux = '/usr/share/dotnet';
const installationDirectoryMac = path.join(
process.env['HOME'] + '',
'.dotnet'
);
const dotnetInstallDir: string | undefined =
process.env['DOTNET_INSTALL_DIR'];
if (dotnetInstallDir) {
process.env['DOTNET_INSTALL_DIR'] =
this.convertInstallPathToAbsolute(dotnetInstallDir);
} else {
if (IS_WINDOWS) {
process.env['DOTNET_INSTALL_DIR'] = installationDirectoryWindows;
} else {
process.env['DOTNET_INSTALL_DIR'] = IS_LINUX
? installationDirectoryLinux
: installationDirectoryMac;
}
}
const dotnetInstallDirDefault = {
linux: '/usr/share/dotnet',
mac: path.join(process.env['HOME'] + '', '.dotnet'),
windows: path.join(process.env['PROGRAMFILES'] + '', 'dotnet')
}[getPlatform()];
const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR']
? this.convertInstallPathToAbsolute(process.env['DOTNET_INSTALL_DIR'])
: dotnetInstallDirDefault;
process.env['DOTNET_INSTALL_DIR'] = dotnetInstallDir;
}
constructor(version: string, quality: QualityOptions) {

View File

@ -1,2 +1,7 @@
export const IS_WINDOWS = process.platform === 'win32';
export const IS_LINUX = process.platform === 'linux';
export const getPlatform = (): 'windows' | 'linux' | 'mac' => {
if (IS_WINDOWS) return 'windows';
if (IS_LINUX) return 'linux';
return 'mac';
};