diff --git a/package.json b/package.json index b1cc31322..432680b7c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ ], "scripts": { "start": "bun run src/ccstatusline.ts", - "build": "rm -rf dist/* ; bun build src/ccstatusline.ts --target=node --outfile=dist/ccstatusline.js --target-version=14", + "build": "rm -rf dist/* ; bun build src/ccstatusline.ts --target=node --splitting --format=esm --outdir=dist --target-version=14", "postbuild": "bun run scripts/replace-version.ts", "example": "cat scripts/payload.example.json | bun start", "video:studio": "remotion studio remotion/index.ts", diff --git a/scripts/replace-version.ts b/scripts/replace-version.ts index 852da26d3..181581761 100755 --- a/scripts/replace-version.ts +++ b/scripts/replace-version.ts @@ -2,6 +2,7 @@ import { readFileSync, + readdirSync, writeFileSync } from 'fs'; import { join } from 'path'; @@ -15,14 +16,25 @@ interface PackageJson { const packageJson = JSON.parse(readFileSync('package.json', 'utf-8')) as PackageJson; const version = packageJson.version; -// Read the bundled file -const bundledFilePath = join('dist', 'ccstatusline.js'); -let bundledContent = readFileSync(bundledFilePath, 'utf-8'); - -// Replace the placeholder with the actual version -bundledContent = bundledContent.replace(/__PACKAGE_VERSION__/g, version); +// The build emits the entry plus code-split chunks, and the placeholder can +// land in any of them, so patch every emitted script rather than just the entry. +let patched = 0; +for (const file of readdirSync('dist')) { + if (!file.endsWith('.js')) { + continue; + } + const path = join('dist', file); + const content = readFileSync(path, 'utf-8'); + if (!content.includes('__PACKAGE_VERSION__')) { + continue; + } + writeFileSync(path, content.replace(/__PACKAGE_VERSION__/g, version)); + patched++; +} -// Write back the modified content -writeFileSync(bundledFilePath, bundledContent); +if (patched === 0) { + console.error('✗ No __PACKAGE_VERSION__ placeholder found in dist/'); + process.exit(1); +} -console.log(`✓ Replaced version placeholder with ${version}`); +console.log(`✓ Replaced version placeholder with ${version} in ${patched} file(s)`); diff --git a/src/ccstatusline.ts b/src/ccstatusline.ts index af6a88535..1da963f8f 100644 --- a/src/ccstatusline.ts +++ b/src/ccstatusline.ts @@ -1,7 +1,6 @@ #!/usr/bin/env node import chalk from 'chalk'; -import { runTUI } from './tui'; import type { SkillsMetrics } from './types'; import type { RenderContext } from './types/RenderContext'; import type { StatusJSON } from './types/StatusJSON'; @@ -353,6 +352,11 @@ async function main() { const { updatemessage, ...newSettings } = settings; await saveSettings(newSettings); } + // Imported lazily: the TUI pulls in ink/React/yoga-layout, which the + // status line render path never touches. Claude Code re-runs this + // binary every couple of seconds, so keeping that graph off the + // render path is worth the dynamic import here. + const { runTUI } = await import('./tui'); runTUI(); } }