import {
  base_command_default
} from "./chunk-LUHAPAT6.js";
import {
  cacheClear
} from "./chunk-HJBER2P6.js";
import {
  isTruthy,
  printEventsJson
} from "./chunk-LA4HX5WI.js";
import {
  require_lib
} from "./chunk-CBD6UXLA.js";
import {
  __toESM,
  init_cjs_shims
} from "./chunk-POZ5MGPT.js";

// src/cli/commands/cache/clear.ts
init_cjs_shims();

// ../cli-kit/dist/public/node/cli.js
init_cjs_shims();
var import_core = __toESM(require_lib());
import { fileURLToPath } from "url";
async function warnIfOldNodeVersion() {
  let nodeVersion = process.versions.node, nodeMajorVersion = Number(nodeVersion.split(".")[0]);
  if (nodeMajorVersion < 18) {
    let { renderWarning } = await import("./ui-RBOM3GUL.js");
    renderWarning({
      headline: "Upgrade to a supported Node version now.",
      body: [
        `Node ${nodeMajorVersion} has reached end-of-life and poses security risks. When you upgrade to a`,
        {
          link: {
            url: "https://nodejs.dev/en/about/previous-releases",
            label: "supported version"
          }
        },
        { char: "," },
        "you'll be able to use Shopify CLI without interruption."
      ]
    });
  }
}
function setupEnvironmentVariables(options) {
  process.argv.includes("--verbose") && (process.env.DEBUG = process.env.DEBUG ?? "*"), options.development && (process.env.SHOPIFY_CLI_ENV = process.env.SHOPIFY_CLI_ENV ?? "development");
}
function forceNoColor() {
  (process.argv.includes("--no-color") || isTruthy(process.env.NO_COLOR) || isTruthy(process.env.SHOPIFY_FLAG_NO_COLOR) || process.env.TERM === "dumb") && (process.env.FORCE_COLOR = "0");
}
async function runCLI(options) {
  setupEnvironmentVariables(options), forceNoColor(), await warnIfOldNodeVersion();
  let { errorHandler } = await import("./error-handler-5SBVAGLO.js"), { isDevelopment } = await import("./local-B3EZUKZU.js"), oclif = await import("./lib-JJXX7GH6.js"), { ShopifyConfig } = await import("./custom-oclif-loader-IEXPGBA7.js");
  isDevelopment() && (oclif.default.settings.debug = !0);
  try {
    let config = new ShopifyConfig({ root: fileURLToPath(options.moduleURL) });
    await config.load(), await oclif.default.run(void 0, config), await oclif.default.flush(), printEventsJson();
  } catch (error) {
    return await errorHandler(error), oclif.default.Errors.handle(error);
  }
}
async function useLocalCLIIfDetected(filepath) {
  let { environmentVariables } = await import("./constants-QFFDI47A.js"), { joinPath: join } = await import("./path-T2RCZTRE.js"), { exec } = await import("./system-NFPBQV3H.js");
  if (!isTruthy(process.env[environmentVariables.enableCliRedirect]) || isTruthy(process.env[environmentVariables.skipCliRedirect]) || process.env.npm_config_user_agent)
    return !1;
  let cliPackage = await localCliPackage();
  if (!cliPackage)
    return !1;
  let correctExecutablePath = join(cliPackage.path, cliPackage.bin.shopify);
  if (correctExecutablePath === filepath)
    return !1;
  try {
    await exec(correctExecutablePath, process.argv.slice(2, process.argv.length), {
      stdio: "inherit",
      env: { [environmentVariables.skipCliRedirect]: "1" }
    });
  } catch (processError) {
    process.exit(processError.exitCode);
  }
  return !0;
}
async function localCliPackage() {
  let { captureOutput } = await import("./system-NFPBQV3H.js"), npmListOutput = "", localShopifyCLI = {};
  try {
    npmListOutput = await captureOutput("npm", ["list", "@shopify/cli", "--json", "-l"]), localShopifyCLI = JSON.parse(npmListOutput);
  } catch {
    return;
  }
  return {
    ...localShopifyCLI.peerDependencies,
    ...localShopifyCLI.devDependencies,
    ...localShopifyCLI.dependencies
  }["@shopify/cli"];
}
var globalFlags = {
  "no-color": import_core.Flags.boolean({
    hidden: !1,
    description: "Disable color output.",
    env: "SHOPIFY_FLAG_NO_COLOR"
  }),
  verbose: import_core.Flags.boolean({
    hidden: !1,
    description: "Increase the verbosity of the output.",
    env: "SHOPIFY_FLAG_VERBOSE"
  })
};
function clearCache() {
  cacheClear();
}

// src/cli/commands/cache/clear.ts
var ClearCache = class extends base_command_default {
  static {
    this.description = "Clear the CLI cache, used to store some API responses and handle notifications status";
  }
  static {
    this.hidden = !0;
  }
  async run() {
    clearCache();
  }
};

export {
  runCLI,
  useLocalCLIIfDetected,
  globalFlags,
  ClearCache
};
//# sourceMappingURL=chunk-55CSCYE5.js.map
