ReviewOS

also looking at this

stacks/ts-analytics

fix: emit a real library build (dist/index.js + ./stx) so the package is importable

#124
Merged glennmichael123 wants to merge fix/library-build into main
6 files +72 -13
build.tsmodified+44-8
Changes to build.ts
@@ -1,10 +1,46 @@
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 the package's JS + declarations so `@stacksjs/ts-analytics`
4 * is importable (package.json's `module`/`exports`/`types` all point at ./dist).
5 *
6 * Builds two entrypoints so both exports resolve:
7 * `.` → dist/index.js + dist/index.d.ts
8 * `./stx` → dist/integrations/stx.js + dist/integrations/stx.d.ts (the tsAnalytics() module)
9 *
10 * The static dashboard SITE is a separate deploy artifact — `bun run build:site`
11 * (build-site.ts → dist-site/). Keeping them apart stops the SSG's cleanOutput
12 * from wiping the library and vice-versa. node_modules stays external.
13 */
14import { rmSync } from 'node:fs'
15import { dts } from 'bun-plugin-dtsx'
16import stx from 'bun-plugin-stx'
17
18rmSync('./dist', { recursive: true, force: true })
19
20const result = await Bun.build({
21 entrypoints: ['./src/index.ts', './src/integrations/stx.ts'],
22 splitting: true,
23 outdir: './dist',
24 root: './src',
25 // bun-plugin-stx resolves the `.stx` imports a few library modules carry
26 // (e.g. handlers render dashboard views server-side); dts() emits declarations.
27 plugins: [stx(), dts()],
28 target: 'bun',
29 format: 'esm',
30 packages: 'external',
1031})
32
33if (!result.success) {
34 console.error('[ts-analytics] library build failed:')
35 for (const log of result.logs)
36 console.error(log)
37 process.exit(1)
38}
39
40for (const f of ['./dist/index.js', './dist/integrations/stx.js']) {
41 if (!(await Bun.file(f).exists())) {
42 console.error(`[ts-analytics] build succeeded but ${f} is missing — check the entrypoints/exports`)
43 process.exit(1)
44 }
45}
46console.log(`[ts-analytics] library built → dist/ (${result.outputs.length} files; index.js + integrations/stx.js present)`)