// src/actions/package/compile/copyTypeFiles.ts
import { copyFile, readdir } from "node:fs/promises";
var copyChain = Promise.resolve();
async function runExclusive(task) {
  const previous = copyChain;
  let release;
  const gate = new Promise((resolve) => {
    release = resolve;
  });
  copyChain = gate;
  try {
    try {
      await previous;
    } catch {
    }
    return await task();
  } finally {
    release?.();
  }
}
var getDistTypeFiles = async (compilerOptions) => {
  const outDir = compilerOptions.outDir ?? "dist";
  const files = await readdir(outDir, { recursive: true });
  return files.filter((file) => file.endsWith("d.ts")).map((file) => `${outDir}/${file}`);
};
var getDistTypeMapFiles = async (compilerOptions) => {
  const outDir = compilerOptions.outDir ?? "dist";
  const files = await readdir(outDir, { recursive: true });
  return files.filter((file) => file.endsWith("d.ts.map")).map((file) => `${outDir}/${file}`);
};
var copyTypeFiles = async (compilerOptions) => {
  await 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
