// src/actions/packman/rewriteSourceImports.ts
import {
  existsSync,
  readFileSync,
  writeFileSync
} from "node:fs";
import chalk from "chalk";
import { globSync } from "glob";
var SWAPS = [
  ["@xylabs/toolchain", "@xylabs/toolchain"],
  ["@xylabs/toolchain", "@xylabs/toolchain"]
];
var SOURCE_GLOBS = [
  "**/*.ts",
  "**/*.tsx",
  "**/*.mts",
  "**/*.cts",
  "**/*.js",
  "**/*.mjs"
];
var IGNORE_PATTERNS = [
  "**/node_modules/**",
  "**/dist/**",
  "**/build/**",
  "**/.yarn/**"
];
function rewriteSourceImports(cwd) {
  const files = globSync(SOURCE_GLOBS, {
    cwd,
    absolute: true,
    ignore: IGNORE_PATTERNS
  });
  let count = 0;
  for (const file of files) {
    if (!existsSync(file)) continue;
    const original = readFileSync(file, "utf8");
    let content = original;
    for (const [from, to] of SWAPS) {
      content = content.replaceAll(from, () => to);
    }
    if (content !== original) {
      writeFileSync(file, content, "utf8");
      count++;
    }
  }
  if (count > 0) {
    console.log(chalk.green(`  Rewrote toolchain imports in ${count} source file(s)`));
  }
}
export {
  rewriteSourceImports
};
//# sourceMappingURL=rewriteSourceImports.mjs.map
