std-env 2.3.1 → 3.0.0-0

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 CHANGED
@@ -1,48 +1,51 @@
1
1
  # std-env
2
2
 
3
- [![npm](https://img.shields.io/npm/dt/std-env.svg?style=flat-square)](http://npmjs.com/package/std-env)
3
+ [![npm](https://img.shields.io/npm/dm/std-env.svg?style=flat-square)](http://npmjs.com/package/std-env)
4
4
  [![npm](https://img.shields.io/npm/v/std-env.svg?style=flat-square)](http://npmjs.com/package/std-env)
5
5
 
6
- Detect running environment of the current Node.js process.
6
+ > Simplified way to detect current running Javascript environment
7
7
 
8
8
  ## Installation
9
9
 
10
- Using Yarn:
11
-
12
- ```
10
+ ```sh
11
+ # Using Yarn
13
12
  yarn add std-env
14
- ```
15
13
 
16
- Using npm:
17
-
18
- ```
14
+ # Using npm
19
15
  npm i std-env
20
16
  ```
21
17
 
22
18
  ## Usage
23
19
 
24
20
  ```js
25
- const env = require('std-env')
26
-
27
- console.log(env)
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
- */
21
+ // ESM
22
+ import { isWindows } from 'std-env'
23
+
24
+ // CommonJS
25
+ const { isCI } = require('std-env')
44
26
  ```
45
27
 
28
+ Available exports:
29
+
30
+ - `hasTTY`
31
+ - `hasWindow`
32
+ - `isCI`
33
+ - `isDebug`
34
+ - `isDevelopment`
35
+ - `isLinux`
36
+ - `isMacOS`
37
+ - `isMinimal`
38
+ - `isProduction`
39
+ - `isTest`
40
+ - `isWindows`
41
+ - `platform`
42
+ - `provider`
43
+
44
+ You can read more about how each flag works from [./src/index.ts](./src/index.ts).
45
+
46
+ List of well known providers can be found from [./src/providers.ts](./src/providers.ts).
47
+
48
+
46
49
  ## License
47
50
 
48
51
  MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,100 @@
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
+ };
61
+ }
62
+ return {
63
+ name: ""
64
+ };
65
+ }
66
+
67
+ const processShim = typeof process !== "undefined" ? process : {};
68
+ const envShim = processShim.env || {};
69
+ const providerInfo = detectProvider(envShim);
70
+ const nodeENV = envShim.NODE_ENV || "";
71
+ const platform = processShim.platform;
72
+ const provider = providerInfo.name;
73
+ const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false;
74
+ const hasTTY = toBoolean(processShim.stdout && processShim.stdout.isTTY);
75
+ const hasWindow = typeof window !== "undefined";
76
+ const isDebug = toBoolean(envShim.DEBUG);
77
+ const isTest = toBoolean(envShim.TEST);
78
+ const isProduction = nodeENV === "production";
79
+ const isDevelopment = nodeENV === "dev" || nodeENV === "development";
80
+ const isMinimal = toBoolean(envShim.MINIMAL) || isCI || isTest || !hasTTY;
81
+ const isWindows = /^win/i.test(platform);
82
+ const isLinux = /^linux/i.test(platform);
83
+ const isMacOS = /^darwin/i.test(platform);
84
+ function toBoolean(val) {
85
+ return val ? val !== "false" : false;
86
+ }
87
+
88
+ exports.hasTTY = hasTTY;
89
+ exports.hasWindow = hasWindow;
90
+ exports.isCI = isCI;
91
+ exports.isDebug = isDebug;
92
+ exports.isDevelopment = isDevelopment;
93
+ exports.isLinux = isLinux;
94
+ exports.isMacOS = isMacOS;
95
+ exports.isMinimal = isMinimal;
96
+ exports.isProduction = isProduction;
97
+ exports.isTest = isTest;
98
+ exports.isWindows = isWindows;
99
+ exports.platform = platform;
100
+ exports.provider = provider;
@@ -0,0 +1,36 @@
1
+ declare type InternalProvider = [vendorName: string, envName?: string, meta?: Record<string, any>];
2
+ declare const providers: InternalProvider[];
3
+ declare type ProviderName = Lowercase<(typeof providers)[number][0]>;
4
+ declare type ProviderInfo = {
5
+ name: ProviderName;
6
+ [meta: string]: any;
7
+ };
8
+
9
+ /** Value of process.platform */
10
+ declare const platform: NodeJS.Platform;
11
+ /** Current current provider name */
12
+ declare const provider: string;
13
+ /** Detect if `CI` environment variable is set or a provider CI detected */
14
+ declare const isCI: boolean;
15
+ /** Detect if stdout.TTY is available */
16
+ declare const hasTTY: boolean;
17
+ /** Detect if global `window` object is available */
18
+ declare const hasWindow: boolean;
19
+ /** Detect if `DEBUG` environment variable is set */
20
+ declare const isDebug: boolean;
21
+ /** Detect if `NODE_ENV` environment variable is `test` */
22
+ declare const isTest: boolean;
23
+ /** Detect if `NODE_ENV` environment variable is `production` */
24
+ declare const isProduction: boolean;
25
+ /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
26
+ declare const isDevelopment: boolean;
27
+ /** Detect if MINIMAL environment variable is set, running in CI or test or TTY is unavailable */
28
+ declare const isMinimal: boolean;
29
+ /** Detect if process.platform is Windows */
30
+ declare const isWindows: boolean;
31
+ /** Detect if process.platform is Linux */
32
+ declare const isLinux: boolean;
33
+ /** Detect if process.platform is macOS (darwin kernel) */
34
+ declare const isMacOS: boolean;
35
+
36
+ export { ProviderInfo, ProviderName, hasTTY, hasWindow, isCI, isDebug, isDevelopment, isLinux, isMacOS, isMinimal, isProduction, isTest, isWindows, platform, provider };
package/dist/index.mjs ADDED
@@ -0,0 +1,84 @@
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
+ };
57
+ }
58
+ return {
59
+ name: ""
60
+ };
61
+ }
62
+
63
+ const processShim = typeof process !== "undefined" ? process : {};
64
+ const envShim = processShim.env || {};
65
+ const providerInfo = detectProvider(envShim);
66
+ const nodeENV = envShim.NODE_ENV || "";
67
+ const platform = processShim.platform;
68
+ const provider = providerInfo.name;
69
+ const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false;
70
+ const hasTTY = toBoolean(processShim.stdout && processShim.stdout.isTTY);
71
+ const hasWindow = typeof window !== "undefined";
72
+ const isDebug = toBoolean(envShim.DEBUG);
73
+ const isTest = toBoolean(envShim.TEST);
74
+ const isProduction = nodeENV === "production";
75
+ const isDevelopment = nodeENV === "dev" || nodeENV === "development";
76
+ const isMinimal = toBoolean(envShim.MINIMAL) || isCI || isTest || !hasTTY;
77
+ const isWindows = /^win/i.test(platform);
78
+ const isLinux = /^linux/i.test(platform);
79
+ const isMacOS = /^darwin/i.test(platform);
80
+ function toBoolean(val) {
81
+ return val ? val !== "false" : false;
82
+ }
83
+
84
+ 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": "2.3.1",
4
- "description": "Detect running environment of the current Node.js process",
3
+ "version": "3.0.0-0",
4
+ "description": "Simplified way to detect current running Javascript environment",
5
5
  "repository": "unjs/std-env",
6
6
  "license": "MIT",
7
- "main": "./index.js",
8
- "types": "./index.d.ts",
9
- "scripts": {
10
- "release": "standard-version && git push --follow-tags && npm publish"
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
- "index.js",
14
- "index.d.ts"
15
+ "dist"
15
16
  ],
16
- "dependencies": {
17
- "ci-info": "^3.1.1"
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.1"
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)