@nuasite/cms-marker 0.0.46 → 0.0.47

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/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "directory": "packages/cms-marker"
15
15
  },
16
16
  "license": "Apache-2.0",
17
- "version": "0.0.46",
17
+ "version": "0.0.47",
18
18
  "module": "src/index.ts",
19
19
  "types": "src/index.ts",
20
20
  "type": "module",
@@ -5,6 +5,7 @@ import type { Plugin } from 'vite'
5
5
 
6
6
  export interface AstroTransformOptions {
7
7
  markComponents?: boolean
8
+ enabled?: boolean
8
9
  }
9
10
 
10
11
  /**
@@ -15,16 +16,27 @@ export interface AstroTransformOptions {
15
16
  * NOTE: Component marking is NOT done here because modifying component tags
16
17
  * in the raw .astro source breaks Astro's JSX-like parser. Component marking
17
18
  * is done at the HTML output level instead (in dev-middleware and build-processor).
19
+ *
20
+ * IMPORTANT: This plugin should only run in dev mode. During build, modifying
21
+ * .astro source files can cause Vite's build-import-analysis to fail with
22
+ * parsing errors. In build mode, source locations are extracted from Astro's
23
+ * compiler output in build-processor.ts instead.
18
24
  */
19
25
  export function createAstroTransformPlugin(options: AstroTransformOptions = {}): Plugin {
20
26
  // Component marking is intentionally disabled at the transform level
21
27
  // const { markComponents = true } = options;
28
+ const { enabled = true } = options
22
29
 
23
30
  return {
24
31
  name: 'astro-cms-source-injector',
25
32
  enforce: 'pre', // Run before Astro's own transforms
26
33
 
27
34
  async transform(code: string, id: string) {
35
+ // Skip transformation if disabled (e.g., during build mode)
36
+ if (!enabled) {
37
+ return null
38
+ }
39
+
28
40
  if (!id.endsWith('.astro')) {
29
41
  return null
30
42
  }
package/src/index.ts CHANGED
@@ -64,6 +64,7 @@ export default function cmsMarker(options: CmsMarkerOptions = {}): AstroIntegrat
64
64
  componentDefinitions,
65
65
  config,
66
66
  idCounter,
67
+ command,
67
68
  }
68
69
 
69
70
  updateConfig({
@@ -8,10 +8,11 @@ export interface VitePluginContext {
8
8
  componentDefinitions: Record<string, ComponentDefinition>
9
9
  config: Required<CmsMarkerOptions>
10
10
  idCounter: { value: number }
11
+ command: 'dev' | 'build' | 'preview' | 'sync'
11
12
  }
12
13
 
13
14
  export function createVitePlugin(context: VitePluginContext): Plugin[] {
14
- const { manifestWriter, componentDefinitions, config } = context
15
+ const { manifestWriter, componentDefinitions, config, command } = context
15
16
 
16
17
  const virtualManifestPlugin: Plugin = {
17
18
  name: 'cms-marker-virtual-manifest',
@@ -34,8 +35,11 @@ export function createVitePlugin(context: VitePluginContext): Plugin[] {
34
35
  }
35
36
 
36
37
  // Create the Astro transform plugin to inject source location attributes
38
+ // Only enabled in dev mode - during build, source locations are handled
39
+ // in build-processor.ts after HTML is generated
37
40
  const astroTransformPlugin = createAstroTransformPlugin({
38
41
  markComponents: config.markComponents,
42
+ enabled: command === 'dev',
39
43
  })
40
44
 
41
45
  // Note: We cannot use transformIndexHtml for static Astro builds because