import { defineConfig } from 'vite'; import replace from '@rollup/plugin-replace'; import { execSync } from 'node:child_process'; import shebang from 'rollup-plugin-preserve-shebang'; import path from 'node:path'; let gitInfo = { branch: '', commit: '', tags: '', commitDate: '', }; try { gitInfo = { branch: execSync('git rev-parse --abbrev-ref HEAD').toString().trim(), commit: execSync('git rev-parse --short HEAD').toString().trim(), tags: '', commitDate: execSync('git log -1 --format=%cd --date=iso').toString().trim(), }; try { gitInfo.tags = execSync('git tag --points-at HEAD | paste -sd "," -').toString().trim(); } catch { gitInfo.tags = ''; } } catch { // eslint-disable-next-line no-console console.log('Directory does not have a Git repository, skipping git info'); } export default defineConfig({ plugins: [ replace({ '__VERSION__': process.env.npm_package_version, '__GIT_BRANCH__': gitInfo.branch, '__GIT_COMMIT__': gitInfo.commit, '__GIT_TAGS__': gitInfo.tags === '' ? '' : `T:${gitInfo.tags}`, '__GIT_COMMIT_DATE__': gitInfo.commitDate, '__SYSTEM_INFO__': `${process.platform} ${process.arch} ${process.version}`, preventAssignment: true, }), shebang({ shebang: '#!/usr/bin/env node', }), ], build: { target: 'esnext', outDir: 'dist', ssr: true, rollupOptions: { external: [ // Dependencies from package.json '@modelcontextprotocol/sdk', '@modelcontextprotocol/sdk/client/index.js', '@modelcontextprotocol/sdk/client/stdio.js', '@modelcontextprotocol/sdk/types.js', '@redaksjon/protokoll', 'commander', 'cli-progress', // Node.js built-in modules (node: prefix) /^node:/, ], input: { main: 'src/main.ts', }, output: { format: 'esm', entryFileNames: '[name].js', chunkFileNames: '[name].js', }, }, modulePreload: false, minify: false, sourcemap: true }, resolve: { alias: { '@': path.resolve(__dirname, 'src'), }, }, });