koguma 2.3.4 → 2.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/dev-sync.ts CHANGED
@@ -37,7 +37,22 @@ import {
37
37
  writeContentDir,
38
38
  type ContentTypeInfo
39
39
  } from './content.ts';
40
- import { CONTENT_DIR, SITE_CONFIG_FILE } from './constants.ts';
40
+ import { CONTENT_DIR, SITE_CONFIG_FILE, KOGUMA_DIR } from './constants.ts';
41
+
42
+ // ── HMR signal ─────────────────────────────────────────────────────
43
+ // Writes a timestamp to .koguma/dbhash after each successful sync.
44
+ // The kogumaHMR Vite plugin watches this file and triggers a full
45
+ // browser reload — much cleaner than watching the SQLite WAL files.
46
+
47
+ function touchDbHash(root: string): void {
48
+ try {
49
+ const dir = resolve(root, KOGUMA_DIR);
50
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
51
+ writeFileSync(resolve(dir, 'dbhash'), String(Date.now()));
52
+ } catch {
53
+ // non-critical — worst case Vite won't auto-reload
54
+ }
55
+ }
41
56
 
42
57
  // ── Constants ──────────────────────────────────────────────────────
43
58
 
@@ -153,6 +168,7 @@ function startFileWatcher(opts: FileWatcherOptions): { stop: () => void } {
153
168
  ...(publishAt !== undefined ? { publish_at: publishAt } : {})
154
169
  });
155
170
  markRecentWrite(entryId);
171
+ touchDbHash(root);
156
172
 
157
173
  ok(
158
174
  `${ANSI.DIM}sync:${ANSI.RESET} ${contentTypeId}/${parts.slice(1).join('/')} → D1`
@@ -396,6 +412,7 @@ function startSyncServer(opts: SyncServerOptions): {
396
412
 
397
413
  if (count > 0) {
398
414
  markRecentWrite(entryId);
415
+ touchDbHash(root);
399
416
  ok(
400
417
  `${ANSI.DIM}sync:${ANSI.RESET} D1 → ${payload.contentType}/${slug || 'index'}`
401
418
  );
package/cli/index.ts CHANGED
@@ -521,6 +521,25 @@ async function cmdDev(): Promise<void> {
521
521
  try {
522
522
  const config = await loadSiteConfig(root);
523
523
  devSync = startDevSync(root, dbName, config.contentTypes, { silent: true });
524
+
525
+ // Inject KOGUMA_DEV_SYNC into .dev.vars so the workerd runtime
526
+ // (which doesn't inherit process env) can access it via c.env.
527
+ const devVarsPath = resolve(root, KOGUMA_DIR, '.dev.vars');
528
+ let existing = '';
529
+ if (existsSync(devVarsPath)) {
530
+ existing = readFileSync(devVarsPath, 'utf-8');
531
+ }
532
+ // Remove any stale KOGUMA_DEV_SYNC line, then append the fresh one
533
+ const cleaned = existing
534
+ .split('\n')
535
+ .filter(l => !l.startsWith('KOGUMA_DEV_SYNC='))
536
+ .join('\n')
537
+ .replace(/\n+$/, '');
538
+ const newContent = cleaned
539
+ ? `${cleaned}\nKOGUMA_DEV_SYNC=${devSync.syncUrl}\n`
540
+ : `KOGUMA_DEV_SYNC=${devSync.syncUrl}\n`;
541
+ writeFileSync(devVarsPath, newContent);
542
+
524
543
  sDevSync.stop('Dev sync active (file watcher + sync server)');
525
544
  } catch (e) {
526
545
  sDevSync.stop('Dev sync failed');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koguma",
3
- "version": "2.3.4",
3
+ "version": "2.3.6",
4
4
  "description": "🐻 A little CMS with big heart — schema-driven, runs on Cloudflare's free tier",
5
5
  "type": "module",
6
6
  "license": "MIT",