// src/actions/lint-init.ts
import {
  existsSync as existsSync3,
  readFileSync as readFileSync4,
  unlinkSync,
  writeFileSync
} from "node:fs";
import PATH5 from "node:path";
import { createInterface } from "node:readline";
import chalk4 from "chalk";

// src/lib/crossSpawn.ts
import crossSpawn from "cross-spawn";
function spawnSync(command, args, options) {
  return crossSpawn.sync(command, args, options);
}

// src/lib/packageManagerRuntime.ts
import fs from "node:fs";
import chalk from "chalk";
var DISPLAY_NAMES = {
  bun: "Bun",
  npm: "npm",
  pnpm: "pnpm",
  yarn: "Yarn"
};
var MAC_INSTALL_COMMANDS = {
  bun: "brew install oven-sh/bun/bun",
  npm: "brew install node",
  pnpm: "brew install pnpm",
  yarn: "brew install yarn"
};
var SUPPORTED_PLATFORMS = ["darwin", "linux", "win32"];
function currentPlatform() {
  return SUPPORTED_PLATFORMS.find((platform) => platform === process.platform) ?? "unknown";
}
function shouldAskYesNo(question) {
  if (!process.stdin.isTTY || !process.stdout.isTTY) {
    return false;
  }
  process.stdout.write(question);
  const buffer = Buffer.alloc(1024);
  const bytesRead = fs.readSync(process.stdin.fd, buffer, 0, buffer.length, null);
  const answer = buffer.toString("utf8", 0, bytesRead).trim().toLowerCase();
  return answer === "y" || answer === "yes";
}
function isCommandInstalled(command) {
  const result = spawnSync(command, ["--version"], {
    encoding: "utf8",
    stdio: "ignore"
  });
  return !result.error && result.status === 0;
}
function isPackageManagerInstalled(pm) {
  return isCommandInstalled(pm);
}
function getPackageManagerInstallPlan(pm, platform = currentPlatform()) {
  const displayName = DISPLAY_NAMES[pm];
  if (platform === "darwin") {
    const command = MAC_INSTALL_COMMANDS[pm];
    return {
      command,
      manualInstructions: [
        `Install ${displayName} with: ${command}`
      ],
      packageManager: pm,
      platform,
      supported: true
    };
  }
  if (platform === "linux") {
    return {
      manualInstructions: [
        `Automatic installation for ${displayName} is not implemented on Linux yet.`,
        `Install ${displayName} manually and re-run the command.`
      ],
      packageManager: pm,
      platform,
      supported: false
    };
  }
  if (platform === "win32") {
    return {
      manualInstructions: [
        `Automatic installation for ${displayName} is not implemented on Windows yet.`,
        `Install ${displayName} manually and re-run the command.`
      ],
      packageManager: pm,
      platform,
      supported: false
    };
  }
  return {
    manualInstructions: [
      `Automatic installation for ${displayName} is not implemented on ${platform} yet.`,
      `Install ${displayName} manually and re-run the command.`
    ],
    packageManager: pm,
    platform,
    supported: false
  };
}
function printManualInstructions(plan, context) {
  console.error(chalk.yellow(`${DISPLAY_NAMES[plan.packageManager]} is required for "${context.operation}".`));
  for (const line of plan.manualInstructions) {
    console.error(chalk.gray(`  ${line}`));
  }
}
function shouldInstallWithHomebrew(pm, cwd) {
  const command = MAC_INSTALL_COMMANDS[pm];
  const result = spawnSync("brew", command.replace("brew ", "").split(" "), {
    cwd,
    encoding: "utf8",
    stdio: "inherit"
  });
  return result.status === 0;
}
function didEnsurePackageManagerInstalled(pm, context) {
  if (isPackageManagerInstalled(pm)) return true;
  const plan = getPackageManagerInstallPlan(pm, context.platform ?? currentPlatform());
  const displayName = DISPLAY_NAMES[pm];
  console.error(chalk.yellow(`${context.operation} requires ${displayName}, but it is not installed.`));
  if (!plan.supported) {
    printManualInstructions(plan, context);
    return false;
  }
  if (!isCommandInstalled("brew")) {
    console.error(chalk.yellow("Homebrew is not installed, so automatic installation is unavailable."));
    console.error(chalk.gray("  Install Homebrew from https://brew.sh and then run:"));
    console.error(chalk.gray(`  ${plan.command}`));
    return false;
  }
  const isConfirmed = shouldAskYesNo(chalk.cyan(`Install ${displayName} with Homebrew now? [y/N] `));
  if (!isConfirmed) {
    console.error(chalk.gray(`Skipping install. Run "${plan.command}" manually and then retry.`));
    return false;
  }
  console.error(chalk.cyan(`Installing ${displayName} via Homebrew...
`));
  if (!shouldInstallWithHomebrew(pm, context.cwd)) {
    console.error(chalk.red(`Homebrew failed to install ${displayName}.`));
    console.error(chalk.gray(`Run "${plan.command}" manually and then retry.`));
    return false;
  }
  if (!isPackageManagerInstalled(pm)) {
    console.error(chalk.red(`${displayName} still does not appear to be installed after Homebrew completed.`));
    console.error(chalk.gray(`Run "${plan.command}" manually and then retry.`));
    return false;
  }
  console.error(chalk.green(`${displayName} installed successfully.`));
  return true;
}
function failureResult() {
  return {
    output: ["", ""],
    pid: 0,
    signal: null,
    status: 1,
    stderr: "",
    stdout: ""
  };
}
function spawnPackageManagerSync(pm, args, options) {
  if (!didEnsurePackageManagerInstalled(pm, options.context)) {
    return failureResult();
  }
  return spawnSync(pm, args, { encoding: "utf8", ...options });
}

// src/pm/workspaces.ts
import { existsSync, readFileSync } from "node:fs";
import PATH from "node:path";
import { globSync } from "glob";
function readJsonFile(path2) {
  if (!existsSync(path2)) return void 0;
  try {
    return JSON.parse(readFileSync(path2, "utf8"));
  } catch {
    return void 0;
  }
}
function readRootPackageJson(cwd = process.cwd()) {
  return readJsonFile(PATH.resolve(cwd, "package.json"));
}
function detectPackageManagerFromPackageJson(cwd = process.cwd()) {
  const packageManager = readRootPackageJson(cwd)?.packageManager;
  if (!(packageManager != null && packageManager.length > 0)) return void 0;
  return packageManager.split("@", 1)[0];
}

// src/pm/detectPackageManager.ts
import { existsSync as existsSync2 } from "node:fs";
var knownPackageManagers = /* @__PURE__ */ new Set(["bun", "npm", "pnpm", "yarn"]);
function detectPackageManager() {
  const packageManager = detectPackageManagerFromPackageJson();
  if (packageManager != null && packageManager.length > 0 && knownPackageManagers.has(packageManager)) {
    return packageManager;
  }
  if (existsSync2("pnpm-lock.yaml") || existsSync2("pnpm-workspace.yaml")) return "pnpm";
  if (existsSync2("bun.lock") || existsSync2("bun.lockb")) return "bun";
  if (existsSync2("yarn.lock") || existsSync2(".yarnrc.yml")) return "yarn";
  if (existsSync2("package-lock.json") || existsSync2("npm-shrinkwrap.json")) return "npm";
  return "yarn";
}

// src/pm/isReactProject.ts
import { readFileSync as readFileSync2 } from "node:fs";
import PATH2 from "node:path";
import chalk2 from "chalk";
import { globSync as globSync2 } from "glob";
function hasReactDependency(packageJsonPath) {
  try {
    const content = readFileSync2(packageJsonPath, "utf8");
    const pkg = JSON.parse(content);
    const allDeps = {
      ...pkg.dependencies,
      ...pkg.devDependencies,
      ...pkg.peerDependencies
    };
    return Object.hasOwn(allDeps, "react") || Object.hasOwn(allDeps, "react-dom");
  } catch {
    return false;
  }
}
function isReactInMonorepo(cwd, isVerbose) {
  const rootPkgPath = PATH2.resolve(cwd, "package.json");
  if (hasReactDependency(rootPkgPath)) {
    if (isVerbose === true) console.log(chalk2.gray("  React detected in package.json"));
    return true;
  }
  const packageJsonPaths = globSync2("packages/**/package.json", {
    cwd,
    ignore: ["**/node_modules/**"]
  });
  for (const relPath of packageJsonPaths) {
    const fullPath = PATH2.resolve(cwd, relPath);
    if (hasReactDependency(fullPath)) {
      if (isVerbose === true) console.log(chalk2.gray(`  React detected in ${relPath}`));
      return true;
    }
  }
  return false;
}

// src/lib/toolchainVersion.ts
import { readFileSync as readFileSync3 } from "node:fs";
import { createRequire } from "node:module";
var require2 = createRequire(import.meta.url);
function bundledToolchainVersion() {
  const pkgPath = require2.resolve("@xylabs/toolchain/package.json");
  const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
  if (!(pkg.version != null && pkg.version.length > 0)) throw new Error("Could not read @xylabs/toolchain version");
  return pkg.version;
}
function bundledToolchainRange() {
  return `^${bundledToolchainVersion()}`;
}

// src/lib/initCwd.ts
function INIT_CWD() {
  return process.env.INIT_CWD ?? process.cwd();
}

// src/lib/shouldRunInstall.ts
import chalk3 from "chalk";
function shouldRunInstall(cwd) {
  const pm = detectPackageManager();
  console.log(chalk3.gray(`Running ${pm} install...`));
  const result = spawnPackageManagerSync(pm, ["install"], {
    context: { cwd, operation: `Run ${pm} install` },
    cwd,
    encoding: "utf8",
    stdio: "inherit"
  });
  if (result.status !== 0) {
    console.warn(chalk3.yellow(`${pm} install failed`));
    return false;
  }
  console.log(chalk3.green("Dependencies installed"));
  return true;
}

// src/actions/dead/runtimeEntries.ts
import fs2 from "node:fs";
import path from "node:path";
var codeExtensionRe = /\.(?:ts|tsx|mts|cts|js|mjs|cjs)$/i;
var resolutionExtensions = [".mjs", ".cjs", ".js", ".d.mts", ".d.cts", ".d.ts", ".mts", ".cts", ".ts", ".tsx"];
function readPackageManifest(location) {
  try {
    return JSON.parse(fs2.readFileSync(path.join(location, "package.json"), "utf8"));
  } catch {
    return void 0;
  }
}
function collectExportTargets(value) {
  if (typeof value === "string") return value.startsWith("./") ? [value] : [];
  if (Array.isArray(value)) return value.flatMap(collectExportTargets);
  if (typeof value !== "object" || value === null) return [];
  return Object.values(value).flatMap(collectExportTargets);
}
function resolveCodeFile(filePath) {
  if (fs2.existsSync(filePath) && codeExtensionRe.test(filePath)) return filePath;
  const ext = path.extname(filePath);
  if (ext) {
    const withoutExt = filePath.slice(0, -ext.length);
    for (const candidateExt of resolutionExtensions) {
      const candidate = `${withoutExt}${candidateExt}`;
      if (fs2.existsSync(candidate)) return candidate;
    }
  }
  for (const candidateExt of resolutionExtensions) {
    const candidate = `${filePath}${candidateExt}`;
    if (fs2.existsSync(candidate)) return candidate;
  }
  for (const candidateExt of resolutionExtensions) {
    const candidate = path.join(filePath, `index${candidateExt}`);
    if (fs2.existsSync(candidate)) return candidate;
  }
  return void 0;
}
function resolveManifestEntry(location, entry) {
  if (path.isAbsolute(entry)) return void 0;
  if (entry.includes("*")) return void 0;
  const relativeEntry = entry.startsWith(".") ? entry : `./${entry}`;
  return resolveCodeFile(path.resolve(location, relativeEntry));
}
function getRuntimeRootFiles(location, manifest) {
  if (!manifest) return [];
  const candidates = [
    ...collectExportTargets(manifest.exports),
    manifest.main,
    manifest.module,
    manifest.types,
    manifest.typings
  ].filter((entry) => typeof entry === "string");
  const bin = manifest.bin;
  if (bin !== void 0) {
    if (typeof bin === "string") candidates.push(bin);
    else for (const value of Object.values(bin)) if (typeof value === "string") candidates.push(value);
  }
  const seen = /* @__PURE__ */ new Set();
  const results = [];
  for (const entry of candidates) {
    const resolved = resolveManifestEntry(location, entry);
    if (!(resolved != null && resolved.length > 0) || seen.has(resolved)) continue;
    const distMapped = mapDistToSrc(location, resolved);
    const final = distMapped ?? resolved;
    if (seen.has(final)) continue;
    seen.add(final);
    results.push(final);
  }
  return results;
}
function mapDistToSrc(location, file) {
  const rel = path.relative(location, file);
  if (!rel.startsWith("dist" + path.sep) && !rel.startsWith("dist/")) return void 0;
  const tail = rel.slice("dist".length).replace(/^[\\/]/, "");
  const tailNoExt = tail.replace(/\.(?:mjs|cjs|js|d\.mts|d\.cts|d\.ts)$/i, "");
  const candidates = [
    path.join(location, "src", tailNoExt),
    path.join(location, "src", tailNoExt + ".ts"),
    path.join(location, "src", tailNoExt + ".tsx"),
    path.join(location, "src", tailNoExt + ".mts"),
    path.join(location, "src", tailNoExt + ".cts")
  ];
  for (const candidate of candidates) {
    const resolved = resolveCodeFile(candidate);
    if (resolved != null && resolved.length > 0) return resolved;
  }
  return void 0;
}

// src/actions/barrel/getReExportSpecs.ts
import fs3 from "node:fs";
import PATH3 from "node:path";
import ts from "typescript";

// src/actions/deplint/getBasePackageName.ts
function getBasePackageName(importName) {
  const importNameScrubbed = importName.replaceAll('"', "").trim();
  if (importNameScrubbed.startsWith("@")) {
    const parts = importNameScrubbed.split("/");
    return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : importNameScrubbed;
  }
  return importNameScrubbed.split("/", 1)[0];
}

// src/actions/barrel/getReExportSpecs.ts
function getReExportSpecs(file) {
  let sourceText;
  try {
    sourceText = fs3.readFileSync(file, "utf8");
  } catch {
    return [];
  }
  const isJsLike = /\.(?:js|mjs|cjs)$/i.test(file);
  const sourceFile = ts.createSourceFile(
    PATH3.basename(file),
    sourceText,
    ts.ScriptTarget.Latest,
    true,
    isJsLike ? ts.ScriptKind.JS : void 0
  );
  const specs = /* @__PURE__ */ new Set();
  function visit(node) {
    if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
      const spec = node.moduleSpecifier.text;
      if (!spec.startsWith(".") && !spec.startsWith("node:")) {
        specs.add(getBasePackageName(spec));
      }
    }
    ts.forEachChild(node, visit);
  }
  visit(sourceFile);
  return [...specs];
}

// src/actions/barrel/resolveBarrel.ts
import fs4 from "node:fs";
import { createRequire as createRequire2 } from "node:module";
import PATH4 from "node:path";
var require3 = createRequire2(import.meta.url);
function findPackageRoot(entry, pkg) {
  let dir = PATH4.dirname(entry);
  for (; ; ) {
    const manifestPath = PATH4.join(dir, "package.json");
    if (fs4.existsSync(manifestPath)) {
      try {
        const manifest = JSON.parse(fs4.readFileSync(manifestPath, "utf8"));
        if (manifest.name === pkg) return dir;
      } catch {
      }
    }
    const parent = PATH4.dirname(dir);
    if (parent === dir) return void 0;
    dir = parent;
  }
}
function resolvePackageDir(pkg, fromDir) {
  try {
    return PATH4.dirname(require3.resolve(`${pkg}/package.json`, { paths: [fromDir] }));
  } catch {
  }
  try {
    const entry = require3.resolve(pkg, { paths: [fromDir] });
    return findPackageRoot(entry, pkg);
  } catch {
    return void 0;
  }
}

// src/actions/barrel/analyzeBarrel.ts
function analyzeBarrel(barrelPkg, fromDir, scopePrefix) {
  const collected = /* @__PURE__ */ new Set();
  const visited = /* @__PURE__ */ new Set();
  const queue = [{ fromDir, pkg: barrelPkg }];
  while (queue.length > 0) {
    const current = queue.shift();
    if (!current || visited.has(current.pkg)) continue;
    visited.add(current.pkg);
    const location = resolvePackageDir(current.pkg, current.fromDir);
    if (!(location != null && location.length > 0)) continue;
    const roots = getRuntimeRootFiles(location, readPackageManifest(location));
    const specs = /* @__PURE__ */ new Set();
    for (const root of roots) {
      for (const spec of getReExportSpecs(root)) specs.add(spec);
    }
    const eligibleSpecs = [...specs].filter(
      (spec) => spec !== barrelPkg && (!(scopePrefix != null && scopePrefix.length > 0) || spec.startsWith(scopePrefix))
    );
    for (const spec of eligibleSpecs) {
      collected.add(spec);
      if (!visited.has(spec)) queue.push({ fromDir: location, pkg: spec });
    }
  }
  collected.delete(barrelPkg);
  return [...collected].toSorted((a, b) => a.localeCompare(b));
}

// src/actions/lint-init.ts
function askConfirmation(question) {
  const rl = createInterface({ input: process.stdin, output: process.stdout });
  return new Promise((resolve) => {
    rl.question(question, (answer) => {
      rl.close();
      resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
    });
  });
}
function defaultBarrelMessage(pkg) {
  return `Use '${pkg}' instead.`;
}
var BARREL_DESCRIPTORS = [
  {
    barrelType: "js",
    configVarName: "disallowedImportsXyLabs",
    message: defaultBarrelMessage("@xylabs/sdk-js"),
    pkg: "@xylabs/sdk-js",
    scopePrefix: "@xylabs/"
  },
  {
    barrelType: "js",
    configVarName: "disallowedImportsXyo",
    message: defaultBarrelMessage("@xyo-network/sdk-js"),
    pkg: "@xyo-network/sdk-js",
    scopePrefix: "@xyo-network/"
  },
  {
    barrelType: "isReact",
    configVarName: "disallowedImportsXyLabsReact",
    message: defaultBarrelMessage("@xylabs/sdk-isReact"),
    pkg: "@xylabs/sdk-isReact",
    scopePrefix: "@xylabs/"
  }
];
function getRequiredDevDependencies(isReact) {
  const configPkg = isReact ? "@xylabs/eslint-config-react-flat" : "@xylabs/eslint-config-flat";
  return {
    [configPkg]: bundledToolchainRange(),
    eslint: "^10.0.0"
  };
}
function isBarrelAvailableForRepo(descriptor, isReact) {
  return descriptor.barrelType === "js" || isReact;
}
function getBarrelDescriptorsForRepo(isReact) {
  return BARREL_DESCRIPTORS.filter((descriptor) => isBarrelAvailableForRepo(descriptor, isReact));
}
function formatDisallowedArray(name, imports, message) {
  const items = imports.map((i) => `  { name: '${i}', message: "${message}" },`).join("\n");
  return `const ${name} = [
${items}
]`;
}
function generateEslintConfig({ barrels, isReact }) {
  const configPkg = isReact ? "@xylabs/eslint-config-react-flat" : "@xylabs/eslint-config-flat";
  const defaultConfigName = isReact ? "configReactTier3OpinionatedTypeChecked" : "configTier3OpinionatedTypeChecked";
  const defaultConfigVarName = "xylabsConfig";
  const lines = [];
  if (isReact) {
    lines.push(
      "import {",
      "  configReactStorybook,",
      `  ${defaultConfigName} as ${defaultConfigVarName},`,
      `} from '${configPkg}'`,
      ""
    );
  } else {
    lines.push(`import { ${defaultConfigName} as ${defaultConfigVarName} } from '${configPkg}'`, "");
  }
  lines.push("import type { Linter } from 'eslint'", "");
  for (const barrel of barrels) {
    lines.push(formatDisallowedArray(barrel.configVarName, barrel.imports, barrel.message), "");
  }
  lines.push("const config: Linter.Config[] = [", "  { ignores: ['.yarn/**', 'build', '**/build/**', '**/dist/**', 'dist', 'node_modules/**', '**/node_modules/**', '**/*.md', '.claude/worktrees/*'] },", `  ...${defaultConfigVarName},`);
  if (isReact) lines.push("  ...configReactStorybook,");
  if (barrels.length > 0) {
    lines.push("  {", "    rules:", "    {", "      'no-restricted-imports': [", "        'warn',", "        {", "          paths: [");
    for (const barrel of barrels) {
      lines.push(`            ...${barrel.configVarName},`);
    }
    lines.push("          ],", "        },", "      ],", "    },", "  },");
  }
  lines.push("]", "", "export default config", "");
  return lines.join("\n");
}
function shouldAddDevDependencies(packageJsonPath, requiredDeps, isVerbose) {
  const content = readFileSync4(packageJsonPath, "utf8");
  const pkg = JSON.parse(content);
  const devDeps = pkg.devDependencies ?? {};
  let isChanged = false;
  for (const [name, version] of Object.entries(requiredDeps)) {
    if (!Object.hasOwn(devDeps, name)) {
      devDeps[name] = version;
      isChanged = true;
      if (isVerbose === true) console.log(chalk4.gray(`  Added ${name}@${version} to devDependencies`));
    } else if (isVerbose === true) {
      console.log(chalk4.gray(`  ${name} already in devDependencies`));
    }
  }
  if (isChanged) {
    const sorted = Object.fromEntries(Object.entries(devDeps).toSorted(([a], [b]) => a.localeCompare(b)));
    pkg.devDependencies = sorted;
    writeFileSync(packageJsonPath, `${JSON.stringify(pkg, null, 2)}
`, "utf8");
    console.log(chalk4.green("Updated package.json devDependencies"));
  } else {
    console.log(chalk4.gray("package.json devDependencies already up to date"));
  }
  return isChanged;
}
function findExistingConfig(configPath, legacyConfigPath) {
  if (existsSync3(configPath)) return configPath;
  if (existsSync3(legacyConfigPath)) return legacyConfigPath;
  return void 0;
}
function removeLegacyConfig(legacyConfigPath) {
  if (!existsSync3(legacyConfigPath)) {
    return;
  }
  unlinkSync(legacyConfigPath);
  console.log(chalk4.gray("Removed legacy eslint.config.mjs"));
}
function updateDependencies(packageJsonPath, isReact, cwd, isVerbose) {
  if (!existsSync3(packageJsonPath)) {
    console.log(chalk4.yellow("No package.json found \u2014 skipping dependency updates"));
    return;
  }
  const isChanged = shouldAddDevDependencies(packageJsonPath, getRequiredDevDependencies(isReact), isVerbose);
  if (isChanged) {
    shouldRunInstall(cwd);
  }
}
function ensureBarrelInstalled(cwd, barrelPkg, isVerbose) {
  const existing = resolvePackageDir(barrelPkg, cwd);
  if (existing !== void 0) return existing;
  const packageJsonPath = PATH5.resolve(cwd, "package.json");
  if (!existsSync3(packageJsonPath)) {
    console.warn(chalk4.yellow(`No package.json found \u2014 cannot install ${barrelPkg} for barrel analysis`));
    return void 0;
  }
  console.log(chalk4.cyan(`${barrelPkg} not installed \u2014 adding it so its barrel can be analyzed`));
  shouldAddDevDependencies(packageJsonPath, { [barrelPkg]: "latest" }, isVerbose);
  shouldRunInstall(cwd);
  return resolvePackageDir(barrelPkg, cwd);
}
function resolveEnabledBarrels(cwd, enabled, isVerbose) {
  const resolved = [];
  for (const descriptor of enabled) {
    const location = ensureBarrelInstalled(cwd, descriptor.pkg, isVerbose);
    if (location === void 0) {
      console.warn(chalk4.yellow(`Skipping ${descriptor.pkg} import restrictions \u2014 package could not be resolved`));
      continue;
    }
    const imports = analyzeBarrel(descriptor.pkg, cwd, descriptor.scopePrefix);
    if (imports.length === 0) {
      console.warn(chalk4.yellow(`Skipping ${descriptor.pkg} import restrictions \u2014 no re-exported packages found`));
      continue;
    }
    if (isVerbose === true) console.log(chalk4.gray(`  ${descriptor.pkg}: ${imports.length} re-exported package(s)`));
    resolved.push({
      configVarName: descriptor.configVarName,
      imports,
      message: descriptor.message
    });
  }
  return resolved;
}
async function lintInit({ isVerbose } = {}) {
  const cwd = INIT_CWD();
  const configPath = PATH5.resolve(cwd, "eslint.config.ts");
  const legacyConfigPath = PATH5.resolve(cwd, "eslint.config.mjs");
  const existingPath = findExistingConfig(configPath, legacyConfigPath);
  if (existingPath !== void 0) {
    const filename = PATH5.basename(existingPath);
    const isConfirmed = await askConfirmation(
      chalk4.yellow(`${filename} already exists. Replace it with eslint.config.ts? (y/N) `)
    );
    if (!isConfirmed) {
      console.log(chalk4.gray(`Skipped \u2014 existing ${filename} preserved`));
      return 0;
    }
  }
  const isReact = isReactInMonorepo(cwd, isVerbose);
  if (isReact) {
    console.log(chalk4.cyan("Detected React packages \u2014 using @xylabs/eslint-config-react-flat"));
  } else if (isVerbose === true) {
    console.log(chalk4.gray("  No React packages detected \u2014 using @xylabs/eslint-config-flat"));
  }
  const enabledBarrels = [];
  for (const descriptor of getBarrelDescriptorsForRepo(isReact)) {
    const isConfirmed = await askConfirmation(
      chalk4.cyan(`Disallow ${descriptor.pkg} barrel imports? (y/N) `)
    );
    if (isConfirmed) enabledBarrels.push(descriptor);
  }
  const barrels = resolveEnabledBarrels(cwd, enabledBarrels, isVerbose);
  const config = generateEslintConfig({ barrels, isReact });
  writeFileSync(configPath, config, "utf8");
  console.log(chalk4.green("Generated eslint.config.ts"));
  removeLegacyConfig(legacyConfigPath);
  updateDependencies(PATH5.resolve(cwd, "package.json"), isReact, cwd, isVerbose);
  return 0;
}
export {
  BARREL_DESCRIPTORS,
  formatDisallowedArray,
  getBarrelDescriptorsForRepo,
  lintInit
};
//# sourceMappingURL=lint-init.mjs.map
