// tsup.config.ts import { defineConfig } from 'tsup' import fs from 'node:fs' import path from 'node:path' // --- 0) Atualiza package.json antes do build (determinístico) --- const pkgPath = path.resolve('package.json') const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) // Agora vamos de Day.js “turbinado”: CJS + ESM + IIFE const nextPkg = { ...pkg, "main": "dist/index.cjs", "types": "dist/index.d.ts", "browser": "dist/index.global.js", "unpkg": "dist/index.global.js", "jsdelivr": "dist/index.global.js", "sideEffects": false, module: undefined, type: undefined as unknown as string, exports: undefined as unknown as Record, } // remove chaves undefined for (const k of Object.keys(nextPkg)) { // @ts-ignore if (nextPkg[k] === undefined) delete (nextPkg as any)[k] } fs.writeFileSync(pkgPath, JSON.stringify(nextPkg, null, 2) + '\n') // --- 1) Externals automáticos --- const external = [ ...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.peerDependencies ?? {}), ] // --- 2) Config tsup: CJS + ESM + IIFE --- export default defineConfig([ // 2.1) CJS para Node/SSR (gera dist/index.cjs + dist/index.d.ts) { entry: { index: 'src/index.ts' }, outDir: 'dist', format: ['cjs'], dts: true, // emite tipos aqui platform: 'neutral', target: 'es2018', treeshake: true, sourcemap: false, minify: true, clean: true, // limpa dist nesta job external, skipNodeModulesBundle: true, outExtension: () => ({ js: '.cjs' }), }, // 2.2) ESM para bundlers (gera dist/index.mjs) { entry: { index: 'src/index.ts' }, outDir: 'dist', format: ['esm'], dts: false, // tipos já emitidos platform: 'neutral', target: 'es2018', treeshake: true, sourcemap: false, minify: true, clean: false, external, skipNodeModulesBundle: true, outExtension: () => ({ js: '.mjs' }), }, // 2.3) IIFE global para