// Bundles the extension's TypeScript entry points into dist/ for Firefox to load. // // Runs on `npm run build` and, via the `prepare` script, on every `npm ci` — so CI's // `web-ext lint` (which needs the referenced bundles to exist) works without a separate // build step. Firefox-only: no polyfill, native ESM, `browser.*` is a global. import { build } from 'esbuild'; import { rm, mkdir } from 'node:fs/promises'; import { fileURLToPath } from 'node:url'; import { dirname, resolve } from 'node:path'; const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const outdir = resolve(root, 'dist'); // One entry per manifest surface. Add popup/options/content here as they land. const entryPoints = { background: resolve(root, 'src/background/index.ts'), }; await rm(outdir, { recursive: true, force: true }); await mkdir(outdir, { recursive: true }); const watch = process.argv.includes('--watch'); const dev = watch || process.argv.includes('--dev'); const options = { entryPoints, outdir, bundle: true, format: 'esm', target: ['firefox128'], platform: 'browser', sourcemap: dev ? 'inline' : 'linked', minify: !dev, logLevel: 'info', // A bare `import ... from 'ws'` etc. must never reach a bundle — fail loud if one does. external: [], }; if (watch) { const ctx = await (await import('esbuild')).context(options); await ctx.watch(); console.log('esbuild: watching'); } else { await build(options); }