Skip to content

Commit

Permalink
Refactor install dir computation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolai Laevskii committed May 12, 2023
1 parent dd32dd7 commit 6d92b9b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 43 deletions.
37 changes: 18 additions & 19 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})();


Expand Down Expand Up @@ -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;


/***/ }),
Expand Down
36 changes: 12 additions & 24 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
};

0 comments on commit 6d92b9b

Please sign in to comment.