'use strict';

const node_fs = require('node:fs');
const consola = require('./cli.81cce562.cjs');

const overrideEnv = (targetEnv) => {
  const currentEnv = process.env.NODE_ENV;
  if (currentEnv && currentEnv !== targetEnv) {
    console.warn(
      `Changing \`NODE_ENV\` from \`${currentEnv}\` to \`${targetEnv}\`, to avoid unintended behavior.`
    );
  }
  process.env.NODE_ENV = targetEnv;
};

async function clearDir(path) {
  await node_fs.promises.rm(path, { recursive: true, force: true });
  await node_fs.promises.mkdir(path, { recursive: true });
}
async function rmRecursive(paths) {
  await Promise.all(
    paths.filter((p) => typeof p === "string").map(async (path) => {
      consola.consola.debug("Removing recursive path", path);
      await node_fs.promises.rm(path, { recursive: true, force: true }).catch(() => {
      });
    })
  );
}

exports.clearDir = clearDir;
exports.overrideEnv = overrideEnv;
exports.rmRecursive = rmRecursive;
