mirror of
https://github.com/actions/setup-dotnet.git
synced 2024-11-22 19:41:08 +07:00
Refactor install dir computation
This commit is contained in:
parent
dd32dd730c
commit
6d92b9bd53
37
dist/index.js
vendored
37
dist/index.js
vendored
@ -419,24 +419,15 @@ class DotnetCoreInstaller {
|
|||||||
exports.DotnetCoreInstaller = DotnetCoreInstaller;
|
exports.DotnetCoreInstaller = DotnetCoreInstaller;
|
||||||
_a = DotnetCoreInstaller;
|
_a = DotnetCoreInstaller;
|
||||||
(() => {
|
(() => {
|
||||||
const installationDirectoryWindows = path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet');
|
const dotnetInstallDirDefault = {
|
||||||
const installationDirectoryLinux = '/usr/share/dotnet';
|
linux: '/usr/share/dotnet',
|
||||||
const installationDirectoryMac = path_1.default.join(process.env['HOME'] + '', '.dotnet');
|
mac: path_1.default.join(process.env['HOME'] + '', '.dotnet'),
|
||||||
const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR'];
|
windows: path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet')
|
||||||
if (dotnetInstallDir) {
|
}[(0, utils_1.getPlatform)()];
|
||||||
process.env['DOTNET_INSTALL_DIR'] =
|
const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR']
|
||||||
_a.convertInstallPathToAbsolute(dotnetInstallDir);
|
? _a.convertInstallPathToAbsolute(process.env['DOTNET_INSTALL_DIR'])
|
||||||
}
|
: dotnetInstallDirDefault;
|
||||||
else {
|
process.env['DOTNET_INSTALL_DIR'] = dotnetInstallDir;
|
||||||
if (utils_1.IS_WINDOWS) {
|
|
||||||
process.env['DOTNET_INSTALL_DIR'] = installationDirectoryWindows;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX
|
|
||||||
? installationDirectoryLinux
|
|
||||||
: installationDirectoryMac;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
@ -591,9 +582,17 @@ run();
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
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_WINDOWS = process.platform === 'win32';
|
||||||
exports.IS_LINUX = process.platform === 'linux';
|
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;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -8,7 +8,7 @@ import {readdir} from 'fs/promises';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
import {IS_LINUX, IS_WINDOWS} from './utils';
|
import {IS_WINDOWS, getPlatform} from './utils';
|
||||||
import {QualityOptions} from './setup-dotnet';
|
import {QualityOptions} from './setup-dotnet';
|
||||||
|
|
||||||
export interface DotnetVersion {
|
export interface DotnetVersion {
|
||||||
@ -115,29 +115,17 @@ export class DotnetCoreInstaller {
|
|||||||
private quality: QualityOptions;
|
private quality: QualityOptions;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
const installationDirectoryWindows = path.join(
|
const dotnetInstallDirDefault = {
|
||||||
process.env['PROGRAMFILES'] + '',
|
linux: '/usr/share/dotnet',
|
||||||
'dotnet'
|
mac: path.join(process.env['HOME'] + '', '.dotnet'),
|
||||||
);
|
windows: path.join(process.env['PROGRAMFILES'] + '', 'dotnet')
|
||||||
const installationDirectoryLinux = '/usr/share/dotnet';
|
}[getPlatform()];
|
||||||
const installationDirectoryMac = path.join(
|
|
||||||
process.env['HOME'] + '',
|
const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR']
|
||||||
'.dotnet'
|
? this.convertInstallPathToAbsolute(process.env['DOTNET_INSTALL_DIR'])
|
||||||
);
|
: dotnetInstallDirDefault;
|
||||||
const dotnetInstallDir: string | undefined =
|
|
||||||
process.env['DOTNET_INSTALL_DIR'];
|
process.env['DOTNET_INSTALL_DIR'] = dotnetInstallDir;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(version: string, quality: QualityOptions) {
|
constructor(version: string, quality: QualityOptions) {
|
||||||
|
@ -1,2 +1,7 @@
|
|||||||
export const IS_WINDOWS = process.platform === 'win32';
|
export const IS_WINDOWS = process.platform === 'win32';
|
||||||
export const IS_LINUX = process.platform === 'linux';
|
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';
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user