Skip to content

Commit

Permalink
Format: Refactor installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolai Laevskii committed May 24, 2023
1 parent aa85432 commit 3dfe267
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('DotnetCoreInstaller tests', () => {

it('Throws if no location contains correct dotnet version', async () => {
await expect(async () => {
await getDotnet('1000.0.0')
await getDotnet('1000.0.0');
}).rejects.toThrow();
}, 30000);

Expand Down
23 changes: 14 additions & 9 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class DotnetInstallScript {
this.escapedScript = path
.join(__dirname, '..', 'externals', this.scriptName)
.replace(/'/g, "''");

this.scriptReady = IS_WINDOWS
? this.setupScriptPowershell()
: this.setupScriptBash();
Expand All @@ -148,7 +148,8 @@ export class DotnetInstallScript {
this.scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
}

this.scriptPath = (await io.which('pwsh', false)) || (await io.which('powershell', true));
this.scriptPath =
(await io.which('pwsh', false)) || (await io.which('powershell', true));
}

private async setupScriptBash() {
Expand Down Expand Up @@ -194,8 +195,8 @@ export class DotnetInstallScript {
return exec.getExecOutput(
`"${this.scriptPath}"`,
this.scriptArguments,
getExecOutputOptions,
)
getExecOutputOptions
);
}
}

Expand All @@ -204,11 +205,13 @@ export abstract class DotnetInstallDir {
linux: '/usr/share/dotnet',
mac: path.join(process.env['HOME'] + '', '.dotnet'),
windows: path.join(process.env['PROGRAMFILES'] + '', 'dotnet')
}
};

public static readonly path = process.env['DOTNET_INSTALL_DIR']
? DotnetInstallDir.convertInstallPathToAbsolute(process.env['DOTNET_INSTALL_DIR'])
: DotnetInstallDir.default[getPlatform()]
? DotnetInstallDir.convertInstallPathToAbsolute(
process.env['DOTNET_INSTALL_DIR']
)
: DotnetInstallDir.default[getPlatform()];

private static convertInstallPathToAbsolute(installDir: string): string {
let transformedPath;
Expand Down Expand Up @@ -239,14 +242,16 @@ export class DotnetCoreInstaller {
DotnetInstallDir.initialize;
}

constructor(private version: string, private quality: QualityOptions) {};
constructor(private version: string, private quality: QualityOptions) {}

public async installDotnet(): Promise<string> {
const versionResolver = new DotnetVersionResolver(this.version);
const dotnetVersion = await versionResolver.createDotnetVersion();

const installScript = new DotnetInstallScript()
.useArguments(IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files')
.useArguments(
IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files'
)
.useVersion(dotnetVersion, this.quality);

const {exitCode, stderr} = await installScript.execute();
Expand Down

0 comments on commit 3dfe267

Please sign in to comment.