From 0d7b84f61d08f53f72b1cdd2eb4165e26b2e7302 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 9 Aug 2023 12:12:42 +0200 Subject: [PATCH] perf: reduce dependency on `process` proxy for flags --- src/flags.ts | 6 +++--- src/process.ts | 2 +- test/index.test.ts | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/flags.ts b/src/flags.ts index fb82ece..d099286 100644 --- a/src/flags.ts +++ b/src/flags.ts @@ -1,10 +1,10 @@ import { detectProvider, ProviderName } from "./providers"; import { env, nodeENV } from "./env"; import { toBoolean } from "./_utils"; -import { process } from "./process"; +import { _process } from "./process"; /** Value of process.platform */ -export const platform = process.platform || ""; +export const platform = _process.platform || ""; /** Current provider info */ export const providerInfo = detectProvider(env); @@ -14,7 +14,7 @@ export const provider: ProviderName = providerInfo.name; export const isCI = toBoolean(env.CI) || providerInfo.ci !== false; /** Detect if stdout.TTY is available */ -export const hasTTY = toBoolean(process.stdout && process.stdout.isTTY); +export const hasTTY = toBoolean(_process.stdout && _process.stdout.isTTY); /** Detect if global `window` object is available */ export const hasWindow = typeof window !== "undefined"; diff --git a/src/process.ts b/src/process.ts index 7da7deb..2500793 100644 --- a/src/process.ts +++ b/src/process.ts @@ -6,7 +6,7 @@ export interface Process versions: Record; } -const _process = (globalThis.process || +export const _process = (globalThis.process || Object.create(null)) as unknown as Process; const processShims: Partial = { diff --git a/test/index.test.ts b/test/index.test.ts index df21f8c..2f7c499 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -22,6 +22,7 @@ describe("std-env", () => { "isLinux", "isMacOS", "isColorSupported", + "_process", "process", "detectProvider", ]