// src/actions/package/compile/resolveCompilePlatforms.ts
import { cwd } from "node:process";
import chalk from "chalk";
var resolvePlatformRecord = (value) => {
  if (value === void 0 || value === true) return { src: {} };
  if (value === false) return {};
  const { esbuildOptions: _legacyEsbuildOptions, ...entries } = value;
  return entries;
};
var classifyPlatform = (value) => {
  if (value === void 0) {
    return {
      deprecatedEmptyObject: false,
      entries: {},
      state: "unset"
    };
  }
  if (typeof value === "boolean") {
    return {
      deprecatedEmptyObject: false,
      entries: value ? { src: {} } : {},
      state: value ? "build" : "off"
    };
  }
  const isDeprecatedEmptyObject = Object.keys(value).length === 0;
  const entries = resolvePlatformRecord(value);
  return {
    deprecatedEmptyObject: isDeprecatedEmptyObject,
    entries,
    state: Object.keys(entries).length > 0 ? "build" : "off"
  };
};
var resolveCompilePlatforms = (compile) => {
  const node = classifyPlatform(compile?.node);
  const browser = classifyPlatform(compile?.browser);
  const neutral = classifyPlatform(compile?.neutral);
  const isAnyBuild = node.state === "build" || browser.state === "build" || neutral.state === "build";
  const neutralEntries = neutral.state === "build" ? neutral.entries : !isAnyBuild && neutral.state === "unset" ? { src: {} } : {};
  const deprecatedEmptyObjectTargets = [
    ...node.deprecatedEmptyObject ? ["node"] : [],
    ...browser.deprecatedEmptyObject ? ["browser"] : [],
    ...neutral.deprecatedEmptyObject ? ["neutral"] : []
  ];
  return {
    browser: browser.state === "build" ? browser.entries : {},
    deprecatedEmptyObjectTargets,
    neutral: neutralEntries,
    node: node.state === "build" ? node.entries : {}
  };
};
var deprecatedEmptyObjectWarned = /* @__PURE__ */ new Set();
var warnDeprecatedEmptyObjectTargets = (targets) => {
  for (const target of targets) {
    const key = `${cwd()}:${target}`;
    if (deprecatedEmptyObjectWarned.has(key)) continue;
    deprecatedEmptyObjectWarned.add(key);
    console.warn(chalk.yellow(
      `[xy] Deprecated: compile.${target} = {} is treated as "do not build". Set it to \`false\` or remove the field.`
    ));
  }
};
export {
  resolveCompilePlatforms,
  resolvePlatformRecord,
  warnDeprecatedEmptyObjectTargets
};
//# sourceMappingURL=resolveCompilePlatforms.mjs.map
