import path from 'node:path';
import { defineConfig } from 'tsup';

const silent = false;

const PACKAGE_ROOT_PATH = process.cwd();

const MAIN_PATH = path.join(PACKAGE_ROOT_PATH, 'src/index.ts');

export default defineConfig((opts) => {
  return {
    ...opts,
    entry: [MAIN_PATH],
    format: ['cjs', 'esm'],
    dts: true,
    sourcemap: true,
    clean: true,
    minify: true,

    ...(silent
      ? {
          silent: true,
          onSuccess: async () => {
            if (opts.watch) {
              console.info('Watching for changes...');
              return;
            }

            console.info('Build succeeded!');
          },
        }
      : {}),
  };
});
