std-env 3.0.0-alpha → 3.1.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/LICENCE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 UnJS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md CHANGED
@@ -1,48 +1,52 @@
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
+ [![bundlephobia](https://img.shields.io/bundlephobia/min/std-env/latest.svg?style=flat-square)](https://bundlephobia.com/result?p=std-env)
5
6
 
6
- Detect running environment of the current Node.js process.
7
+ > Detect current Javascript environment
7
8
 
8
9
  ## Installation
9
10
 
10
- Using yarn:
11
-
12
- ```
11
+ ```sh
12
+ # Using Yarn
13
13
  yarn add std-env
14
- ```
15
14
 
16
- Usin 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
- 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
- */
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
@@ -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' | 'stormkit';
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,87 @@
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
+ ["STORMKIT"]
43
+ ];
44
+ function detectProvider(env) {
45
+ for (const provider of providers) {
46
+ const envName = provider[1] || provider[0];
47
+ if (env[envName]) {
48
+ return {
49
+ name: provider[0].toLowerCase(),
50
+ ...provider[2]
51
+ };
52
+ }
53
+ }
54
+ if (env.SHELL && env.SHELL === "/bin/jsh") {
55
+ return {
56
+ name: "stackblitz",
57
+ ci: false
58
+ };
59
+ }
60
+ return {
61
+ name: "",
62
+ ci: false
63
+ };
64
+ }
65
+
66
+ const processShim = typeof process !== "undefined" ? process : {};
67
+ const envShim = processShim.env || {};
68
+ const providerInfo = detectProvider(envShim);
69
+ const nodeENV = envShim.NODE_ENV || "";
70
+ const platform = processShim.platform;
71
+ const provider = providerInfo.name;
72
+ const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false;
73
+ const hasTTY = toBoolean(processShim.stdout && processShim.stdout.isTTY);
74
+ const hasWindow = typeof window !== "undefined";
75
+ const isDebug = toBoolean(envShim.DEBUG);
76
+ const isTest = toBoolean(envShim.TEST);
77
+ const isProduction = nodeENV === "production";
78
+ const isDevelopment = nodeENV === "dev" || nodeENV === "development";
79
+ const isMinimal = toBoolean(envShim.MINIMAL) || isCI || isTest || !hasTTY;
80
+ const isWindows = /^win/i.test(platform);
81
+ const isLinux = /^linux/i.test(platform);
82
+ const isMacOS = /^darwin/i.test(platform);
83
+ function toBoolean(val) {
84
+ return val ? val !== "false" : false;
85
+ }
86
+
87
+ export { hasTTY, hasWindow, isCI, isDebug, isDevelopment, isLinux, isMacOS, isMinimal, isProduction, isTest, isWindows, platform, provider };
package/package.json CHANGED
@@ -1,19 +1,35 @@
1
1
  {
2
2
  "name": "std-env",
3
- "version": "3.0.0-alpha",
4
- "description": "Detect running environment of the current Node.js process",
3
+ "version": "3.1.0",
4
+ "description": "Detect current Javascript environment",
5
+ "repository": "unjs/std-env",
5
6
  "license": "MIT",
6
- "main": "index.js",
7
- "types": "index.d.ts",
8
- "repository": "nuxt-contrib/std-env",
9
- "contributors": [
10
- "Pooya Parsa <pooya@pi0.ir>"
11
- ],
12
- "dependencies": {
13
- "ci-info": "^2.0.0"
7
+ "sideEffects": false,
8
+ "exports": {
9
+ "import": "./dist/index.mjs",
10
+ "require": "./dist/index.cjs"
14
11
  },
12
+ "main": "./dist/index.cjs",
13
+ "types": "./dist/index.d.ts",
15
14
  "files": [
16
- "index.js",
17
- "index.d.ts"
18
- ]
19
- }
15
+ "dist"
16
+ ],
17
+ "devDependencies": {
18
+ "@nuxtjs/eslint-config-typescript": "^9.0.0",
19
+ "c8": "^7.11.0",
20
+ "eslint": "^8.13.0",
21
+ "jiti": "^1.13.0",
22
+ "standard-version": "^9.3.2",
23
+ "unbuild": "^0.7.4",
24
+ "vitest": "^0.9.3"
25
+ },
26
+ "packageManager": "pnpm@6.32.7",
27
+ "scripts": {
28
+ "build": "unbuild",
29
+ "dev": "vitest",
30
+ "lint": "eslint --ext .ts .",
31
+ "release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
32
+ "test": "pnpm lint && vitest run"
33
+ },
34
+ "readme": "# std-env\n\n[![npm](https://img.shields.io/npm/dm/std-env.svg?style=flat-square)](http://npmjs.com/package/std-env)\n[![npm](https://img.shields.io/npm/v/std-env.svg?style=flat-square)](http://npmjs.com/package/std-env)\n[![bundlephobia](https://img.shields.io/bundlephobia/min/std-env/latest.svg?style=flat-square)](https://bundlephobia.com/result?p=std-env)\n\n> Detect current Javascript environment\n\n## Installation\n\n```sh\n# Using Yarn\nyarn add std-env\n\n# Using npm\nnpm i std-env\n```\n\n## Usage\n\n```js\n// ESM\nimport { isWindows } from 'std-env'\n\n// CommonJS\nconst { isCI } = require('std-env')\n```\n\nAvailable exports:\n\n- `hasTTY`\n- `hasWindow`\n- `isCI`\n- `isDebug`\n- `isDevelopment`\n- `isLinux`\n- `isMacOS`\n- `isMinimal`\n- `isProduction`\n- `isTest`\n- `isWindows`\n- `platform`\n- `provider`\n\nYou can read more about how each flag works from [./src/index.ts](./src/index.ts).\n\nList of well known providers can be found from [./src/providers.ts](./src/providers.ts).\n\n\n## License\n\nMIT\n"
35
+ }
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)