|
| 1 | +/** |
| 2 | + * @file Rolldown configuration for the meander CLI bundle — one |
| 3 | + * real bundle, `dist/cli.mjs`, the consumer-install entry |
| 4 | + * (see package.json `bin`). `scripts/repo/build.mts` imports |
| 5 | + * this config and calls rolldown's `build()` with it; type |
| 6 | + * declarations are emitted separately via `tsc`. |
| 7 | + * Externals: |
| 8 | + * |
| 9 | + * - node built-ins (never bundled). |
| 10 | + * - csso / mermaid / puppeteer / rolldown / svgo — loaded dynamically by opt-in |
| 11 | + * features. Bundling them would drag in Chromium downloads (puppeteer) or |
| 12 | + * force mermaid's DOM-heavy runtime into the CLI for everyone. Consumers |
| 13 | + * install `rolldown` themselves only if they enable the JS minify pass; |
| 14 | + * `csso` and `svgo` ship as direct meander deps but stay external so their |
| 15 | + * (larger) parser code isn't duplicated into cli.mjs. |
| 16 | + * - @valtown/sdk — only used by deploy-val. Kept external so the CLI stays |
| 17 | + * small for the 90% of users who only run generate / serve / publish. |
| 18 | + */ |
| 19 | + |
| 20 | +import { builtinModules } from 'node:module' |
| 21 | +import path from 'node:path' |
| 22 | +import { fileURLToPath } from 'node:url' |
| 23 | + |
| 24 | +import type { BuildOptions } from 'rolldown' |
| 25 | + |
| 26 | +const configDir = path.dirname(fileURLToPath(import.meta.url)) |
| 27 | +const rootPath = path.join(configDir, '..', '..') |
| 28 | + |
| 29 | +const nodeBuiltins = [ |
| 30 | + ...builtinModules, |
| 31 | + ...builtinModules.map(m => `node:${m}`), |
| 32 | +] |
| 33 | + |
| 34 | +/** |
| 35 | + * Optional + deploy-only deps. Never bundled. |
| 36 | + */ |
| 37 | +export const runtimeExternals = [ |
| 38 | + '@valtown/sdk', |
| 39 | + 'csso', |
| 40 | + 'mermaid', |
| 41 | + 'puppeteer', |
| 42 | + 'rolldown', |
| 43 | + 'svgo', |
| 44 | +] |
| 45 | + |
| 46 | +/* `external` string entries match the import specifier EXACTLY — a bare |
| 47 | + * 'rolldown' entry does not cover src/minify.mts's `import('rolldown/ |
| 48 | + * experimental')`. Bundling that subpath would inline rolldown's own napi |
| 49 | + * loader into cli.mjs, where its binary-lookup paths (resolved relative to |
| 50 | + * rolldown's own package dir) no longer point anywhere real. The regex |
| 51 | + * externalizes every 'rolldown' + 'rolldown/<subpath>' specifier so the |
| 52 | + * whole package stays a real runtime import. */ |
| 53 | +const rolldownSpecifier = /^rolldown(?:\/|$)/ |
| 54 | + |
| 55 | +export const cliBuildConfig: BuildOptions = { |
| 56 | + external: [...nodeBuiltins, ...runtimeExternals, rolldownSpecifier], |
| 57 | + input: path.join(rootPath, 'src/cli.mts'), |
| 58 | + output: { |
| 59 | + banner: '#!/usr/bin/env node', |
| 60 | + // Internal dynamic imports fold into the single-file bundle |
| 61 | + // (external opt-in deps stay dynamic at runtime). |
| 62 | + codeSplitting: false, |
| 63 | + file: path.join(rootPath, 'dist/cli.mjs'), |
| 64 | + format: 'esm', |
| 65 | + minify: false, |
| 66 | + sourcemap: false, |
| 67 | + }, |
| 68 | + platform: 'node', |
| 69 | +} |
0 commit comments