@shopify/create-app
Version:
A CLI tool to create a new Shopify app.
201 lines (198 loc) • 8.04 kB
JavaScript
import {
fetchNotifications,
filterNotifications
} from "./chunk-FU4STSWX.js";
import "./chunk-B7LXQVGX.js";
import "./chunk-MSED5ZFM.js";
import {
CLI_KIT_VERSION
} from "./chunk-HHKEZAAX.js";
import "./chunk-G53O4PDO.js";
import {
isPreReleaseVersion
} from "./chunk-XYNOPL42.js";
import {
addNPMDependencies,
checkForCachedNewVersion,
checkForNewVersion,
findUpAndReadPackageJson,
getPackageManager,
usesWorkspaces
} from "./chunk-ZPNNBR5Z.js";
import {
getAutoUpgradeEnabled,
runAtMinimumInterval,
setAutoUpgradeEnabled
} from "./chunk-5LLHAM5N.js";
import {
exec,
isCI,
renderSuccess
} from "./chunk-TGZSJFOF.js";
import "./chunk-JMC4PKOZ.js";
import "./chunk-YYJ6EVI6.js";
import "./chunk-LEQAULOW.js";
import "./chunk-CM6ALOD7.js";
import "./chunk-E43EDJOG.js";
import "./chunk-ODCXYGJ2.js";
import "./chunk-LBXDGVFS.js";
import "./chunk-JGGOQOPO.js";
import "./chunk-OQ3KXXGH.js";
import "./chunk-VJHCFG5K.js";
import {
currentProcessIsGlobal,
getProjectDir,
inferPackageManagerForGlobalCLI,
outputContent,
outputDebug,
outputInfo,
outputToken,
outputWarn
} from "./chunk-PK2M5CKS.js";
import {
isDevelopment
} from "./chunk-X2X377NR.js";
import "./chunk-7OHJH7BF.js";
import "./chunk-HNIAZN6U.js";
import {
cwd,
moduleDirectory,
sniffForPath
} from "./chunk-C3J4HVUN.js";
import "./chunk-UFLX7QDP.js";
import "./chunk-SI4LHZYW.js";
import "./chunk-D6NYWNY2.js";
import {
init_cjs_shims
} from "./chunk-3XNI6LP4.js";
// ../cli-kit/dist/public/node/upgrade.js
init_cjs_shims();
function cliInstallCommand() {
let packageManager = inferPackageManagerForGlobalCLI();
if (!(!packageManager || packageManager === "unknown"))
return packageManager === "homebrew" ? "brew upgrade shopify-cli" : packageManager === "yarn" ? `${packageManager} global add @shopify/cli@latest` : `${packageManager} ${packageManager === "pnpm" ? "add" : "install"} -g @shopify/cli@latest`;
}
async function runCLIUpgrade(options = {}) {
let path = sniffForPath() ?? cwd(), projectDir = getProjectDir(path), isGlobal = currentProcessIsGlobal();
if (isDevelopment()) {
outputInfo("Skipping upgrade in development mode.");
return;
}
if (!(options.autoupgrade && !isGlobal))
if (isGlobal) {
let installCommand = cliInstallCommand();
if (!installCommand)
throw new Error("Could not determine the package manager");
let [command, ...args] = installCommand.split(" ");
if (!command)
throw new Error("Could not determine the command to run");
let newerVersion = checkForCachedNewVersion("@shopify/cli", CLI_KIT_VERSION), headline = newerVersion ? `\u2728 New version of Shopify CLI available! (${CLI_KIT_VERSION} \u2192 ${newerVersion})` : "\u2728 New version of Shopify CLI available!";
outputInfo(outputContent`${headline}
Now upgrading by running: ${outputToken.genericShellCommand(installCommand)}...`), await exec(command, args, { stdio: "inherit" }), renderSuccess({
headline: "Shopify CLI upgraded.",
body: newerVersion ? `You're now on version ${newerVersion}.` : "You're now on the latest version."
});
} else if (projectDir)
await upgradeLocalShopify(projectDir, CLI_KIT_VERSION);
else
throw new Error("Could not determine the local project directory");
}
function versionToAutoUpgrade() {
let currentVersion = CLI_KIT_VERSION, newerVersion = checkForCachedNewVersion("@shopify/cli", currentVersion);
if (!newerVersion) {
outputDebug("Auto-upgrade: No newer version available.");
return;
}
if (process.env.SHOPIFY_CLI_FORCE_AUTO_UPGRADE === "1")
return outputDebug("Auto-upgrade: Forcing auto-upgrade because of SHOPIFY_CLI_FORCE_AUTO_UPGRADE."), newerVersion;
if (!getAutoUpgradeEnabled()) {
outputDebug("Auto-upgrade: Skipping because auto-upgrade is not enabled.");
return;
}
if (isCI()) {
outputDebug("Auto-upgrade: Skipping auto-upgrade in CI.");
return;
}
if (isPreReleaseVersion(currentVersion)) {
outputDebug("Auto-upgrade: Skipping auto-upgrade for pre-release version.");
return;
}
return newerVersion;
}
async function hasBlockingAutoUpgradeNotification() {
try {
let { notifications } = await fetchNotifications();
return filterNotifications(notifications, "", ["autoupgrade"]).some((notification) => notification.type === "error");
} catch {
return !1;
}
}
async function warnIfUpgradeAvailable() {
if (isCI() || isPreReleaseVersion(CLI_KIT_VERSION) || getAutoUpgradeEnabled())
return;
let newerVersion = checkForCachedNewVersion("@shopify/cli", CLI_KIT_VERSION);
newerVersion && await runAtMinimumInterval("warn-on-available-upgrade", { days: 1 }, async () => {
outputWarn(getOutputUpdateCLIReminder(newerVersion));
});
}
function getOutputUpdateCLIReminder(version, isMajor = !1) {
let installCommand = cliInstallCommand(), base = installCommand ? outputContent`💡 Version ${version} available! Run ${outputToken.genericShellCommand(installCommand)}`.value : outputContent`💡 Version ${version} available!`.value;
if (isMajor) {
let releaseUrl = `https://github.com/Shopify/cli/releases/tag/${version}`, majorNotice = outputContent`⚠️ This is a major version — review breaking changes before upgrading:\n ${outputToken.link(releaseUrl, releaseUrl)}`.value;
return `${base}
${majorNotice}`;
}
return base;
}
async function upgradeLocalShopify(projectDir, currentVersion) {
let packageJson = (await findUpAndReadPackageJson(projectDir)).content, packageJsonDependencies = packageJson.dependencies ?? {}, packageJsonDevDependencies = packageJson.devDependencies ?? {}, resolvedCLIVersion = { ...packageJsonDependencies, ...packageJsonDevDependencies }[await cliDependency()];
if (!resolvedCLIVersion) {
outputDebug("Auto-upgrade: CLI dependency not found in project dependencies, skipping local upgrade.");
return;
}
resolvedCLIVersion.slice(0, 1).match(/[\^~]/) && (resolvedCLIVersion = currentVersion);
let newestCLIVersion = await checkForNewVersion(await cliDependency(), resolvedCLIVersion);
newestCLIVersion ? outputUpgradeMessage(resolvedCLIVersion, newestCLIVersion) : outputWontInstallMessage(resolvedCLIVersion), await installJsonDependencies("prod", packageJsonDependencies, projectDir), await installJsonDependencies("dev", packageJsonDevDependencies, projectDir);
}
async function installJsonDependencies(depsEnv, deps, directory) {
let packagesToUpdate = [await cliDependency(), ...await oclifPlugins()].filter((pkg) => !!deps[pkg]).map((pkg) => ({ name: pkg, version: "latest" })), appUsesWorkspaces = await usesWorkspaces(directory);
packagesToUpdate.length > 0 && await addNPMDependencies(packagesToUpdate, {
packageManager: await getPackageManager(directory),
type: depsEnv,
directory,
stdout: process.stdout,
stderr: process.stderr,
addToRootDirectory: appUsesWorkspaces
});
}
async function cliDependency() {
return (await packageJsonContents()).name;
}
async function oclifPlugins() {
return (await packageJsonContents())?.oclif?.plugins ?? [];
}
var _packageJsonContents;
async function packageJsonContents() {
if (!_packageJsonContents) {
let packageJson = await findUpAndReadPackageJson(moduleDirectory(import.meta.url));
_packageJsonContents = _packageJsonContents ?? packageJson.content;
}
return _packageJsonContents;
}
function outputWontInstallMessage(currentVersion) {
outputInfo(outputContent`You're on the latest version, ${outputToken.yellow(currentVersion)}, no need to upgrade!`);
}
function outputUpgradeMessage(currentVersion, newestVersion) {
outputInfo(outputContent`Upgrading CLI from ${outputToken.yellow(currentVersion)} to ${outputToken.yellow(newestVersion)}...`);
}
export {
cliInstallCommand,
getAutoUpgradeEnabled,
getOutputUpdateCLIReminder,
hasBlockingAutoUpgradeNotification,
runCLIUpgrade,
setAutoUpgradeEnabled,
versionToAutoUpgrade,
warnIfUpgradeAvailable
};
//# sourceMappingURL=upgrade-QE6OI6PW.js.map