std-env 2.3.1 → 3.0.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 +32 -28
- package/dist/index.cjs +102 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.mjs +86 -0
- package/package.json +15 -11
- package/CHANGELOG.md +0 -5
- package/index.d.ts +0 -20
- package/index.js +0 -70
package/README.md
CHANGED
|
@@ -1,48 +1,52 @@
|
|
|
1
1
|
# std-env
|
|
2
2
|
|
|
3
|
-
[](http://npmjs.com/package/std-env)
|
|
4
4
|
[](http://npmjs.com/package/std-env)
|
|
5
|
+
[](https://bundlephobia.com/result?p=std-env)
|
|
5
6
|
|
|
6
|
-
Detect
|
|
7
|
+
> Detect current Javascript environment
|
|
7
8
|
|
|
8
9
|
## Installation
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
```
|
|
11
|
+
```sh
|
|
12
|
+
# Using Yarn
|
|
13
13
|
yarn add std-env
|
|
14
|
-
```
|
|
15
14
|
|
|
16
|
-
Using npm
|
|
17
|
-
|
|
18
|
-
```
|
|
15
|
+
# Using npm
|
|
19
16
|
npm i std-env
|
|
20
17
|
```
|
|
21
18
|
|
|
22
19
|
## Usage
|
|
23
20
|
|
|
24
21
|
```js
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
browser: false,
|
|
32
|
-
test: false,
|
|
33
|
-
dev: true,
|
|
34
|
-
production: false,
|
|
35
|
-
debug: false,
|
|
36
|
-
ci: false,
|
|
37
|
-
tty: true,
|
|
38
|
-
minimalCLI: false,
|
|
39
|
-
windows: false,
|
|
40
|
-
darwin: true,
|
|
41
|
-
linux: false
|
|
42
|
-
}
|
|
43
|
-
*/
|
|
22
|
+
// ESM
|
|
23
|
+
import { isWindows } from 'std-env'
|
|
24
|
+
|
|
25
|
+
// CommonJS
|
|
26
|
+
const { isCI } = require('std-env')
|
|
44
27
|
```
|
|
45
28
|
|
|
29
|
+
Available exports:
|
|
30
|
+
|
|
31
|
+
- `hasTTY`
|
|
32
|
+
- `hasWindow`
|
|
33
|
+
- `isCI`
|
|
34
|
+
- `isDebug`
|
|
35
|
+
- `isDevelopment`
|
|
36
|
+
- `isLinux`
|
|
37
|
+
- `isMacOS`
|
|
38
|
+
- `isMinimal`
|
|
39
|
+
- `isProduction`
|
|
40
|
+
- `isTest`
|
|
41
|
+
- `isWindows`
|
|
42
|
+
- `platform`
|
|
43
|
+
- `provider`
|
|
44
|
+
|
|
45
|
+
You can read more about how each flag works from [./src/index.ts](./src/index.ts).
|
|
46
|
+
|
|
47
|
+
List of well known providers can be found from [./src/providers.ts](./src/providers.ts).
|
|
48
|
+
|
|
49
|
+
|
|
46
50
|
## License
|
|
47
51
|
|
|
48
52
|
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const providers = [
|
|
6
|
+
["APPVEYOR"],
|
|
7
|
+
["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],
|
|
8
|
+
["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],
|
|
9
|
+
["APPCIRCLE", "AC_APPCIRCLE"],
|
|
10
|
+
["BAMBOO", "bamboo_planKey"],
|
|
11
|
+
["BITBUCKET", "BITBUCKET_COMMIT"],
|
|
12
|
+
["BITRISE", "BITRISE_IO"],
|
|
13
|
+
["BUDDY", "BUDDY_WORKSPACE_ID"],
|
|
14
|
+
["BUILDKITE"],
|
|
15
|
+
["CIRCLE", "CIRCLECI"],
|
|
16
|
+
["CIRRUS", "CIRRUS_CI"],
|
|
17
|
+
["CODEBUILD", "CODEBUILD_BUILD_ARN"],
|
|
18
|
+
["CODEFRESH", "CF_BUILD_ID"],
|
|
19
|
+
["DRONE"],
|
|
20
|
+
["DRONE", "DRONE_BUILD_EVENT"],
|
|
21
|
+
["DSARI"],
|
|
22
|
+
["GITHUB_ACTIONS"],
|
|
23
|
+
["GITLAB", "GITLAB_CI"],
|
|
24
|
+
["GITLAB", "CI_MERGE_REQUEST_ID"],
|
|
25
|
+
["GOCD", "GO_PIPELINE_LABEL"],
|
|
26
|
+
["LAYERCI"],
|
|
27
|
+
["HUDSON", "HUDSON_URL"],
|
|
28
|
+
["JENKINS", "JENKINS_URL"],
|
|
29
|
+
["MAGNUM"],
|
|
30
|
+
["NETLIFY"],
|
|
31
|
+
["NETLIFY", "NETLIFY_LOCAL", { ci: false }],
|
|
32
|
+
["NEVERCODE"],
|
|
33
|
+
["RENDER"],
|
|
34
|
+
["SAIL", "SAILCI"],
|
|
35
|
+
["SEMAPHORE"],
|
|
36
|
+
["SCREWDRIVER"],
|
|
37
|
+
["SHIPPABLE"],
|
|
38
|
+
["SOLANO", "TDDIUM"],
|
|
39
|
+
["STRIDER"],
|
|
40
|
+
["TEAMCITY", "TEAMCITY_VERSION"],
|
|
41
|
+
["TRAVIS"],
|
|
42
|
+
["VERCEL", "NOW_BUILDER"],
|
|
43
|
+
["APPCENTER", "APPCENTER_BUILD_ID"],
|
|
44
|
+
["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }],
|
|
45
|
+
["STACKBLITZ"]
|
|
46
|
+
];
|
|
47
|
+
function detectProvider(env) {
|
|
48
|
+
for (const provider of providers) {
|
|
49
|
+
const envName = provider[1] || provider[0];
|
|
50
|
+
if (env[envName]) {
|
|
51
|
+
return {
|
|
52
|
+
name: provider[0].toLowerCase(),
|
|
53
|
+
...provider[2]
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (env.SHELL && env.SHELL === "/bin/jsh") {
|
|
58
|
+
return {
|
|
59
|
+
name: "stackblitz",
|
|
60
|
+
ci: false
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
name: "",
|
|
65
|
+
ci: false
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const processShim = typeof process !== "undefined" ? process : {};
|
|
70
|
+
const envShim = processShim.env || {};
|
|
71
|
+
const providerInfo = detectProvider(envShim);
|
|
72
|
+
const nodeENV = envShim.NODE_ENV || "";
|
|
73
|
+
const platform = processShim.platform;
|
|
74
|
+
const provider = providerInfo.name;
|
|
75
|
+
const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false;
|
|
76
|
+
const hasTTY = toBoolean(processShim.stdout && processShim.stdout.isTTY);
|
|
77
|
+
const hasWindow = typeof window !== "undefined";
|
|
78
|
+
const isDebug = toBoolean(envShim.DEBUG);
|
|
79
|
+
const isTest = toBoolean(envShim.TEST);
|
|
80
|
+
const isProduction = nodeENV === "production";
|
|
81
|
+
const isDevelopment = nodeENV === "dev" || nodeENV === "development";
|
|
82
|
+
const isMinimal = toBoolean(envShim.MINIMAL) || isCI || isTest || !hasTTY;
|
|
83
|
+
const isWindows = /^win/i.test(platform);
|
|
84
|
+
const isLinux = /^linux/i.test(platform);
|
|
85
|
+
const isMacOS = /^darwin/i.test(platform);
|
|
86
|
+
function toBoolean(val) {
|
|
87
|
+
return val ? val !== "false" : false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
exports.hasTTY = hasTTY;
|
|
91
|
+
exports.hasWindow = hasWindow;
|
|
92
|
+
exports.isCI = isCI;
|
|
93
|
+
exports.isDebug = isDebug;
|
|
94
|
+
exports.isDevelopment = isDevelopment;
|
|
95
|
+
exports.isLinux = isLinux;
|
|
96
|
+
exports.isMacOS = isMacOS;
|
|
97
|
+
exports.isMinimal = isMinimal;
|
|
98
|
+
exports.isProduction = isProduction;
|
|
99
|
+
exports.isTest = isTest;
|
|
100
|
+
exports.isWindows = isWindows;
|
|
101
|
+
exports.platform = platform;
|
|
102
|
+
exports.provider = provider;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
declare type ProviderName = '' | 'appveyor' | 'azure_pipelines' | 'azure_static' | 'appcircle' | 'bamboo' | 'bitbucket' | 'bitrise' | 'buddy' | 'buildkite' | 'circle' | 'cirrus' | 'codebuild' | 'codefresh' | 'drone' | 'drone' | 'dsari' | 'github_actions' | 'gitlab' | 'gitlab' | 'gocd' | 'layerci' | 'hudson' | 'jenkins' | 'magnum' | 'netlify' | 'netlify' | 'nevercode' | 'render' | 'sail' | 'semaphore' | 'screwdriver' | 'shippable' | 'solano' | 'strider' | 'teamcity' | 'travis' | 'vercel' | 'appcenter' | 'codesandbox' | 'stackblitz';
|
|
2
|
+
declare type ProviderInfo = {
|
|
3
|
+
name: ProviderName;
|
|
4
|
+
[meta: string]: any;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/** Value of process.platform */
|
|
8
|
+
declare const platform: NodeJS.Platform;
|
|
9
|
+
/** Current provider name */
|
|
10
|
+
declare const provider: ProviderName;
|
|
11
|
+
/** Detect if `CI` environment variable is set or a provider CI detected */
|
|
12
|
+
declare const isCI: boolean;
|
|
13
|
+
/** Detect if stdout.TTY is available */
|
|
14
|
+
declare const hasTTY: boolean;
|
|
15
|
+
/** Detect if global `window` object is available */
|
|
16
|
+
declare const hasWindow: boolean;
|
|
17
|
+
/** Detect if `DEBUG` environment variable is set */
|
|
18
|
+
declare const isDebug: boolean;
|
|
19
|
+
/** Detect if `NODE_ENV` environment variable is `test` */
|
|
20
|
+
declare const isTest: boolean;
|
|
21
|
+
/** Detect if `NODE_ENV` environment variable is `production` */
|
|
22
|
+
declare const isProduction: boolean;
|
|
23
|
+
/** Detect if `NODE_ENV` environment variable is `dev` or `development` */
|
|
24
|
+
declare const isDevelopment: boolean;
|
|
25
|
+
/** Detect if MINIMAL environment variable is set, running in CI or test or TTY is unavailable */
|
|
26
|
+
declare const isMinimal: boolean;
|
|
27
|
+
/** Detect if process.platform is Windows */
|
|
28
|
+
declare const isWindows: boolean;
|
|
29
|
+
/** Detect if process.platform is Linux */
|
|
30
|
+
declare const isLinux: boolean;
|
|
31
|
+
/** Detect if process.platform is macOS (darwin kernel) */
|
|
32
|
+
declare const isMacOS: boolean;
|
|
33
|
+
|
|
34
|
+
export { ProviderInfo, ProviderName, hasTTY, hasWindow, isCI, isDebug, isDevelopment, isLinux, isMacOS, isMinimal, isProduction, isTest, isWindows, platform, provider };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const providers = [
|
|
2
|
+
["APPVEYOR"],
|
|
3
|
+
["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],
|
|
4
|
+
["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],
|
|
5
|
+
["APPCIRCLE", "AC_APPCIRCLE"],
|
|
6
|
+
["BAMBOO", "bamboo_planKey"],
|
|
7
|
+
["BITBUCKET", "BITBUCKET_COMMIT"],
|
|
8
|
+
["BITRISE", "BITRISE_IO"],
|
|
9
|
+
["BUDDY", "BUDDY_WORKSPACE_ID"],
|
|
10
|
+
["BUILDKITE"],
|
|
11
|
+
["CIRCLE", "CIRCLECI"],
|
|
12
|
+
["CIRRUS", "CIRRUS_CI"],
|
|
13
|
+
["CODEBUILD", "CODEBUILD_BUILD_ARN"],
|
|
14
|
+
["CODEFRESH", "CF_BUILD_ID"],
|
|
15
|
+
["DRONE"],
|
|
16
|
+
["DRONE", "DRONE_BUILD_EVENT"],
|
|
17
|
+
["DSARI"],
|
|
18
|
+
["GITHUB_ACTIONS"],
|
|
19
|
+
["GITLAB", "GITLAB_CI"],
|
|
20
|
+
["GITLAB", "CI_MERGE_REQUEST_ID"],
|
|
21
|
+
["GOCD", "GO_PIPELINE_LABEL"],
|
|
22
|
+
["LAYERCI"],
|
|
23
|
+
["HUDSON", "HUDSON_URL"],
|
|
24
|
+
["JENKINS", "JENKINS_URL"],
|
|
25
|
+
["MAGNUM"],
|
|
26
|
+
["NETLIFY"],
|
|
27
|
+
["NETLIFY", "NETLIFY_LOCAL", { ci: false }],
|
|
28
|
+
["NEVERCODE"],
|
|
29
|
+
["RENDER"],
|
|
30
|
+
["SAIL", "SAILCI"],
|
|
31
|
+
["SEMAPHORE"],
|
|
32
|
+
["SCREWDRIVER"],
|
|
33
|
+
["SHIPPABLE"],
|
|
34
|
+
["SOLANO", "TDDIUM"],
|
|
35
|
+
["STRIDER"],
|
|
36
|
+
["TEAMCITY", "TEAMCITY_VERSION"],
|
|
37
|
+
["TRAVIS"],
|
|
38
|
+
["VERCEL", "NOW_BUILDER"],
|
|
39
|
+
["APPCENTER", "APPCENTER_BUILD_ID"],
|
|
40
|
+
["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }],
|
|
41
|
+
["STACKBLITZ"]
|
|
42
|
+
];
|
|
43
|
+
function detectProvider(env) {
|
|
44
|
+
for (const provider of providers) {
|
|
45
|
+
const envName = provider[1] || provider[0];
|
|
46
|
+
if (env[envName]) {
|
|
47
|
+
return {
|
|
48
|
+
name: provider[0].toLowerCase(),
|
|
49
|
+
...provider[2]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (env.SHELL && env.SHELL === "/bin/jsh") {
|
|
54
|
+
return {
|
|
55
|
+
name: "stackblitz",
|
|
56
|
+
ci: false
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
name: "",
|
|
61
|
+
ci: false
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const processShim = typeof process !== "undefined" ? process : {};
|
|
66
|
+
const envShim = processShim.env || {};
|
|
67
|
+
const providerInfo = detectProvider(envShim);
|
|
68
|
+
const nodeENV = envShim.NODE_ENV || "";
|
|
69
|
+
const platform = processShim.platform;
|
|
70
|
+
const provider = providerInfo.name;
|
|
71
|
+
const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false;
|
|
72
|
+
const hasTTY = toBoolean(processShim.stdout && processShim.stdout.isTTY);
|
|
73
|
+
const hasWindow = typeof window !== "undefined";
|
|
74
|
+
const isDebug = toBoolean(envShim.DEBUG);
|
|
75
|
+
const isTest = toBoolean(envShim.TEST);
|
|
76
|
+
const isProduction = nodeENV === "production";
|
|
77
|
+
const isDevelopment = nodeENV === "dev" || nodeENV === "development";
|
|
78
|
+
const isMinimal = toBoolean(envShim.MINIMAL) || isCI || isTest || !hasTTY;
|
|
79
|
+
const isWindows = /^win/i.test(platform);
|
|
80
|
+
const isLinux = /^linux/i.test(platform);
|
|
81
|
+
const isMacOS = /^darwin/i.test(platform);
|
|
82
|
+
function toBoolean(val) {
|
|
83
|
+
return val ? val !== "false" : false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { hasTTY, hasWindow, isCI, isDebug, isDevelopment, isLinux, isMacOS, isMinimal, isProduction, isTest, isWindows, platform, provider };
|
package/package.json
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "std-env",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Detect
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"description": "Detect current Javascript environment",
|
|
5
5
|
"repository": "unjs/std-env",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.cjs"
|
|
11
11
|
},
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
12
14
|
"files": [
|
|
13
|
-
"
|
|
14
|
-
"index.d.ts"
|
|
15
|
+
"dist"
|
|
15
16
|
],
|
|
16
|
-
"
|
|
17
|
-
"
|
|
17
|
+
"scripts": {
|
|
18
|
+
"prepack": "unbuild",
|
|
19
|
+
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
|
|
20
|
+
"test": "node test.cjs"
|
|
18
21
|
},
|
|
19
22
|
"devDependencies": {
|
|
20
|
-
"standard-version": "^9.3.
|
|
23
|
+
"standard-version": "^9.3.2",
|
|
24
|
+
"unbuild": "^0.5.11"
|
|
21
25
|
}
|
|
22
26
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
### [2.3.1](https://github.com/unjs/std-env/compare/v2.3.0...v2.3.1) (2021-09-29)
|
package/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
declare const env: {
|
|
2
|
-
readonly browser: boolean
|
|
3
|
-
|
|
4
|
-
readonly test: boolean
|
|
5
|
-
readonly dev: boolean
|
|
6
|
-
readonly production: boolean
|
|
7
|
-
readonly debug: boolean
|
|
8
|
-
|
|
9
|
-
readonly ci: boolean
|
|
10
|
-
readonly tty: boolean
|
|
11
|
-
|
|
12
|
-
readonly minimal: boolean
|
|
13
|
-
readonly minimalCLI: boolean
|
|
14
|
-
|
|
15
|
-
readonly windows: boolean
|
|
16
|
-
readonly darwin: boolean
|
|
17
|
-
readonly linux: boolean
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default env;
|
package/index.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// Gather initial information
|
|
2
|
-
var isCI = false
|
|
3
|
-
var debug = false
|
|
4
|
-
var tty = false
|
|
5
|
-
var nodeENV = 'development'
|
|
6
|
-
var browser = typeof window !== 'undefined'
|
|
7
|
-
var platform = ''
|
|
8
|
-
var minimal = false
|
|
9
|
-
|
|
10
|
-
// Boolean helper
|
|
11
|
-
function toBoolean(val) {
|
|
12
|
-
return (!val || val === 'false') ? false : true
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Process dependent
|
|
16
|
-
if (typeof process !== 'undefined') {
|
|
17
|
-
// Platform
|
|
18
|
-
if (process.platform) {
|
|
19
|
-
platform = String(process.platform)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// TTY
|
|
23
|
-
if (process.stdout) {
|
|
24
|
-
tty = toBoolean(process.stdout.isTTY)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Is CI
|
|
28
|
-
isCI = Boolean(require('ci-info').isCI)
|
|
29
|
-
|
|
30
|
-
// Env dependent
|
|
31
|
-
if (process.env) {
|
|
32
|
-
// NODE_ENV
|
|
33
|
-
if (process.env.NODE_ENV) {
|
|
34
|
-
nodeENV = process.env.NODE_ENV
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// DEBUG
|
|
38
|
-
debug = toBoolean(process.env.DEBUG)
|
|
39
|
-
|
|
40
|
-
// MINIMAL
|
|
41
|
-
minimal = toBoolean(process.env.MINIMAL)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Construct env object
|
|
46
|
-
var env = {
|
|
47
|
-
browser: browser,
|
|
48
|
-
|
|
49
|
-
test: nodeENV === 'test',
|
|
50
|
-
dev: nodeENV === 'development' || nodeENV === 'dev',
|
|
51
|
-
production: nodeENV === 'production',
|
|
52
|
-
debug: debug,
|
|
53
|
-
|
|
54
|
-
ci: isCI,
|
|
55
|
-
tty: tty,
|
|
56
|
-
|
|
57
|
-
minimal: undefined,
|
|
58
|
-
minimalCLI: undefined,
|
|
59
|
-
|
|
60
|
-
windows: /^win/i.test(platform),
|
|
61
|
-
darwin: /^darwin/i.test(platform),
|
|
62
|
-
linux: /^linux/i.test(platform),
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Compute minimal
|
|
66
|
-
env.minimal = minimal || env.ci || env.test || !env.tty
|
|
67
|
-
env.minimalCLI = env.minimal
|
|
68
|
-
|
|
69
|
-
// Export env
|
|
70
|
-
module.exports = Object.freeze(env)
|