1
>
/*---------------------------------------------------------------------------------------------
powershell.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import * as os from 'os';
7
>
import * as path from '../common/path.js';
8
>
import * as pfs from './pfs.js';
9
>
10
>
// This is required, since parseInt("7-preview") will return 7.
11
>
const IntRegex: RegExp = /^\d+$/;
12
>
13
>
const PwshMsixRegex: RegExp = /^Microsoft.PowerShell_.*/;
14
>
const PwshPreviewMsixRegex: RegExp = /^Microsoft.PowerShellPreview_.*/;
15
>
16
>
const enum Arch {
17
>
x64,
18
>
x86,
19
>
ARM
20
>
}
21
>
22
>
let processArch: Arch;
23
>
switch (process.arch) {
24
>
case 'ia32':
25
processArch = Arch.x86;
26
break;
28
>
case 'arm64':
29
processArch = Arch.ARM;
30
break;
32
>
processArch = Arch.x64;
33
>
break;
34
>
}
35
>
36
>
/*
37
>
Currently, here are the values for these environment variables on their respective archs:
38
>
39
>
On x86 process on x86:
40
>
PROCESSOR_ARCHITECTURE is X86
41
>
PROCESSOR_ARCHITEW6432 is undefined
42
>
43
>
On x86 process on x64:
44
>
PROCESSOR_ARCHITECTURE is X86
45
>
PROCESSOR_ARCHITEW6432 is AMD64
46
>
47
>
On x64 process on x64:
48
>
PROCESSOR_ARCHITECTURE is AMD64
49
>
PROCESSOR_ARCHITEW6432 is undefined
50
>
51
>
On ARM process on ARM:
52
>
PROCESSOR_ARCHITECTURE is ARM64
53
>
PROCESSOR_ARCHITEW6432 is undefined
54
>
55
>
On x86 process on ARM:
56
>
PROCESSOR_ARCHITECTURE is X86
57
>
PROCESSOR_ARCHITEW6432 is ARM64
58
>
59
>
On x64 process on ARM:
60
>
PROCESSOR_ARCHITECTURE is ARM64
61
>
PROCESSOR_ARCHITEW6432 is undefined
62
>
*/
63
>
let osArch: Arch;
64
>
if (process.env['PROCESSOR_ARCHITEW6432']) {
65
osArch = process.env['PROCESSOR_ARCHITEW6432'] === 'ARM64'
66
? Arch.ARM
67
: Arch.x64;
68
>
} else if (process.env['PROCESSOR_ARCHITECTURE'] === 'ARM64') {
powershell.ts
69
osArch = Arch.ARM;
70
>
} else if (process.env['PROCESSOR_ARCHITECTURE'] === 'X86') {
powershell.ts
71
osArch = Arch.x86;
73
>
osArch = Arch.x64;
74
>
}
75
>
76
>
export interface IPowerShellExeDetails {
77
>
readonly displayName: string;
78
>
readonly exePath: string;
79
>
}
80
>
81
>
interface IPossiblePowerShellExe extends IPowerShellExeDetails {
82
>
exists(): Promise<boolean>;
83
>
}
84
>
85
>
class PossiblePowerShellExe implements IPossiblePowerShellExe {
86
>
constructor(
87
public readonly exePath: string,
88
public readonly displayName: string,
89
private knownToExist?: boolean) { }
91
>
public async exists(): Promise<boolean> {
92
if (this.knownToExist === undefined) {
93
this.knownToExist = await pfs.SymlinkSupport.existsFile(this.exePath);