import glob from 'fast-glob' import { build } from 'esbuild' import { Project } from 'ts-morph' const project = new Project({ compilerOptions: { outDir: 'dist', emitDeclarationOnly: true, }, tsConfigFilePath: './tsconfig.json', }) project.emit() build({ entryPoints: await glob(['src/**/*.{ts,tsx}', '!src/**/*.test.ts']), outdir: 'dist', format: 'esm', watch: process.argv.includes('--watch') ? { onRebuild: async (error) => { if (error) { console.error('watch build failed:', error) } else { await Promise.all( project .getSourceFiles() .map((sourceFile) => sourceFile.refreshFromFileSystem()) ) project.emit() } }, } : undefined, })