ReviewOS

also looking at this

stacks/ts-analytics

feat(stx): one-line stx integration (plugins: ['@stacksjs/ts-analytics']) + fix library build

#123
Closed glennmichael123 wants to merge feat/stx-integration into main
11 files +331 -13
build.tsmodified+48-8
Changes to build.ts
@@ -1,10 +1,50 @@
11#!/usr/bin/env bun
2import { generateStaticSite } from '@stacksjs/stx/ssg'
3
4await generateStaticSite({
5 pagesDir: 'pages',
6 outputDir: 'dist',
7 publicDir: 'public',
8 sitemap: true,
9 cleanOutput: true,
2/**
3 * Library build — emits dist/index.js (+ every module under ./*) and
4 * declarations, so `@stacksjs/ts-analytics` is importable as a package
5 * (package.json `module`/`exports`/`types` all point at ./dist).
6 *
7 * The static dashboard SITE is a separate deploy artifact — see build-site.ts
8 * (`bun run build:site` → dist-site/). Keeping them apart stops the SSG's
9 * cleanOutput from wiping the library and vice-versa.
10 *
11 * Mirrors the sibling stacks library builds: every source module is built so
12 * the `./*` subpath export resolves to real JS (not just a .d.ts stub), with
13 * node_modules left external (`packages: 'external'`).
14 */
15import { rmSync } from 'node:fs'
16import { dts } from 'bun-plugin-dtsx'
17import stx from 'bun-plugin-stx'
18
19rmSync('./dist', { recursive: true, force: true })
20
21// Build from the public entry only and let Bun follow the import graph, so the
22// dashboard-UI shims (src/components/dashboard re-exports repo-root `.stx`) that
23// aren't part of the library API are excluded automatically. `splitting` keeps
24// shared code in chunks instead of duplicating it into index.js.
25const result = await Bun.build({
26 entrypoints: ['./src/index.ts'],
27 splitting: true,
28 outdir: './dist',
29 root: './src',
30 // bun-plugin-stx resolves the `.stx` imports a few library modules carry
31 // (e.g. handlers render dashboard views server-side); dts() emits declarations.
32 plugins: [stx(), dts()],
33 target: 'bun',
34 format: 'esm',
35 packages: 'external',
1036})
37
38if (!result.success) {
39 console.error('[ts-analytics] library build failed:')
40 for (const log of result.logs)
41 console.error(log)
42 process.exit(1)
43}
44
45const hasIndex = await Bun.file('./dist/index.js').exists()
46if (!hasIndex) {
47 console.error('[ts-analytics] build succeeded but dist/index.js is missing — check src/index.ts')
48 process.exit(1)
49}
50console.log(`[ts-analytics] library built → dist/ (${result.outputs.length} files, dist/index.js present)`)