UNPKG

llmxml

Version:

Convert between markdown and LLM-friendly pseudo-XML

65 lines (63 loc) 1.73 kB
import { defineConfig } from 'tsup'; import { copyFile, mkdir } from 'fs/promises'; import { fileURLToPath } from 'url'; import { join, dirname } from 'path'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); export default defineConfig([ // ESM build { entry: ['src/index.ts'], format: 'esm', dts: true, splitting: false, sourcemap: true, clean: true, treeshake: true, outDir: 'dist/esm', esbuildOptions(options) { options.legalComments = 'none'; options.ignoreAnnotations = true; }, async onSuccess() { // Copy grammar file to ESM build await mkdir(join('dist', 'esm', 'grammar'), { recursive: true }); await copyFile( join('src', 'grammar', 'llmxml.pegjs'), join('dist', 'esm', 'grammar', 'llmxml.pegjs') ); } }, // CJS build { entry: ['src/index.ts'], format: 'cjs', dts: true, splitting: false, sourcemap: true, clean: false, treeshake: true, outDir: 'dist/cjs', noExternal: ['unified', 'remark', 'remark-parse', 'jsdom', 'winston'], platform: 'node', target: 'node16', outExtension: ({ format }) => ({ js: `.${format}` }), esbuildOptions(options) { options.legalComments = 'none'; options.ignoreAnnotations = true; }, async onSuccess() { try { // Copy grammar file to CJS build await mkdir(join('dist', 'cjs', 'grammar'), { recursive: true }); await copyFile( join('src', 'grammar', 'llmxml.pegjs'), join('dist', 'cjs', 'grammar', 'llmxml.pegjs') ); } catch (err) { console.error('Error copying grammar file:', err); } } } ]);