Repository navigation
Expand file tree
/
Copy pathruntimeEnvironment.ts
More file actions
63 lines (52 loc) · 1.49 KB
/
Copy pathruntimeEnvironment.ts
File metadata and controls
63 lines (52 loc) · 1.49 KB
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
import { getEnvVariable } from '../getEnvVariable';
export const automatedEnvironmentVariables = [
'CI',
'CONTINUOUS_INTEGRATION',
'GITHUB_ACTIONS',
'GITLAB_CI',
'CIRCLECI',
'TRAVIS',
'BUILDKITE',
'BITBUCKET_BUILD_NUMBER',
'APPVEYOR',
'CODEBUILD_BUILD_ID',
'TF_BUILD',
'TEAMCITY_VERSION',
'JENKINS_URL',
'HUDSON_URL',
'BAMBOO_BUILDKEY',
'CF_PAGES',
] as const;
const isTruthyEnvValue = (value: unknown): boolean => {
if (typeof value !== 'string' || !value) {
return false;
}
return !['0', 'false', 'off', 'no'].includes(value.toLowerCase());
};
export const isDevelopmentEnvironment = (): boolean => {
try {
return process.env.NODE_ENV === 'development';
// eslint-disable-next-line no-empty
} catch {}
// TODO: add support for import.meta.env.DEV that is being used by vite
return false;
};
export const isTestEnvironment = (): boolean => {
try {
return process.env.NODE_ENV === 'test';
// eslint-disable-next-line no-empty
} catch {}
// TODO: add support for import.meta.env.DEV that is being used by vite
return false;
};
export const isProductionEnvironment = (): boolean => {
try {
return process.env.NODE_ENV === 'production';
// eslint-disable-next-line no-empty
} catch {}
// TODO: add support for import.meta.env.DEV that is being used by vite
return false;
};
export const isAutomatedEnvironment = (): boolean => {
return automatedEnvironmentVariables.some(name => isTruthyEnvValue(getEnvVariable(name)));
};