@nuasite/cms 0.22.1 → 0.23.0

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/dist/editor.js CHANGED
@@ -381,7 +381,7 @@ function CS(t, e) {
381
381
  function ES(t, e) {
382
382
  return typeof e == "function" ? e(t) : e;
383
383
  }
384
- const J_ = "0.22.1", j_ = J_, ct = {
384
+ const J_ = "0.23.0", j_ = J_, ct = {
385
385
  /** Highlight overlay for hovered elements */
386
386
  HIGHLIGHT: 2147483644,
387
387
  /** Hover outline for elements/components */
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/astro-cms"
15
15
  },
16
16
  "license": "Apache-2.0",
17
- "version": "0.22.1",
17
+ "version": "0.23.0",
18
18
  "module": "src/index.ts",
19
19
  "types": "src/index.ts",
20
20
  "type": "module",
package/src/index.ts CHANGED
@@ -58,9 +58,9 @@ export interface NuaCmsOptions extends CmsMarkerOptions {
58
58
  }>
59
59
  /**
60
60
  * Enable polling for file watching.
61
- * Ensures reliable change detection after CMS edits.
62
- * Set to `false` to use native fs events instead.
63
- * @default true
61
+ * Set to `true` on filesystems that don't support native events (e.g. network mounts).
62
+ * E2B sandboxes use ext4 with full inotify support, so polling is unnecessary.
63
+ * @default false
64
64
  */
65
65
  usePolling?: boolean
66
66
  }
@@ -85,7 +85,7 @@ export default function nuaCms(options: NuaCmsOptions = {}): AstroIntegration {
85
85
  componentDirs = ['src/components'],
86
86
  contentDir = 'src/content',
87
87
  mdxComponentDirs,
88
- usePolling = true,
88
+ usePolling = false,
89
89
  seo = { trackSeo: true, markTitle: true, parseJsonLd: true },
90
90
  } = options
91
91
 
@@ -180,7 +180,6 @@ export default function nuaCms(options: NuaCmsOptions = {}): AstroIntegration {
180
180
  config: markerConfig,
181
181
  idCounter,
182
182
  command,
183
- contentDir,
184
183
  }
185
184
 
186
185
  const vitePlugins: any[] = [...(createVitePlugin(pluginContext) as any)]
@@ -1,3 +1,5 @@
1
+ import { watch } from 'node:fs'
2
+ import { join } from 'node:path'
1
3
  import type { Plugin } from 'vite'
2
4
  import { expectedDeletions } from './dev-middleware'
3
5
  import type { ManifestWriter } from './manifest-writer'
@@ -11,11 +13,10 @@ export interface VitePluginContext {
11
13
  config: Required<CmsMarkerOptions>
12
14
  idCounter: { value: number }
13
15
  command: 'dev' | 'build' | 'preview' | 'sync'
14
- contentDir: string
15
16
  }
16
17
 
17
18
  export function createVitePlugin(context: VitePluginContext): Plugin[] {
18
- const { manifestWriter, componentDefinitions, command, contentDir } = context
19
+ const { manifestWriter, componentDefinitions, command } = context
19
20
 
20
21
  const virtualManifestPlugin: Plugin = {
21
22
  name: 'cms-marker-virtual-manifest',
@@ -79,21 +80,52 @@ export function createVitePlugin(context: VitePluginContext): Plugin[] {
79
80
  },
80
81
  }
81
82
 
82
- // Suppress immediate HMR page reload for content collection files.
83
- // Without this, Astro's vite-plugin-content-imports invalidates the module and
84
- // triggers a browser reload BEFORE the content layer has flushed the updated
85
- // data store to disk causing a brief render of stale frontmatter data.
86
- // By returning [] the module graph still marks the module stale (so the MDX body
87
- // gets re-compiled on next request), but the browser reload is deferred until
88
- // the content layer writes data-store.json and fires `astro:content-changed`.
89
- const contentHmrPlugin: Plugin = {
90
- name: 'cms-defer-content-hmr',
91
- enforce: 'pre',
92
- handleHotUpdate({ file }) {
83
+ // Vite's bundled chokidar 3.6.0 fails to detect changes to .astro/data-store.json
84
+ // (added via watcher.add() in Astro's vite-plugin-content-virtual-mod).
85
+ // Without this, content collection edits update the data store on disk but the
86
+ // browser never receives a full-reload because Vite's watcher never fires "change"
87
+ // for that file. We use native fs.watch as a reliable fallback.
88
+ const dataStoreWatchPlugin: Plugin = {
89
+ name: 'cms-data-store-watch',
90
+ configureServer(server) {
93
91
  if (command !== 'dev') return
94
- const contentSuffix = `/${contentDir}/`
95
- if (file.includes(contentSuffix)) {
96
- return []
92
+ const root = server.config.root
93
+ const dataStorePath = join(root, '.astro', 'data-store.json')
94
+ let fsWatcher: ReturnType<typeof watch> | undefined
95
+ let debounce: ReturnType<typeof setTimeout> | undefined
96
+
97
+ const invalidate = () => {
98
+ // Replicate Astro's invalidateDataStore which never fires because
99
+ // Vite's bundled chokidar 3.6.0 misses atomic-write changes.
100
+ const ssr = server.environments.ssr
101
+ const mod = ssr.moduleGraph.getModuleById('\0astro:data-store')
102
+ if (mod) {
103
+ ssr.moduleGraph.invalidateModule(mod, undefined, Date.now(), true)
104
+ }
105
+ ssr.hot.send('astro:content-changed', {})
106
+ server.environments.client.hot.send({ type: 'full-reload', path: '*' })
107
+ }
108
+
109
+ const startWatching = () => {
110
+ try {
111
+ fsWatcher = watch(dataStorePath, () => {
112
+ clearTimeout(debounce)
113
+ debounce = setTimeout(invalidate, 80)
114
+ })
115
+ } catch {
116
+ // File doesn't exist yet — retry when it appears
117
+ setTimeout(startWatching, 2000)
118
+ }
119
+ }
120
+
121
+ // Data store is created during content sync, which runs after server start
122
+ setTimeout(startWatching, 3000)
123
+
124
+ const origClose = server.close.bind(server)
125
+ server.close = async () => {
126
+ fsWatcher?.close()
127
+ clearTimeout(debounce)
128
+ return origClose()
97
129
  }
98
130
  },
99
131
  }
@@ -103,5 +135,5 @@ export function createVitePlugin(context: VitePluginContext): Plugin[] {
103
135
  // HTML processing is done in build-processor.ts after pages are generated.
104
136
  // Source location attributes are provided natively by Astro's compiler
105
137
  // (data-astro-source-file, data-astro-source-loc) in dev mode.
106
- return [virtualManifestPlugin, watcherPlugin, contentHmrPlugin, createArrayTransformPlugin()]
138
+ return [virtualManifestPlugin, watcherPlugin, dataStoreWatchPlugin, createArrayTransformPlugin()]
107
139
  }