Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/cli-kit/src/public/node/context/local.ts
Comment thread
gonzaloriestra marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ export function homeDirectory(): string {
return homedir()
}

/**
* Memoized value for the verbose check.
*/
let memoizedIsVerbose: boolean | undefined
Comment thread
gonzaloriestra marked this conversation as resolved.

/**
* Memoized value for the unit test check.
*/
let memoizedIsUnitTest: boolean | undefined

/**
* Returns true if the CLI is running in debug mode.
*
Expand All @@ -51,6 +61,11 @@ export function isDevelopment(env = process.env): boolean {
* @returns True if SHOPIFY_FLAG_VERBOSE is truthy or the flag --verbose has been passed.
*/
export function isVerbose(env = process.env): boolean {
if (env === process.env) {
// Memoize the result to avoid repeated scans of process.argv and env lookups
// in high-frequency paths like outputDebug.
return (memoizedIsVerbose ??= isTruthy(env[environmentVariables.verbose]) || process.argv.includes('--verbose'))
Comment thread
gonzaloriestra marked this conversation as resolved.
}
return isTruthy(env[environmentVariables.verbose]) || process.argv.includes('--verbose')
}

Expand Down Expand Up @@ -88,6 +103,11 @@ export async function isShopify(env = process.env): Promise<boolean> {
* @returns True if the SHOPIFY_UNIT_TEST environment variable is truthy.
*/
export function isUnitTest(env = process.env): boolean {
if (env === process.env) {
// Memoize the result as SHOPIFY_UNIT_TEST is static during execution
// and checked frequently to suppress output.
return (memoizedIsUnitTest ??= isTruthy(env[environmentVariables.unitTest]))
}
return isTruthy(env[environmentVariables.unitTest])
}

Expand Down
Loading