// Rollup configuration reproducing upstream's Vite dist build under Debian.
//
// Upstream builds dist/ with Vite (support/build-dist.mjs); since Vite uses
// Rollup internally, we reproduce the three published artifacts directly with
// Rollup, avoiding a Vite build-dependency:
//   * dist/js-yaml.js      UMD, readable
//   * dist/js-yaml.min.js  UMD, minified
//   * dist/js-yaml.mjs     ES module
//
// Plugins and package.json are loaded through createRequire because Debian's
// Node only augments the CommonJS resolver with /usr/share/nodejs, not the
// native ESM resolver used for `import` in a .mjs config.
import { createRequire } from 'node:module'

const require = createRequire(import.meta.url)
const commonjs = require('@rollup/plugin-commonjs')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const terser = require('@rollup/plugin-terser')
const pkg = require('../package.json')

const banner = `/*! ${pkg.name} ${pkg.version} https://github.com/${pkg.repository} @license ${pkg.license} */`

// Same entry as the Vite build: a thin proxy re-exporting the CommonJS API
// both as named exports and as a default export.
const input = 'lib/index_vite_proxy.tmp.mjs'

const plugins = [nodeResolve(), commonjs()]

const umd = { format: 'umd', name: 'jsyaml', exports: 'named', esModule: true, banner }

export default [
  {
    input,
    output: [
      { ...umd, file: 'dist/js-yaml.js' },
      { ...umd, file: 'dist/js-yaml.min.js', plugins: [terser()] }
    ],
    plugins
  },
  {
    input,
    output: [
      { format: 'es', file: 'dist/js-yaml.mjs', banner }
    ],
    plugins
  }
]
