@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
57 lines • 2.19 kB
JavaScript
import { captureOutput } from '../node/system.js';
import which from 'which';
import { satisfies } from 'semver';
/**
* Returns the version of the local dependency of the CLI if it's installed in the provided directory.
*
* @param directory - Path of the project to look for the dependency.
* @returns The CLI version or undefined if the dependency is not installed.
*/
export async function localCLIVersion(directory) {
try {
const output = await captureOutput('npm', ['list', '@shopify/cli'], { cwd: directory });
return output.match(/@shopify\/cli@([\w.-]*)/)?.[1];
// eslint-disable-next-line no-catch-all/no-catch-all
}
catch {
return undefined;
}
}
/**
* Returns the version of the globally installed CLI, only if it's greater than 3.59.0 (when the global CLI was introduced).
*
* @returns The version of the CLI if it is globally installed or undefined.
*/
export async function globalCLIVersion() {
try {
const env = { ...process.env, SHOPIFY_CLI_NO_ANALYTICS: '1' };
// Both execa and which find the project dependency. We need to exclude it.
const shopifyBinaries = which.sync('shopify', { all: true }).filter((path) => !path.includes('node_modules'));
if (!shopifyBinaries[0])
return undefined;
const output = await captureOutput(shopifyBinaries[0], [], { env });
const versionMatch = output.match(/@shopify\/cli\/([^\s]+)/);
if (versionMatch && versionMatch[1]) {
const version = versionMatch[1];
if (satisfies(version, `>=3.59.0`) || isPreReleaseVersion(version)) {
return version;
}
}
return undefined;
// eslint-disable-next-line no-catch-all/no-catch-all
}
catch {
return undefined;
}
}
/**
* Returns true if the given version is a pre-release version.
* Meaning is a `nightly`, `snapshot`, or `experimental` version.
*
* @param version - The version to check.
* @returns True if the version is a pre-release version.
*/
export function isPreReleaseVersion(version) {
return version.startsWith('0.0.0');
}
//# sourceMappingURL=version.js.map