Commit 1 of 1:
84200c42a7
fix: emit a real library build (dist/index.js + ./stx) instead of an SSG site
whole branch
Review threads live on the whole diff, not on one commit, so
none are shown here - a thread's line means something in the
branch's final form, and painting it into an intermediate
step would put it on code it is not about.
Changes to .gitignore ⋯ 4 lines Show the 4 lines above this hunk @@ -5,6 +5,7 @@5 5 * . tgz 6 6 coverage 7 7 dist 8 + dist - site 8 9 lib - cov 9 10 logs 10 11 node_modules
Changes to build-site.ts @@ -0,0 +1,17 @@ 1 + # ! / usr / bin / env bun 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + import { generateStaticSite } from '@stacksjs/stx/ssg' 10 + 11 + await generateStaticSite ( { 12 + pagesDir : 'pages' , 13 + outputDir : 'dist-site' , 14 + publicDir : 'public' , 15 + sitemap : true , 16 + cleanOutput : true , 17 + } )
Changes to build.ts @@ -1,10 +1,46 @@ 1 1 # ! / usr / bin / env bun 2 - import { generateStaticSite } from '@stacksjs/stx/ssg' 3 - 4 - await generateStaticSite ( { 5 - pagesDir : 'pages' , 6 - outputDir : 'dist' , 7 - publicDir : 'public' , 8 - sitemap : true , 9 - cleanOutput : true , 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + import { rmSync } from 'node:fs' 15 + import { dts } from 'bun-plugin-dtsx' 16 + import stx from 'bun-plugin-stx' 17 + 18 + rmSync ( './dist' , { recursive : true , force : true } ) 19 + 20 + const result = await Bun . build ( { 21 + entrypoints : [ './src/index.ts' , './src/integrations/stx.ts' ] , 22 + splitting : true , 23 + outdir : './dist' , 24 + root : './src' , 25 + 26 + 27 + plugins : [ stx ( ) , dts ( ) ] , 28 + target : 'bun' , 29 + format : 'esm' , 30 + packages : 'external' , 10 31 } ) 32 + 33 + if ( ! 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 + 40 + for ( 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 + } 46 + console . log ( `[ts-analytics] library built → dist/ (${result.outputs.length} files; index.js + integrations/stx.js present)` )
Changes to package.json ⋯ 45 lines Show the 45 lines above this hunk @@ -46,6 +46,7 @@46 46 "scripts" : { 47 47 "analytics" : "bun ./bin/cli.ts" , 48 48 "build" : "bun build.ts" , 49 + "build:site" : "bun build-site.ts" , 49 50 "preview" : "bun preview.ts" , 50 51 "dev" : "bun --watch serve.ts" , 51 52 "dev:server" : "bun --watch ./server/index.ts" ,
Changes to preview.ts @@ -1,13 +1,14 @@ 1 1 # ! / usr / bin / env bun 2 2 3 - 4 - 3 + 4 + 5 + 5 6 6 7 7 8 8 9 9 10 const port = Number ( process . argv [ 2 ] ) || 3001 10 - const distDir = 'dist' 11 + const distDir = 'dist -site ' 11 12 12 13 Bun . serve ( { 13 14 port ,
src/tracking-script.ts modified +5 -2 Changes to src/tracking-script.ts ⋯ 186 lines Show the 186 lines above this hunk @@ -187,10 +187,13 @@ function buildScript(config: TrackingScriptConfig): string { 187 187 } 188 188 189 189 function buildConfigSection ( config : TrackingScriptConfig ) : string { 190 + 191 + 192 + 190 193 return `// Configuration 191 194 var CONFIG = { 192 - siteId : ' ${config.siteId} ' , 193 - endpoint : ' ${config.apiEndpoint}/collect ' , 195 + siteId : $ { JSON . stringify ( config . siteId ) } , 196 + endpoint : $ { JSON . stringify ( `${ config.apiEndpoint}/collect ` ) } , 194 197 honorDnt : $ { config . honorDnt ? ? true } , 195 198 sessionTimeout : $ { ( config . sessionTimeout ? ? 30 ) * 60 * 1000 } , 196 199 debug : $ { config . debug ? ? false } ,