Skip to content
Open
Show file tree
Hide file tree
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
Empty file added .jules/bolt.md
Empty file.
19 changes: 19 additions & 0 deletions packages/cli-kit/src/public/node/context/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export function homeDirectory(): string {
return homedir()
}

/**
* Memoized values for environment checks.
* These are only used when the functions are called with `process.env` to ensure
* consistency and performance in hot paths (like logging) while maintaining
* test isolation when custom environment objects are provided.
*/
let memoizedIsVerbose: boolean | undefined
let memoizedIsUnitTest: boolean | undefined

/**
* Returns true if the CLI is running in debug mode.
*
Expand All @@ -51,6 +60,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'))
}
return isTruthy(env[environmentVariables.verbose]) || process.argv.includes('--verbose')
}

Expand Down Expand Up @@ -88,6 +102,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