std-env 3.3.3 → 3.4.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
@@ -4,33 +4,35 @@
4
4
  [![npm](https://img.shields.io/npm/v/std-env.svg?style=flat-square)](http://npmjs.com/package/std-env)
5
5
  [![bundlephobia](https://img.shields.io/bundlephobia/min/std-env/latest.svg?style=flat-square)](https://bundlephobia.com/result?p=std-env)
6
6
 
7
- > Detect current Javascript environment
7
+ > Runtime agnostic JS utils
8
8
 
9
9
  ## Installation
10
10
 
11
11
  ```sh
12
- # Using Yarn
13
- yarn add std-env
14
-
15
12
  # Using npm
16
13
  npm i std-env
14
+
15
+ # Using pnpm
16
+ pnpm i std-env
17
+
18
+ # Using yarn
19
+ yarn add std-env
17
20
  ```
18
21
 
19
22
  ## Usage
20
23
 
21
24
  ```js
22
25
  // ESM
23
- import { isWindows } from 'std-env'
26
+ import { env, isDevelopment, isProduction } from "std-env";
24
27
 
25
28
  // CommonJS
26
- const { isCI } = require('std-env')
29
+ const { env, isDevelopment, isProduction } = require("std-env");
27
30
  ```
28
31
 
29
- Available exports:
32
+ ## Flags
30
33
 
31
34
  - `hasTTY`
32
35
  - `hasWindow`
33
- - `isCI`
34
36
  - `isDebug`
35
37
  - `isDevelopment`
36
38
  - `isLinux`
@@ -40,12 +42,72 @@ Available exports:
40
42
  - `isTest`
41
43
  - `isWindows`
42
44
  - `platform`
43
- - `provider`
45
+ - `isColorSupported`
46
+ - `nodeVersion`
47
+ - `nodeMajorVersion`
48
+
49
+ You can read more about how each flag works from [./src/flags.ts](./src/flags.ts).
50
+
51
+ ## Provider Detection
44
52
 
45
- You can read more about how each flag works from [./src/index.ts](./src/index.ts).
53
+ `std-env` can automatically detect the current runtime provider based on environment variables.
54
+
55
+ You can use `isCI` and `platform` exports to detect it:
56
+
57
+ ```ts
58
+ import { isCI, provider, providerInfo } from "std-env";
59
+
60
+ console.log({
61
+ isCI, // true
62
+ provider, // "github_actions"
63
+ providerInfo, // { name: "github_actions", isCI: true }
64
+ });
65
+ ```
46
66
 
47
67
  List of well known providers can be found from [./src/providers.ts](./src/providers.ts).
48
68
 
69
+ ## Runtime Detection
70
+
71
+ `std-env` can automatically detect the current JavaScript runtime based on global variables, following the [WinterCG Runtime Keys proposal](https://runtime-keys.proposal.wintercg.org/):
72
+
73
+ ```ts
74
+ import { runtime, runtimeInfo } from "std-env";
75
+
76
+ // "" | "node" | "deno" | "bun" | "workerd" | "lagon" ...
77
+ console.log(runtime);
78
+
79
+ // { name: "node" }
80
+ console.log(runtimeInfo);
81
+ ```
82
+
83
+ You can also use individual named exports for each runtime detection:
84
+
85
+ - `isNetlify`
86
+ - `isEdgeLight`
87
+ - `isWorkerd`
88
+ - `isDeno`
89
+ - `isLagon`
90
+ - `isNode`
91
+ - `isBun`
92
+ - `isFastly`
93
+
94
+ List of well known providers can be found from [./src/runtimes.ts](./src/runtimes.ts).
95
+
96
+ ## Platform-Agnostic `env`
97
+
98
+ `std-env` provides a lightweight proxy to access environment variables in a platform agnostic way.
99
+
100
+ ```ts
101
+ import { env } from "std-env";
102
+ ```
103
+
104
+ ## Platform-Agnostic `process`
105
+
106
+ `std-env` provides a lightweight proxy to access [`process`](https://nodejs.org/api/process.html) object in a platform agnostic way.
107
+
108
+ ```ts
109
+ import { process } from "std-env";
110
+ ```
49
111
 
50
112
  ## License
51
113
 
package/dist/index.cjs CHANGED
@@ -1,103 +1 @@
1
- 'use strict';
2
-
3
- const providers = [
4
- ["APPVEYOR"],
5
- ["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],
6
- ["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],
7
- ["APPCIRCLE", "AC_APPCIRCLE"],
8
- ["BAMBOO", "bamboo_planKey"],
9
- ["BITBUCKET", "BITBUCKET_COMMIT"],
10
- ["BITRISE", "BITRISE_IO"],
11
- ["BUDDY", "BUDDY_WORKSPACE_ID"],
12
- ["BUILDKITE"],
13
- ["CIRCLE", "CIRCLECI"],
14
- ["CIRRUS", "CIRRUS_CI"],
15
- ["CLOUDFLARE_PAGES", "CF_PAGES", { ci: true }],
16
- ["CODEBUILD", "CODEBUILD_BUILD_ARN"],
17
- ["CODEFRESH", "CF_BUILD_ID"],
18
- ["DRONE"],
19
- ["DRONE", "DRONE_BUILD_EVENT"],
20
- ["DSARI"],
21
- ["GITHUB_ACTIONS"],
22
- ["GITLAB", "GITLAB_CI"],
23
- ["GITLAB", "CI_MERGE_REQUEST_ID"],
24
- ["GOCD", "GO_PIPELINE_LABEL"],
25
- ["LAYERCI"],
26
- ["HUDSON", "HUDSON_URL"],
27
- ["JENKINS", "JENKINS_URL"],
28
- ["MAGNUM"],
29
- ["NETLIFY"],
30
- ["NETLIFY", "NETLIFY_LOCAL", { ci: false }],
31
- ["NEVERCODE"],
32
- ["RENDER"],
33
- ["SAIL", "SAILCI"],
34
- ["SEMAPHORE"],
35
- ["SCREWDRIVER"],
36
- ["SHIPPABLE"],
37
- ["SOLANO", "TDDIUM"],
38
- ["STRIDER"],
39
- ["TEAMCITY", "TEAMCITY_VERSION"],
40
- ["TRAVIS"],
41
- ["VERCEL", "NOW_BUILDER"],
42
- ["APPCENTER", "APPCENTER_BUILD_ID"],
43
- ["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }],
44
- ["STACKBLITZ"],
45
- ["STORMKIT"],
46
- ["CLEAVR"]
47
- ];
48
- function detectProvider(env) {
49
- for (const provider of providers) {
50
- const envName = provider[1] || provider[0];
51
- if (env[envName]) {
52
- return {
53
- name: provider[0].toLowerCase(),
54
- ...provider[2]
55
- };
56
- }
57
- }
58
- if (env.SHELL && env.SHELL === "/bin/jsh") {
59
- return {
60
- name: "stackblitz",
61
- ci: false
62
- };
63
- }
64
- return {
65
- name: "",
66
- ci: false
67
- };
68
- }
69
-
70
- const processShim = typeof process !== "undefined" ? process : {};
71
- const envShim = processShim.env || {};
72
- const providerInfo = detectProvider(envShim);
73
- const nodeENV = typeof process !== "undefined" && process.env && process.env.NODE_ENV || "";
74
- const platform = processShim.platform;
75
- const provider = providerInfo.name;
76
- const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false;
77
- const hasTTY = toBoolean(processShim.stdout && processShim.stdout.isTTY);
78
- const hasWindow = typeof window !== "undefined";
79
- const isDebug = toBoolean(envShim.DEBUG);
80
- const isTest = nodeENV === "test" || toBoolean(envShim.TEST);
81
- const isProduction = nodeENV === "production";
82
- const isDevelopment = nodeENV === "dev" || nodeENV === "development";
83
- const isMinimal = toBoolean(envShim.MINIMAL) || isCI || isTest || !hasTTY;
84
- const isWindows = /^win/i.test(platform);
85
- const isLinux = /^linux/i.test(platform);
86
- const isMacOS = /^darwin/i.test(platform);
87
- function toBoolean(val) {
88
- return val ? val !== "false" : false;
89
- }
90
-
91
- exports.hasTTY = hasTTY;
92
- exports.hasWindow = hasWindow;
93
- exports.isCI = isCI;
94
- exports.isDebug = isDebug;
95
- exports.isDevelopment = isDevelopment;
96
- exports.isLinux = isLinux;
97
- exports.isMacOS = isMacOS;
98
- exports.isMinimal = isMinimal;
99
- exports.isProduction = isProduction;
100
- exports.isTest = isTest;
101
- exports.isWindows = isWindows;
102
- exports.platform = platform;
103
- exports.provider = provider;
1
+ "use strict";const r$1=Object.create(null),s=e=>globalThis.process?.env||void 0||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?r$1:globalThis),env=new Proxy(r$1,{get(e,n){return s()[n]??r$1[n]},has(e,n){const i=s();return n in i||n in r$1},set(e,n,i){const l=s(!0);return l[n]=i,!0},deleteProperty(e,n){if(!n)return!1;const i=s(!0);return delete i[n],!0},ownKeys(){const e=s(!0);return Object.keys(e)}}),nodeENV=typeof process<"u"&&process.env&&process.env.NODE_ENV||"",E=[["APPVEYOR"],["AZURE_PIPELINES","SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],["AZURE_STATIC","INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],["APPCIRCLE","AC_APPCIRCLE"],["BAMBOO","bamboo_planKey"],["BITBUCKET","BITBUCKET_COMMIT"],["BITRISE","BITRISE_IO"],["BUDDY","BUDDY_WORKSPACE_ID"],["BUILDKITE"],["CIRCLE","CIRCLECI"],["CIRRUS","CIRRUS_CI"],["CLOUDFLARE_PAGES","CF_PAGES",{ci:!0}],["CODEBUILD","CODEBUILD_BUILD_ARN"],["CODEFRESH","CF_BUILD_ID"],["DRONE"],["DRONE","DRONE_BUILD_EVENT"],["DSARI"],["GITHUB_ACTIONS"],["GITLAB","GITLAB_CI"],["GITLAB","CI_MERGE_REQUEST_ID"],["GOCD","GO_PIPELINE_LABEL"],["LAYERCI"],["HUDSON","HUDSON_URL"],["JENKINS","JENKINS_URL"],["MAGNUM"],["NETLIFY"],["NETLIFY","NETLIFY_LOCAL",{ci:!1}],["NEVERCODE"],["RENDER"],["SAIL","SAILCI"],["SEMAPHORE"],["SCREWDRIVER"],["SHIPPABLE"],["SOLANO","TDDIUM"],["STRIDER"],["TEAMCITY","TEAMCITY_VERSION"],["TRAVIS"],["VERCEL","NOW_BUILDER"],["VERCEL","VERCEL",{ci:!1}],["VERCEL","VERCEL_ENV",{ci:!1}],["APPCENTER","APPCENTER_BUILD_ID"],["CODESANDBOX","CODESANDBOX_SSE",{ci:!1}],["STACKBLITZ"],["STORMKIT"],["CLEAVR"]];function I(){if(globalThis.process?.env)for(const e of E){const n=e[1]||e[0];if(globalThis.process?.env[n])return{name:e[0].toLowerCase(),...e[2]}}return globalThis.process?.env?.SHELL==="/bin/jsh"&&globalThis.process?.versions?.webcontainer?{name:"stackblitz",ci:!1}:{name:"",ci:!1}}const providerInfo=I(),provider=providerInfo.name;function toBoolean(e){return e?e!=="false":!1}const platform=globalThis.process?.platform||"",isCI=toBoolean(env.CI)||providerInfo.ci!==!1,hasTTY=toBoolean(globalThis.process?.stdout&&globalThis.process?.stdout.isTTY),hasWindow=typeof window<"u",isDebug=toBoolean(env.DEBUG),isTest=nodeENV==="test"||toBoolean(env.TEST),isProduction=nodeENV==="production",isDevelopment=nodeENV==="dev"||nodeENV==="development",isMinimal=toBoolean(env.MINIMAL)||isCI||isTest||!hasTTY,isWindows=/^win/i.test(platform),isLinux=/^linux/i.test(platform),isMacOS=/^darwin/i.test(platform),isColorSupported=!toBoolean(env.NO_COLOR)&&(toBoolean(env.FORCE_COLOR)||isWindows&&env.TERM!=="dumb"||hasTTY&&env.TERM&&env.TERM==="dumb"||isCI),nodeVersion=(globalThis.process?.versions?.node||"").replace(/^v/,"")||null,nodeMajorVersion=Number(nodeVersion?.split(".")[0])||null,o$1=globalThis.process||Object.create(null),r={versions:{}},process$1=new Proxy(o$1,{get(e,n){if(n==="env")return env;if(n in e)return e[n];if(n in r)return r[n]}}),isNetlify=!!globalThis.Netlify,isEdgeLight=!!globalThis.EdgeRuntime,isWorkerd=globalThis.navigator?.userAgent==="Cloudflare-Workers",isDeno=!!globalThis.Deno,isLagon=!!globalThis.__lagon__,isNode=globalThis.process?.release?.name==="node",isBun=!!globalThis.Bun||!!process.versions.bun,isFastly=!!globalThis.fastly,o=[[isNetlify,"netlify"],[isEdgeLight,"edge-light"],[isWorkerd,"workerd"],[isDeno,"deno"],[isLagon,"lagon"],[isNode,"node"],[isBun,"bun"],[isFastly,"fastly"]];function t(){const e=o.find(n=>n[0]);if(e)return{name:e[1]}}const runtimeInfo=t(),runtime=runtimeInfo?.name||"";exports.env=env,exports.hasTTY=hasTTY,exports.hasWindow=hasWindow,exports.isBun=isBun,exports.isCI=isCI,exports.isColorSupported=isColorSupported,exports.isDebug=isDebug,exports.isDeno=isDeno,exports.isDevelopment=isDevelopment,exports.isEdgeLight=isEdgeLight,exports.isFastly=isFastly,exports.isLagon=isLagon,exports.isLinux=isLinux,exports.isMacOS=isMacOS,exports.isMinimal=isMinimal,exports.isNetlify=isNetlify,exports.isNode=isNode,exports.isProduction=isProduction,exports.isTest=isTest,exports.isWindows=isWindows,exports.isWorkerd=isWorkerd,exports.nodeENV=nodeENV,exports.nodeMajorVersion=nodeMajorVersion,exports.nodeVersion=nodeVersion,exports.platform=platform,exports.process=process$1,exports.provider=provider,exports.providerInfo=providerInfo,exports.runtime=runtime,exports.runtimeInfo=runtimeInfo;
@@ -0,0 +1,66 @@
1
+ type EnvObject = Record<string, string | undefined>;
2
+ declare const env: EnvObject;
3
+ declare const nodeENV: string;
4
+
5
+ /** Value of process.platform */
6
+ declare const platform: NodeJS.Platform;
7
+ /** Detect if `CI` environment variable is set or a provider CI detected */
8
+ declare const isCI: boolean;
9
+ /** Detect if stdout.TTY is available */
10
+ declare const hasTTY: boolean;
11
+ /** Detect if global `window` object is available */
12
+ declare const hasWindow: boolean;
13
+ /** Detect if `DEBUG` environment variable is set */
14
+ declare const isDebug: boolean;
15
+ /** Detect if `NODE_ENV` environment variable is `test` */
16
+ declare const isTest: boolean;
17
+ /** Detect if `NODE_ENV` environment variable is `production` */
18
+ declare const isProduction: boolean;
19
+ /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
20
+ declare const isDevelopment: boolean;
21
+ /** Detect if MINIMAL environment variable is set, running in CI or test or TTY is unavailable */
22
+ declare const isMinimal: boolean;
23
+ /** Detect if process.platform is Windows */
24
+ declare const isWindows: boolean;
25
+ /** Detect if process.platform is Linux */
26
+ declare const isLinux: boolean;
27
+ /** Detect if process.platform is macOS (darwin kernel) */
28
+ declare const isMacOS: boolean;
29
+ /** Color Support */
30
+ declare const isColorSupported: boolean;
31
+ /** Node.js versions */
32
+ declare const nodeVersion: string | null;
33
+ declare const nodeMajorVersion: number | null;
34
+
35
+ interface Process extends Partial<Omit<typeof globalThis.process, "versions">> {
36
+ env: EnvObject;
37
+ versions: Record<string, string>;
38
+ }
39
+ declare const process: Process;
40
+
41
+ type ProviderName = "" | "appveyor" | "azure_pipelines" | "azure_static" | "appcircle" | "bamboo" | "bitbucket" | "bitrise" | "buddy" | "buildkite" | "circle" | "cirrus" | "cloudflare_pages" | "codebuild" | "codefresh" | "drone" | "drone" | "dsari" | "github_actions" | "gitlab" | "gocd" | "layerci" | "hudson" | "jenkins" | "magnum" | "netlify" | "nevercode" | "render" | "sail" | "semaphore" | "screwdriver" | "shippable" | "solano" | "strider" | "teamcity" | "travis" | "vercel" | "appcenter" | "codesandbox" | "stackblitz" | "stormkit" | "cleavr";
42
+ type ProviderInfo = {
43
+ name: ProviderName;
44
+ ci?: boolean;
45
+ [meta: string]: any;
46
+ };
47
+ /** Current provider info */
48
+ declare const providerInfo: ProviderInfo;
49
+ declare const provider: ProviderName;
50
+
51
+ type RuntimeName = "workerd" | "deno" | "lagon" | "netlify" | "node" | "bun" | "edge-light" | "fastly" | "";
52
+ type RuntimeInfo = {
53
+ name: RuntimeName;
54
+ };
55
+ declare const isNetlify: boolean;
56
+ declare const isEdgeLight: boolean;
57
+ declare const isWorkerd: boolean;
58
+ declare const isDeno: boolean;
59
+ declare const isLagon: boolean;
60
+ declare const isNode: boolean;
61
+ declare const isBun: boolean;
62
+ declare const isFastly: boolean;
63
+ declare const runtimeInfo: RuntimeInfo | undefined;
64
+ declare const runtime: string;
65
+
66
+ export { EnvObject, Process, ProviderInfo, ProviderName, RuntimeInfo, RuntimeName, env, hasTTY, hasWindow, isBun, isCI, isColorSupported, isDebug, isDeno, isDevelopment, isEdgeLight, isFastly, isLagon, isLinux, isMacOS, isMinimal, isNetlify, isNode, isProduction, isTest, isWindows, isWorkerd, nodeENV, nodeMajorVersion, nodeVersion, platform, process, provider, providerInfo, runtime, runtimeInfo };
@@ -0,0 +1,66 @@
1
+ type EnvObject = Record<string, string | undefined>;
2
+ declare const env: EnvObject;
3
+ declare const nodeENV: string;
4
+
5
+ /** Value of process.platform */
6
+ declare const platform: NodeJS.Platform;
7
+ /** Detect if `CI` environment variable is set or a provider CI detected */
8
+ declare const isCI: boolean;
9
+ /** Detect if stdout.TTY is available */
10
+ declare const hasTTY: boolean;
11
+ /** Detect if global `window` object is available */
12
+ declare const hasWindow: boolean;
13
+ /** Detect if `DEBUG` environment variable is set */
14
+ declare const isDebug: boolean;
15
+ /** Detect if `NODE_ENV` environment variable is `test` */
16
+ declare const isTest: boolean;
17
+ /** Detect if `NODE_ENV` environment variable is `production` */
18
+ declare const isProduction: boolean;
19
+ /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
20
+ declare const isDevelopment: boolean;
21
+ /** Detect if MINIMAL environment variable is set, running in CI or test or TTY is unavailable */
22
+ declare const isMinimal: boolean;
23
+ /** Detect if process.platform is Windows */
24
+ declare const isWindows: boolean;
25
+ /** Detect if process.platform is Linux */
26
+ declare const isLinux: boolean;
27
+ /** Detect if process.platform is macOS (darwin kernel) */
28
+ declare const isMacOS: boolean;
29
+ /** Color Support */
30
+ declare const isColorSupported: boolean;
31
+ /** Node.js versions */
32
+ declare const nodeVersion: string | null;
33
+ declare const nodeMajorVersion: number | null;
34
+
35
+ interface Process extends Partial<Omit<typeof globalThis.process, "versions">> {
36
+ env: EnvObject;
37
+ versions: Record<string, string>;
38
+ }
39
+ declare const process: Process;
40
+
41
+ type ProviderName = "" | "appveyor" | "azure_pipelines" | "azure_static" | "appcircle" | "bamboo" | "bitbucket" | "bitrise" | "buddy" | "buildkite" | "circle" | "cirrus" | "cloudflare_pages" | "codebuild" | "codefresh" | "drone" | "drone" | "dsari" | "github_actions" | "gitlab" | "gocd" | "layerci" | "hudson" | "jenkins" | "magnum" | "netlify" | "nevercode" | "render" | "sail" | "semaphore" | "screwdriver" | "shippable" | "solano" | "strider" | "teamcity" | "travis" | "vercel" | "appcenter" | "codesandbox" | "stackblitz" | "stormkit" | "cleavr";
42
+ type ProviderInfo = {
43
+ name: ProviderName;
44
+ ci?: boolean;
45
+ [meta: string]: any;
46
+ };
47
+ /** Current provider info */
48
+ declare const providerInfo: ProviderInfo;
49
+ declare const provider: ProviderName;
50
+
51
+ type RuntimeName = "workerd" | "deno" | "lagon" | "netlify" | "node" | "bun" | "edge-light" | "fastly" | "";
52
+ type RuntimeInfo = {
53
+ name: RuntimeName;
54
+ };
55
+ declare const isNetlify: boolean;
56
+ declare const isEdgeLight: boolean;
57
+ declare const isWorkerd: boolean;
58
+ declare const isDeno: boolean;
59
+ declare const isLagon: boolean;
60
+ declare const isNode: boolean;
61
+ declare const isBun: boolean;
62
+ declare const isFastly: boolean;
63
+ declare const runtimeInfo: RuntimeInfo | undefined;
64
+ declare const runtime: string;
65
+
66
+ export { EnvObject, Process, ProviderInfo, ProviderName, RuntimeInfo, RuntimeName, env, hasTTY, hasWindow, isBun, isCI, isColorSupported, isDebug, isDeno, isDevelopment, isEdgeLight, isFastly, isLagon, isLinux, isMacOS, isMinimal, isNetlify, isNode, isProduction, isTest, isWindows, isWorkerd, nodeENV, nodeMajorVersion, nodeVersion, platform, process, provider, providerInfo, runtime, runtimeInfo };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,9 @@
1
- type ProviderName = "" | "appveyor" | "azure_pipelines" | "azure_static" | "appcircle" | "bamboo" | "bitbucket" | "bitrise" | "buddy" | "buildkite" | "circle" | "cirrus" | "cloudflare_pages" | "codebuild" | "codefresh" | "drone" | "drone" | "dsari" | "github_actions" | "gitlab" | "gocd" | "layerci" | "hudson" | "jenkins" | "magnum" | "netlify" | "nevercode" | "render" | "sail" | "semaphore" | "screwdriver" | "shippable" | "solano" | "strider" | "teamcity" | "travis" | "vercel" | "appcenter" | "codesandbox" | "stackblitz" | "stormkit" | "cleavr";
2
- type ProviderInfo = {
3
- name: ProviderName;
4
- [meta: string]: any;
5
- };
1
+ type EnvObject = Record<string, string | undefined>;
2
+ declare const env: EnvObject;
3
+ declare const nodeENV: string;
6
4
 
7
5
  /** Value of process.platform */
8
6
  declare const platform: NodeJS.Platform;
9
- /** Current provider name */
10
- declare const provider: ProviderName;
11
7
  /** Detect if `CI` environment variable is set or a provider CI detected */
12
8
  declare const isCI: boolean;
13
9
  /** Detect if stdout.TTY is available */
@@ -30,5 +26,41 @@ declare const isWindows: boolean;
30
26
  declare const isLinux: boolean;
31
27
  /** Detect if process.platform is macOS (darwin kernel) */
32
28
  declare const isMacOS: boolean;
29
+ /** Color Support */
30
+ declare const isColorSupported: boolean;
31
+ /** Node.js versions */
32
+ declare const nodeVersion: string | null;
33
+ declare const nodeMajorVersion: number | null;
34
+
35
+ interface Process extends Partial<Omit<typeof globalThis.process, "versions">> {
36
+ env: EnvObject;
37
+ versions: Record<string, string>;
38
+ }
39
+ declare const process: Process;
40
+
41
+ type ProviderName = "" | "appveyor" | "azure_pipelines" | "azure_static" | "appcircle" | "bamboo" | "bitbucket" | "bitrise" | "buddy" | "buildkite" | "circle" | "cirrus" | "cloudflare_pages" | "codebuild" | "codefresh" | "drone" | "drone" | "dsari" | "github_actions" | "gitlab" | "gocd" | "layerci" | "hudson" | "jenkins" | "magnum" | "netlify" | "nevercode" | "render" | "sail" | "semaphore" | "screwdriver" | "shippable" | "solano" | "strider" | "teamcity" | "travis" | "vercel" | "appcenter" | "codesandbox" | "stackblitz" | "stormkit" | "cleavr";
42
+ type ProviderInfo = {
43
+ name: ProviderName;
44
+ ci?: boolean;
45
+ [meta: string]: any;
46
+ };
47
+ /** Current provider info */
48
+ declare const providerInfo: ProviderInfo;
49
+ declare const provider: ProviderName;
50
+
51
+ type RuntimeName = "workerd" | "deno" | "lagon" | "netlify" | "node" | "bun" | "edge-light" | "fastly" | "";
52
+ type RuntimeInfo = {
53
+ name: RuntimeName;
54
+ };
55
+ declare const isNetlify: boolean;
56
+ declare const isEdgeLight: boolean;
57
+ declare const isWorkerd: boolean;
58
+ declare const isDeno: boolean;
59
+ declare const isLagon: boolean;
60
+ declare const isNode: boolean;
61
+ declare const isBun: boolean;
62
+ declare const isFastly: boolean;
63
+ declare const runtimeInfo: RuntimeInfo | undefined;
64
+ declare const runtime: string;
33
65
 
34
- export { ProviderInfo, ProviderName, hasTTY, hasWindow, isCI, isDebug, isDevelopment, isLinux, isMacOS, isMinimal, isProduction, isTest, isWindows, platform, provider };
66
+ export { EnvObject, Process, ProviderInfo, ProviderName, RuntimeInfo, RuntimeName, env, hasTTY, hasWindow, isBun, isCI, isColorSupported, isDebug, isDeno, isDevelopment, isEdgeLight, isFastly, isLagon, isLinux, isMacOS, isMinimal, isNetlify, isNode, isProduction, isTest, isWindows, isWorkerd, nodeENV, nodeMajorVersion, nodeVersion, platform, process, provider, providerInfo, runtime, runtimeInfo };
package/dist/index.mjs CHANGED
@@ -1,89 +1 @@
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
- ["CLOUDFLARE_PAGES", "CF_PAGES", { ci: true }],
14
- ["CODEBUILD", "CODEBUILD_BUILD_ARN"],
15
- ["CODEFRESH", "CF_BUILD_ID"],
16
- ["DRONE"],
17
- ["DRONE", "DRONE_BUILD_EVENT"],
18
- ["DSARI"],
19
- ["GITHUB_ACTIONS"],
20
- ["GITLAB", "GITLAB_CI"],
21
- ["GITLAB", "CI_MERGE_REQUEST_ID"],
22
- ["GOCD", "GO_PIPELINE_LABEL"],
23
- ["LAYERCI"],
24
- ["HUDSON", "HUDSON_URL"],
25
- ["JENKINS", "JENKINS_URL"],
26
- ["MAGNUM"],
27
- ["NETLIFY"],
28
- ["NETLIFY", "NETLIFY_LOCAL", { ci: false }],
29
- ["NEVERCODE"],
30
- ["RENDER"],
31
- ["SAIL", "SAILCI"],
32
- ["SEMAPHORE"],
33
- ["SCREWDRIVER"],
34
- ["SHIPPABLE"],
35
- ["SOLANO", "TDDIUM"],
36
- ["STRIDER"],
37
- ["TEAMCITY", "TEAMCITY_VERSION"],
38
- ["TRAVIS"],
39
- ["VERCEL", "NOW_BUILDER"],
40
- ["APPCENTER", "APPCENTER_BUILD_ID"],
41
- ["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }],
42
- ["STACKBLITZ"],
43
- ["STORMKIT"],
44
- ["CLEAVR"]
45
- ];
46
- function detectProvider(env) {
47
- for (const provider of providers) {
48
- const envName = provider[1] || provider[0];
49
- if (env[envName]) {
50
- return {
51
- name: provider[0].toLowerCase(),
52
- ...provider[2]
53
- };
54
- }
55
- }
56
- if (env.SHELL && env.SHELL === "/bin/jsh") {
57
- return {
58
- name: "stackblitz",
59
- ci: false
60
- };
61
- }
62
- return {
63
- name: "",
64
- ci: false
65
- };
66
- }
67
-
68
- const processShim = typeof process !== "undefined" ? process : {};
69
- const envShim = processShim.env || {};
70
- const providerInfo = detectProvider(envShim);
71
- const nodeENV = typeof process !== "undefined" && process.env && process.env.NODE_ENV || "";
72
- const platform = processShim.platform;
73
- const provider = providerInfo.name;
74
- const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false;
75
- const hasTTY = toBoolean(processShim.stdout && processShim.stdout.isTTY);
76
- const hasWindow = typeof window !== "undefined";
77
- const isDebug = toBoolean(envShim.DEBUG);
78
- const isTest = nodeENV === "test" || toBoolean(envShim.TEST);
79
- const isProduction = nodeENV === "production";
80
- const isDevelopment = nodeENV === "dev" || nodeENV === "development";
81
- const isMinimal = toBoolean(envShim.MINIMAL) || isCI || isTest || !hasTTY;
82
- const isWindows = /^win/i.test(platform);
83
- const isLinux = /^linux/i.test(platform);
84
- const isMacOS = /^darwin/i.test(platform);
85
- function toBoolean(val) {
86
- return val ? val !== "false" : false;
87
- }
88
-
89
- export { hasTTY, hasWindow, isCI, isDebug, isDevelopment, isLinux, isMacOS, isMinimal, isProduction, isTest, isWindows, platform, provider };
1
+ const r=Object.create(null),t=e=>globalThis.process?.env||import.meta.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?r:globalThis),s=new Proxy(r,{get(e,o){return t()[o]??r[o]},has(e,o){const i=t();return o in i||o in r},set(e,o,i){const p=t(!0);return p[o]=i,!0},deleteProperty(e,o){if(!o)return!1;const i=t(!0);return delete i[o],!0},ownKeys(){const e=t(!0);return Object.keys(e)}}),E=typeof process<"u"&&process.env&&process.env.NODE_ENV||"",d=[["APPVEYOR"],["AZURE_PIPELINES","SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],["AZURE_STATIC","INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],["APPCIRCLE","AC_APPCIRCLE"],["BAMBOO","bamboo_planKey"],["BITBUCKET","BITBUCKET_COMMIT"],["BITRISE","BITRISE_IO"],["BUDDY","BUDDY_WORKSPACE_ID"],["BUILDKITE"],["CIRCLE","CIRCLECI"],["CIRRUS","CIRRUS_CI"],["CLOUDFLARE_PAGES","CF_PAGES",{ci:!0}],["CODEBUILD","CODEBUILD_BUILD_ARN"],["CODEFRESH","CF_BUILD_ID"],["DRONE"],["DRONE","DRONE_BUILD_EVENT"],["DSARI"],["GITHUB_ACTIONS"],["GITLAB","GITLAB_CI"],["GITLAB","CI_MERGE_REQUEST_ID"],["GOCD","GO_PIPELINE_LABEL"],["LAYERCI"],["HUDSON","HUDSON_URL"],["JENKINS","JENKINS_URL"],["MAGNUM"],["NETLIFY"],["NETLIFY","NETLIFY_LOCAL",{ci:!1}],["NEVERCODE"],["RENDER"],["SAIL","SAILCI"],["SEMAPHORE"],["SCREWDRIVER"],["SHIPPABLE"],["SOLANO","TDDIUM"],["STRIDER"],["TEAMCITY","TEAMCITY_VERSION"],["TRAVIS"],["VERCEL","NOW_BUILDER"],["VERCEL","VERCEL",{ci:!1}],["VERCEL","VERCEL_ENV",{ci:!1}],["APPCENTER","APPCENTER_BUILD_ID"],["CODESANDBOX","CODESANDBOX_SSE",{ci:!1}],["STACKBLITZ"],["STORMKIT"],["CLEAVR"]];function B(){if(globalThis.process?.env)for(const e of d){const o=e[1]||e[0];if(globalThis.process?.env[o])return{name:e[0].toLowerCase(),...e[2]}}return globalThis.process?.env?.SHELL==="/bin/jsh"&&globalThis.process?.versions?.webcontainer?{name:"stackblitz",ci:!1}:{name:"",ci:!1}}const I=B(),U=I.name;function n(e){return e?e!=="false":!1}const l=globalThis.process?.platform||"",T=n(s.CI)||I.ci!==!1,a=n(globalThis.process?.stdout&&globalThis.process?.stdout.isTTY),P=typeof window<"u",h=n(s.DEBUG),c=E==="test"||n(s.TEST),f=E==="production",v=E==="dev"||E==="development",m=n(s.MINIMAL)||T||c||!a,C=/^win/i.test(l),M=/^linux/i.test(l),V=/^darwin/i.test(l),y=!n(s.NO_COLOR)&&(n(s.FORCE_COLOR)||C&&s.TERM!=="dumb"||a&&s.TERM&&s.TERM==="dumb"||T),R=(globalThis.process?.versions?.node||"").replace(/^v/,"")||null,w=Number(R?.split(".")[0])||null,Y=globalThis.process||Object.create(null),L={versions:{}},G=new Proxy(Y,{get(e,o){if(o==="env")return s;if(o in e)return e[o];if(o in L)return L[o]}}),_=!!globalThis.Netlify,O=!!globalThis.EdgeRuntime,D=globalThis.navigator?.userAgent==="Cloudflare-Workers",A=!!globalThis.Deno,u=!!globalThis.__lagon__,N=globalThis.process?.release?.name==="node",S=!!globalThis.Bun||!!process.versions.bun,b=!!globalThis.fastly,K=[[_,"netlify"],[O,"edge-light"],[D,"workerd"],[A,"deno"],[u,"lagon"],[N,"node"],[S,"bun"],[b,"fastly"]];function F(){const e=K.find(o=>o[0]);if(e)return{name:e[1]}}const g=F(),W=g?.name||"";export{s as env,a as hasTTY,P as hasWindow,S as isBun,T as isCI,y as isColorSupported,h as isDebug,A as isDeno,v as isDevelopment,O as isEdgeLight,b as isFastly,u as isLagon,M as isLinux,V as isMacOS,m as isMinimal,_ as isNetlify,N as isNode,f as isProduction,c as isTest,C as isWindows,D as isWorkerd,E as nodeENV,w as nodeMajorVersion,R as nodeVersion,l as platform,G as process,U as provider,I as providerInfo,W as runtime,g as runtimeInfo};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "std-env",
3
- "version": "3.3.3",
4
- "description": "Detect current Javascript environment",
3
+ "version": "3.4.0",
4
+ "description": "Runtime agnostic JS utils",
5
5
  "repository": "unjs/std-env",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,
@@ -21,20 +21,24 @@
21
21
  "lint": "eslint --ext .ts . && prettier -c src test",
22
22
  "lint:fix": "eslint --fix --ext .ts . && prettier -w src test",
23
23
  "prepack": "unbuild",
24
+ "play:bun": "bun playground/bun.ts",
25
+ "play:deno": "pnpm build && deno run -A playground/deno.ts",
26
+ "play:node": "pnpm build && node playground/node.mjs",
24
27
  "release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
25
- "test": "pnpm lint && vitest run --coverage"
28
+ "test": "pnpm lint && pnpm typecheck && vitest run --coverage",
29
+ "typecheck": "tsc --noEmit"
26
30
  },
27
31
  "devDependencies": {
28
- "@types/node": "^18.16.3",
29
- "@vitest/coverage-c8": "^0.31.0",
30
- "changelogen": "^0.5.3",
31
- "eslint": "^8.39.0",
32
- "eslint-config-unjs": "^0.1.0",
33
- "jiti": "^1.18.2",
34
- "prettier": "^2.8.8",
35
- "typescript": "^5.0.4",
36
- "unbuild": "^1.2.1",
37
- "vitest": "^0.31.0"
32
+ "@types/node": "^20.5.0",
33
+ "@vitest/coverage-v8": "^0.34.2",
34
+ "changelogen": "^0.5.4",
35
+ "eslint": "^8.47.0",
36
+ "eslint-config-unjs": "^0.2.1",
37
+ "jiti": "^1.19.2",
38
+ "prettier": "^3.0.2",
39
+ "typescript": "^5.1.6",
40
+ "unbuild": "^2.0.0-rc.0",
41
+ "vitest": "^0.34.2"
38
42
  },
39
- "packageManager": "pnpm@8.4.0"
43
+ "packageManager": "pnpm@8.6.12"
40
44
  }