@ms-cloudpack/environment 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/lib/environmentInfo.d.ts +43 -0
- package/lib/getAdjustedTimeout.d.ts +7 -0
- package/lib/getEnvBoolean.d.ts +7 -0
- package/lib/index.d.ts +2 -0
- package/package.json +29 -0
- package/src/environmentInfo.js +64 -0
- package/src/getAdjustedTimeout.js +14 -0
- package/src/getEnvBoolean.js +12 -0
- package/src/index.js +4 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @ms-cloudpack/environment
|
|
2
|
+
|
|
3
|
+
Environment-related utilities for Cloudpack. This helps centralize `process.env` access to a single place.
|
|
4
|
+
|
|
5
|
+
### Development notes
|
|
6
|
+
|
|
7
|
+
This package is written in JS so it can be consumed by Cloudpack's internal scripts package `@ms-cloudpack/scripts`. Only `.d.ts` files are emitted to `lib`.
|
|
8
|
+
|
|
9
|
+
The package also builds with the `cloudpack-scripts` bin from `@ms-cloudpack/scripts` (via the repo root dependency on that package). Technically this is circular, but it won't be an issue in practice because the scripts package is also written in JS.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-Cloudpack-specific environment information.
|
|
3
|
+
*/
|
|
4
|
+
export const environmentInfo: Readonly<{
|
|
5
|
+
/** True if running in PR/CI (github or ADO) */
|
|
6
|
+
isCI: boolean;
|
|
7
|
+
/** True if running in a codespace */
|
|
8
|
+
isCodespaces: boolean;
|
|
9
|
+
/** True if running within jest */
|
|
10
|
+
isJest: boolean;
|
|
11
|
+
/** True if running via lage */
|
|
12
|
+
isLage: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* True if debugging in VS Code.
|
|
15
|
+
*
|
|
16
|
+
* NOTE: This only works if running with a launch configuration that sets `VS_CODE_DEBUG`
|
|
17
|
+
* (it's not automatically set by VS Code).
|
|
18
|
+
*/
|
|
19
|
+
isVsCodeDebug: boolean;
|
|
20
|
+
/** True if running on Windows (shorthand for `process.platform === 'win32'`) */
|
|
21
|
+
isWindows: boolean;
|
|
22
|
+
/** Info only applicable if running in Azure DevOps */
|
|
23
|
+
ado: Readonly<{
|
|
24
|
+
buildId: string | undefined;
|
|
25
|
+
definitionId: string | undefined;
|
|
26
|
+
buildReason: string | undefined;
|
|
27
|
+
pullRequestId: string | undefined;
|
|
28
|
+
}> | undefined;
|
|
29
|
+
/** Info only applicable if running on Windows. Only set if running on Windows. */
|
|
30
|
+
windows: Readonly<{
|
|
31
|
+
appData: string | undefined;
|
|
32
|
+
computerName: string | undefined;
|
|
33
|
+
programFiles: string | undefined;
|
|
34
|
+
}> | undefined;
|
|
35
|
+
cloudpack: Readonly<{
|
|
36
|
+
/** Whether cloudpack sync is enabled (default true) */
|
|
37
|
+
isSyncEnabled: boolean;
|
|
38
|
+
/** Custom telemetry connection string */
|
|
39
|
+
telemetryConnectionString: string | undefined;
|
|
40
|
+
/** External correlation ID used to correlate telemetry across different services */
|
|
41
|
+
telemetryExternalCorrelationId: string | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
}>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a timeout value with an appropriate multiplier for the current environment.
|
|
3
|
+
* - x3 for windows CI
|
|
4
|
+
* - x1.5 for other CI or windows local
|
|
5
|
+
* @param baseTimeout - Base timeout in ms
|
|
6
|
+
*/
|
|
7
|
+
export function getAdjustedTimeout(baseTimeout: number): number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a boolean value from an environment variable.
|
|
3
|
+
* @param {string} name - variable name
|
|
4
|
+
* @returns {boolean | undefined} false if the value is set to '0' or 'false',
|
|
5
|
+
* true if set to anything else, undefined if not set
|
|
6
|
+
*/
|
|
7
|
+
export function getEnvBoolean(name: string): boolean | undefined;
|
package/lib/index.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ms-cloudpack/environment",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Environment-related utilities for Cloudpack.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"source": "./src/index.js",
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"import": "./src/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"api": "yarn run -T cloudpack-scripts api",
|
|
20
|
+
"build:watch": "yarn run -T cloudpack-scripts build-watch",
|
|
21
|
+
"build": "yarn run -T cloudpack-scripts build",
|
|
22
|
+
"lint:update": "yarn run -T cloudpack-scripts lint-update",
|
|
23
|
+
"lint": "yarn run -T cloudpack-scripts lint"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"lib/**/!(*.test.*)",
|
|
27
|
+
"src/**/!(*.test.*)"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-properties -- this is the file that reads the environment */
|
|
2
|
+
import { getEnvBoolean } from './getEnvBoolean.js';
|
|
3
|
+
|
|
4
|
+
const isADO = !!getEnvBoolean('TF_BUILD');
|
|
5
|
+
const isWindows = process.platform === 'win32';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Non-Cloudpack-specific environment information.
|
|
9
|
+
*/
|
|
10
|
+
// Objects are frozen to prevent accidental modification.
|
|
11
|
+
export const environmentInfo = Object.freeze({
|
|
12
|
+
/** True if running in PR/CI (github or ADO) */
|
|
13
|
+
isCI: !!getEnvBoolean('CI') || isADO,
|
|
14
|
+
|
|
15
|
+
/** True if running in a codespace */
|
|
16
|
+
isCodespaces: !!getEnvBoolean('CODESPACES'),
|
|
17
|
+
|
|
18
|
+
/** True if running within jest */
|
|
19
|
+
isJest: !!process.env.JEST_WORKER_ID,
|
|
20
|
+
|
|
21
|
+
/** True if running via lage */
|
|
22
|
+
isLage: !!process.env.LAGE_PACKAGE_NAME,
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* True if debugging in VS Code.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: This only works if running with a launch configuration that sets `VS_CODE_DEBUG`
|
|
28
|
+
* (it's not automatically set by VS Code).
|
|
29
|
+
*/
|
|
30
|
+
isVsCodeDebug: !!process.env.VS_CODE_DEBUG,
|
|
31
|
+
|
|
32
|
+
/** True if running on Windows (shorthand for `process.platform === 'win32'`) */
|
|
33
|
+
isWindows,
|
|
34
|
+
|
|
35
|
+
/** Info only applicable if running in Azure DevOps */
|
|
36
|
+
ado: isADO
|
|
37
|
+
? Object.freeze({
|
|
38
|
+
buildId: process.env.BUILD_BUILDID,
|
|
39
|
+
definitionId: process.env.SYSTEM_DEFINITIONID,
|
|
40
|
+
buildReason: process.env.BUILD_REASON,
|
|
41
|
+
pullRequestId: process.env.SYSTEM_PULLREQUEST_PULLREQUESTID,
|
|
42
|
+
})
|
|
43
|
+
: undefined,
|
|
44
|
+
|
|
45
|
+
/** Info only applicable if running on Windows. Only set if running on Windows. */
|
|
46
|
+
windows: isWindows
|
|
47
|
+
? Object.freeze({
|
|
48
|
+
appData: process.env.APPDATA,
|
|
49
|
+
computerName: process.env.COMPUTERNAME,
|
|
50
|
+
programFiles: process.env.ProgramFiles,
|
|
51
|
+
})
|
|
52
|
+
: undefined,
|
|
53
|
+
|
|
54
|
+
cloudpack: Object.freeze({
|
|
55
|
+
/** Whether cloudpack sync is enabled (default true) */
|
|
56
|
+
isSyncEnabled: getEnvBoolean('CLOUDPACK_SYNC') ?? true,
|
|
57
|
+
|
|
58
|
+
/** Custom telemetry connection string */
|
|
59
|
+
telemetryConnectionString: process.env.CLOUDPACK_TELEMETRY_CONNECTION_STRING,
|
|
60
|
+
|
|
61
|
+
/** External correlation ID used to correlate telemetry across different services */
|
|
62
|
+
telemetryExternalCorrelationId: process.env.CLOUDPACK_TELEMETRY_EXTERNAL_CORRELATION_ID,
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { environmentInfo } from './environmentInfo.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get a timeout value with an appropriate multiplier for the current environment.
|
|
5
|
+
* - x3 for windows CI
|
|
6
|
+
* - x1.5 for other CI or windows local
|
|
7
|
+
* @param baseTimeout - Base timeout in ms
|
|
8
|
+
*/
|
|
9
|
+
export function getAdjustedTimeout(/** @type {number} */ baseTimeout) {
|
|
10
|
+
if (environmentInfo.isCI) {
|
|
11
|
+
return environmentInfo.isWindows ? baseTimeout * 3 : Math.round(baseTimeout * 1.5);
|
|
12
|
+
}
|
|
13
|
+
return environmentInfo.isWindows ? Math.round(baseTimeout * 1.5) : baseTimeout;
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-properties -- this is the file that reads the environment */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get a boolean value from an environment variable.
|
|
5
|
+
* @param {string} name - variable name
|
|
6
|
+
* @returns {boolean | undefined} false if the value is set to '0' or 'false',
|
|
7
|
+
* true if set to anything else, undefined if not set
|
|
8
|
+
*/
|
|
9
|
+
export function getEnvBoolean(name) {
|
|
10
|
+
const value = process.env[name]?.toLowerCase();
|
|
11
|
+
return value ? value !== '0' && value !== 'false' : undefined;
|
|
12
|
+
}
|
package/src/index.js
ADDED