-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
63 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const _process: typeof process = | ||
typeof process === "undefined" ? ({} as typeof process) : process; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function toBoolean(val) { | ||
return val ? val !== "false" : false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { detectProvider, ProviderName } from "./providers"; | ||
import { env, nodeENV } from "./env"; | ||
import { toBoolean } from "./_utils"; | ||
import { _process } from "./_process"; | ||
|
||
const _providerInfo = detectProvider(env); | ||
|
||
/** Value of process.platform */ | ||
export const platform = _process.platform; | ||
|
||
/** Current provider name */ | ||
export const provider: ProviderName = _providerInfo.name; | ||
|
||
/** Detect if `CI` environment variable is set or a provider CI detected */ | ||
export const isCI = toBoolean(env.CI) || _providerInfo.ci !== false; | ||
|
||
/** Detect if stdout.TTY is available */ | ||
export const hasTTY = toBoolean(_process.stdout && _process.stdout.isTTY); | ||
|
||
/** Detect if global `window` object is available */ | ||
export const hasWindow = typeof window !== "undefined"; | ||
|
||
/** Detect if `DEBUG` environment variable is set */ | ||
export const isDebug = toBoolean(env.DEBUG); | ||
|
||
/** Detect if `NODE_ENV` environment variable is `test` */ | ||
export const isTest = nodeENV === "test" || toBoolean(env.TEST); | ||
|
||
/** Detect if `NODE_ENV` environment variable is `production` */ | ||
export const isProduction = nodeENV === "production"; | ||
|
||
/** Detect if `NODE_ENV` environment variable is `dev` or `development` */ | ||
export const isDevelopment = nodeENV === "dev" || nodeENV === "development"; | ||
|
||
/** Detect if MINIMAL environment variable is set, running in CI or test or TTY is unavailable */ | ||
export const isMinimal = toBoolean(env.MINIMAL) || isCI || isTest || !hasTTY; | ||
|
||
/** Detect if process.platform is Windows */ | ||
export const isWindows = /^win/i.test(platform); | ||
|
||
/** Detect if process.platform is Linux */ | ||
export const isLinux = /^linux/i.test(platform); | ||
|
||
/** Detect if process.platform is macOS (darwin kernel) */ | ||
export const isMacOS = /^darwin/i.test(platform); | ||
|
||
/** Color Support */ | ||
export const isColorSupported = | ||
!toBoolean(env.NO_COLOR) && | ||
(toBoolean(env.FORCE_COLOR) || | ||
(isWindows && !(env.TERM === "dumb")) || | ||
(hasTTY && env.TERM && !(env.TERM !== "dumb")) || | ||
isCI); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,3 @@ | ||
import { detectProvider, ProviderName } from "./providers"; | ||
import { env, nodeENV } from "./env"; | ||
export { env, nodeENV } from "./env"; | ||
|
||
export type { ProviderName, ProviderInfo } from "./providers"; | ||
|
||
const _process: typeof process = | ||
typeof process === "undefined" ? ({} as typeof process) : process; | ||
const envShim = _process.env || ({} as typeof process.env); | ||
const providerInfo = detectProvider(envShim); | ||
|
||
/** Value of process.platform */ | ||
export const platform = _process.platform; | ||
|
||
/** Current provider name */ | ||
export const provider: ProviderName = providerInfo.name; | ||
|
||
/** Detect if `CI` environment variable is set or a provider CI detected */ | ||
export const isCI = toBoolean(env.CI) || providerInfo.ci !== false; | ||
|
||
/** Detect if stdout.TTY is available */ | ||
export const hasTTY = toBoolean(_process.stdout && _process.stdout.isTTY); | ||
|
||
/** Detect if global `window` object is available */ | ||
export const hasWindow = typeof window !== "undefined"; | ||
|
||
/** Detect if `DEBUG` environment variable is set */ | ||
export const isDebug = toBoolean(env.DEBUG); | ||
|
||
/** Detect if `NODE_ENV` environment variable is `test` */ | ||
export const isTest = nodeENV === "test" || toBoolean(env.TEST); | ||
|
||
/** Detect if `NODE_ENV` environment variable is `production` */ | ||
export const isProduction = nodeENV === "production"; | ||
|
||
/** Detect if `NODE_ENV` environment variable is `dev` or `development` */ | ||
export const isDevelopment = nodeENV === "dev" || nodeENV === "development"; | ||
|
||
/** Detect if MINIMAL environment variable is set, running in CI or test or TTY is unavailable */ | ||
export const isMinimal = toBoolean(env.MINIMAL) || isCI || isTest || !hasTTY; | ||
|
||
/** Detect if process.platform is Windows */ | ||
export const isWindows = /^win/i.test(platform); | ||
|
||
/** Detect if process.platform is Linux */ | ||
export const isLinux = /^linux/i.test(platform); | ||
|
||
/** Detect if process.platform is macOS (darwin kernel) */ | ||
export const isMacOS = /^darwin/i.test(platform); | ||
|
||
/** Color Support */ | ||
export const isColorSupported = | ||
!toBoolean(env.NO_COLOR) && | ||
(toBoolean(env.FORCE_COLOR) || | ||
(isWindows && !(env.TERM === "dumb")) || | ||
(hasTTY && env.TERM && !(env.TERM !== "dumb")) || | ||
isCI); | ||
|
||
// -- Utils -- | ||
|
||
function toBoolean(val) { | ||
return val ? val !== "false" : false; | ||
} | ||
export * from "./providers"; | ||
export * from "./env"; | ||
export * from "./flags"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters