// src/actions/package/compile/copyTypeFiles.ts
import { copyFile, readdir } from "fs/promises";
import { Mutex } from "async-mutex";
var copyFileMutex = new Mutex();
var getDistTypeFiles = async (compilerOptions) => {
  const outDir = compilerOptions.outDir ?? "dist";
  return (await readdir(outDir, { recursive: true })).filter((file) => file.endsWith("d.ts")).map((file) => `${outDir}/${file}`);
};
var getDistTypeMapFiles = async (compilerOptions) => {
  const outDir = compilerOptions.outDir ?? "dist";
  return (await readdir(outDir, { recursive: true })).filter((file) => file.endsWith("d.ts.map")).map((file) => `${outDir}/${file}`);
};
var copyTypeFiles = async (compilerOptions) => {
  await copyFileMutex.runExclusive(async () => {
    const distTypeFiles = await getDistTypeFiles(compilerOptions);
    await Promise.all(
      distTypeFiles.map(async (file) => {
        await copyFile(file, file.replace("d.ts", "d.mts"));
        await copyFile(file, file.replace("d.ts", "d.cts"));
      })
    );
    const distTypeMapFiles = await getDistTypeMapFiles(compilerOptions);
    await Promise.all(
      distTypeMapFiles.map(async (file) => {
        await copyFile(file, file.replace("d.ts.map", "d.mts.map"));
        await copyFile(file, file.replace("d.ts.map", "d.cts.map"));
      })
    );
  });
};
export {
  copyTypeFiles
};
//# sourceMappingURL=copyTypeFiles.mjs.map