-
Notifications
You must be signed in to change notification settings - Fork 575
/
Copy pathenv.ts
117 lines (98 loc) · 3.23 KB
/
env.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import * as semver from 'semver'
import * as vscode from 'vscode'
import * as packageJson from '../../../package.json'
/**
* Components associated with {@link module:vscode.env}.
*/
export interface Env {
clipboard: Clipboard
}
export namespace Env {
export function vscode(): Env {
return new DefaultEnv()
}
}
export interface Clipboard {
/**
* See {@link module:vscode.Clipboard.writeText}.
*/
writeText(message: string): Thenable<void>
}
class DefaultEnv implements Env {
public get clipboard(): Clipboard {
return vscode.env.clipboard
}
}
/**
* Returns true if the current build is running on CI (build server).
*/
export function isCI(): boolean {
return undefined !== process.env['GITHUB_ACTION'] || undefined !== process.env['CODEBUILD_BUILD_ID']
}
/** Variable added via webpack */
declare let EXTENSION_VERSION: string // eslint-disable-line @typescript-eslint/naming-convention
const testVersion = 'testPluginVersion'
/** The current extension version. If not built via Webpack, this defaults to {@link testVersion}. */
let extensionVersion = testVersion
try {
extensionVersion = EXTENSION_VERSION
} catch (e) {} // Just a reference error
/**
* Returns true if the current build is a production build (as opposed to a
* prerelease/test/nightly build)
*/
export function isReleaseVersion(prereleaseOk: boolean = false): boolean {
return (prereleaseOk || !semver.prerelease(extensionVersion)) && extensionVersion !== testVersion
}
/**
* Returns true when source mapping is available
*/
export function isSourceMappingAvailable(): boolean {
return extensionVersion === testVersion
}
/**
* Returns true if the extension is being ran from automation.
*/
export function isAutomation(): boolean {
return isCI() || !!process.env['AWS_TOOLKIT_AUTOMATION']
}
/**
* Returns true if name mangling has occured to the extension source code.
*/
export function isNameMangled(): boolean {
return isNameMangled.name !== 'isNameMangled'
}
export { extensionVersion }
/**
* Returns true if the extension is being ran on the minimum version of VS Code as defined
* by the `engines` field in `package.json`
*/
export function isMinimumVersion(): boolean {
return vscode.version.startsWith(getMinVscodeVersion())
}
/**
* Returns the minimum vscode "engine" version declared in `package.json`.
*/
export function getMinVscodeVersion(): string {
return packageJson.engines.vscode.replace(/[^~]/, '')
}
/**
* Returns the minimum nodejs version declared in `package.json`.
*/
export function getMinNodejsVersion(): string {
return packageJson.devDependencies['@types/node'].replace(/[^~]/, '')
}
export function getCodeCatalystDevEnvId(): string | undefined {
return process.env['__DEV_ENVIRONMENT_ID']
}
export function getCodeCatalystProjectName(): string | undefined {
return process.env['__DEV_ENVIRONMENT_PROJECT_NAME']
}
export function getCodeCatalystSpaceName(): string | undefined {
// TODO: remove legacy __DEV_ENVIRONMENT_ORGANIZATION_NAME
return process.env['__DEV_ENVIRONMENT_SPACE_NAME'] || process.env['__DEV_ENVIRONMENT_ORGANIZATION_NAME']
}