import type { Options } from 'tsup'

/**
 * Platform build contract for every @platform-modules/* module.
 *
 * One place that fixes: ESM-only output, ES2022 target, emitted .d.ts,
 * tree-shaken bundles (matches `sideEffects: false`), clean dist per build.
 * Consumers pass only what differs per module:
 *   - `entry`    the subpath entrypoints (one for leaf modules, many for fan-out)
 *   - `external` peers + workspace deps the consumer must bring (react, @platform-modules/*)
 *
 * `external` is set only when provided — no empty-array default leaks to the
 * seam (R1). Consumed raw (.ts) by tsup's esbuild config loader, so no build.
 */
export function tsupBase(options: { entry: string[]; external?: string[] }): Options {
  return {
    entry: options.entry,
    format: ['esm'],
    target: 'es2022',
    dts: true,
    clean: true,
    treeshake: true,
    splitting: false,
    ...(options.external ? { external: options.external } : {}),
  }
}
