Skip to content
Draft
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
25 changes: 21 additions & 4 deletions packages/cli-kit/src/public/node/context/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export function isVerbose(env = process.env): boolean {
return isTruthy(env[environmentVariables.verbose]) || process.argv.includes('--verbose')
}

/**
* Memoized value for the Shopify environment check.
*/
let memoizedIsShopify: Promise<boolean> | undefined

/**
* Returns true if the environment in which the CLI is running is either
* a local environment (where dev is present).
Expand All @@ -62,11 +67,23 @@ export function isVerbose(env = process.env): boolean {
* @returns True if the CLI is used in a Shopify environment.
*/
export async function isShopify(env = process.env): Promise<boolean> {
if (Object.prototype.hasOwnProperty.call(env, environmentVariables.runAsUser)) {
return !isTruthy(env[environmentVariables.runAsUser])
if (env === process.env && memoizedIsShopify !== undefined && !isUnitTest()) {
return memoizedIsShopify
}

const resultPromise = (async () => {
if (Object.prototype.hasOwnProperty.call(env, environmentVariables.runAsUser)) {
return !isTruthy(env[environmentVariables.runAsUser])
}
const devInstalled = await lazyFileExists(pathConstants.executables.dev)
return devInstalled
})()

if (env === process.env && !isUnitTest()) {
memoizedIsShopify = resultPromise
}
const devInstalled = await lazyFileExists(pathConstants.executables.dev)
return devInstalled

return resultPromise
}

/**
Expand Down
Loading