@nuasite/cms-marker 0.0.65 → 0.0.67
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/types/build-processor.d.ts +2 -1
- package/dist/types/build-processor.d.ts.map +1 -1
- package/dist/types/component-registry.d.ts.map +1 -1
- package/dist/types/config.d.ts +19 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/dev-middleware.d.ts +10 -2
- package/dist/types/dev-middleware.d.ts.map +1 -1
- package/dist/types/error-collector.d.ts +56 -0
- package/dist/types/error-collector.d.ts.map +1 -0
- package/dist/types/html-processor.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/manifest-writer.d.ts.map +1 -1
- package/dist/types/source-finder.d.ts +18 -3
- package/dist/types/source-finder.d.ts.map +1 -1
- package/dist/types/tailwind-colors.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types.d.ts +2 -4
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/vite-plugin.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/build-processor.ts +73 -19
- package/src/component-registry.ts +2 -0
- package/src/config.ts +29 -0
- package/src/dev-middleware.ts +12 -4
- package/src/error-collector.ts +106 -0
- package/src/html-processor.ts +55 -37
- package/src/index.ts +20 -4
- package/src/manifest-writer.ts +12 -2
- package/src/source-finder.ts +1003 -295
- package/src/tailwind-colors.ts +249 -48
- package/src/types.ts +2 -4
- package/src/vite-plugin.ts +4 -12
- package/dist/types/astro-transform.d.ts +0 -21
- package/dist/types/astro-transform.d.ts.map +0 -1
- package/src/astro-transform.ts +0 -205
package/src/tailwind-colors.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs/promises'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
+
import { getProjectRoot } from './config'
|
|
3
4
|
import type { AvailableColors, AvailableTextStyles, ColorClasses, TailwindColor, TextStyleValue } from './types'
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -45,92 +46,290 @@ export const SPECIAL_COLORS = ['transparent', 'current', 'inherit', 'white', 'bl
|
|
|
45
46
|
*/
|
|
46
47
|
const DEFAULT_COLOR_VALUES: Record<string, Record<string, string>> = {
|
|
47
48
|
slate: {
|
|
48
|
-
'50': '#f8fafc',
|
|
49
|
-
'
|
|
49
|
+
'50': '#f8fafc',
|
|
50
|
+
'100': '#f1f5f9',
|
|
51
|
+
'200': '#e2e8f0',
|
|
52
|
+
'300': '#cbd5e1',
|
|
53
|
+
'400': '#94a3b8',
|
|
54
|
+
'500': '#64748b',
|
|
55
|
+
'600': '#475569',
|
|
56
|
+
'700': '#334155',
|
|
57
|
+
'800': '#1e293b',
|
|
58
|
+
'900': '#0f172a',
|
|
59
|
+
'950': '#020617',
|
|
50
60
|
},
|
|
51
61
|
gray: {
|
|
52
|
-
'50': '#f9fafb',
|
|
53
|
-
'
|
|
62
|
+
'50': '#f9fafb',
|
|
63
|
+
'100': '#f3f4f6',
|
|
64
|
+
'200': '#e5e7eb',
|
|
65
|
+
'300': '#d1d5db',
|
|
66
|
+
'400': '#9ca3af',
|
|
67
|
+
'500': '#6b7280',
|
|
68
|
+
'600': '#4b5563',
|
|
69
|
+
'700': '#374151',
|
|
70
|
+
'800': '#1f2937',
|
|
71
|
+
'900': '#111827',
|
|
72
|
+
'950': '#030712',
|
|
54
73
|
},
|
|
55
74
|
zinc: {
|
|
56
|
-
'50': '#fafafa',
|
|
57
|
-
'
|
|
75
|
+
'50': '#fafafa',
|
|
76
|
+
'100': '#f4f4f5',
|
|
77
|
+
'200': '#e4e4e7',
|
|
78
|
+
'300': '#d4d4d8',
|
|
79
|
+
'400': '#a1a1aa',
|
|
80
|
+
'500': '#71717a',
|
|
81
|
+
'600': '#52525b',
|
|
82
|
+
'700': '#3f3f46',
|
|
83
|
+
'800': '#27272a',
|
|
84
|
+
'900': '#18181b',
|
|
85
|
+
'950': '#09090b',
|
|
58
86
|
},
|
|
59
87
|
neutral: {
|
|
60
|
-
'50': '#fafafa',
|
|
61
|
-
'
|
|
88
|
+
'50': '#fafafa',
|
|
89
|
+
'100': '#f5f5f5',
|
|
90
|
+
'200': '#e5e5e5',
|
|
91
|
+
'300': '#d4d4d4',
|
|
92
|
+
'400': '#a3a3a3',
|
|
93
|
+
'500': '#737373',
|
|
94
|
+
'600': '#525252',
|
|
95
|
+
'700': '#404040',
|
|
96
|
+
'800': '#262626',
|
|
97
|
+
'900': '#171717',
|
|
98
|
+
'950': '#0a0a0a',
|
|
62
99
|
},
|
|
63
100
|
stone: {
|
|
64
|
-
'50': '#fafaf9',
|
|
65
|
-
'
|
|
101
|
+
'50': '#fafaf9',
|
|
102
|
+
'100': '#f5f5f4',
|
|
103
|
+
'200': '#e7e5e4',
|
|
104
|
+
'300': '#d6d3d1',
|
|
105
|
+
'400': '#a8a29e',
|
|
106
|
+
'500': '#78716c',
|
|
107
|
+
'600': '#57534e',
|
|
108
|
+
'700': '#44403c',
|
|
109
|
+
'800': '#292524',
|
|
110
|
+
'900': '#1c1917',
|
|
111
|
+
'950': '#0c0a09',
|
|
66
112
|
},
|
|
67
113
|
red: {
|
|
68
|
-
'50': '#fef2f2',
|
|
69
|
-
'
|
|
114
|
+
'50': '#fef2f2',
|
|
115
|
+
'100': '#fee2e2',
|
|
116
|
+
'200': '#fecaca',
|
|
117
|
+
'300': '#fca5a5',
|
|
118
|
+
'400': '#f87171',
|
|
119
|
+
'500': '#ef4444',
|
|
120
|
+
'600': '#dc2626',
|
|
121
|
+
'700': '#b91c1c',
|
|
122
|
+
'800': '#991b1b',
|
|
123
|
+
'900': '#7f1d1d',
|
|
124
|
+
'950': '#450a0a',
|
|
70
125
|
},
|
|
71
126
|
orange: {
|
|
72
|
-
'50': '#fff7ed',
|
|
73
|
-
'
|
|
127
|
+
'50': '#fff7ed',
|
|
128
|
+
'100': '#ffedd5',
|
|
129
|
+
'200': '#fed7aa',
|
|
130
|
+
'300': '#fdba74',
|
|
131
|
+
'400': '#fb923c',
|
|
132
|
+
'500': '#f97316',
|
|
133
|
+
'600': '#ea580c',
|
|
134
|
+
'700': '#c2410c',
|
|
135
|
+
'800': '#9a3412',
|
|
136
|
+
'900': '#7c2d12',
|
|
137
|
+
'950': '#431407',
|
|
74
138
|
},
|
|
75
139
|
amber: {
|
|
76
|
-
'50': '#fffbeb',
|
|
77
|
-
'
|
|
140
|
+
'50': '#fffbeb',
|
|
141
|
+
'100': '#fef3c7',
|
|
142
|
+
'200': '#fde68a',
|
|
143
|
+
'300': '#fcd34d',
|
|
144
|
+
'400': '#fbbf24',
|
|
145
|
+
'500': '#f59e0b',
|
|
146
|
+
'600': '#d97706',
|
|
147
|
+
'700': '#b45309',
|
|
148
|
+
'800': '#92400e',
|
|
149
|
+
'900': '#78350f',
|
|
150
|
+
'950': '#451a03',
|
|
78
151
|
},
|
|
79
152
|
yellow: {
|
|
80
|
-
'50': '#fefce8',
|
|
81
|
-
'
|
|
153
|
+
'50': '#fefce8',
|
|
154
|
+
'100': '#fef9c3',
|
|
155
|
+
'200': '#fef08a',
|
|
156
|
+
'300': '#fde047',
|
|
157
|
+
'400': '#facc15',
|
|
158
|
+
'500': '#eab308',
|
|
159
|
+
'600': '#ca8a04',
|
|
160
|
+
'700': '#a16207',
|
|
161
|
+
'800': '#854d0e',
|
|
162
|
+
'900': '#713f12',
|
|
163
|
+
'950': '#422006',
|
|
82
164
|
},
|
|
83
165
|
lime: {
|
|
84
|
-
'50': '#f7fee7',
|
|
85
|
-
'
|
|
166
|
+
'50': '#f7fee7',
|
|
167
|
+
'100': '#ecfccb',
|
|
168
|
+
'200': '#d9f99d',
|
|
169
|
+
'300': '#bef264',
|
|
170
|
+
'400': '#a3e635',
|
|
171
|
+
'500': '#84cc16',
|
|
172
|
+
'600': '#65a30d',
|
|
173
|
+
'700': '#4d7c0f',
|
|
174
|
+
'800': '#3f6212',
|
|
175
|
+
'900': '#365314',
|
|
176
|
+
'950': '#1a2e05',
|
|
86
177
|
},
|
|
87
178
|
green: {
|
|
88
|
-
'50': '#f0fdf4',
|
|
89
|
-
'
|
|
179
|
+
'50': '#f0fdf4',
|
|
180
|
+
'100': '#dcfce7',
|
|
181
|
+
'200': '#bbf7d0',
|
|
182
|
+
'300': '#86efac',
|
|
183
|
+
'400': '#4ade80',
|
|
184
|
+
'500': '#22c55e',
|
|
185
|
+
'600': '#16a34a',
|
|
186
|
+
'700': '#15803d',
|
|
187
|
+
'800': '#166534',
|
|
188
|
+
'900': '#14532d',
|
|
189
|
+
'950': '#052e16',
|
|
90
190
|
},
|
|
91
191
|
emerald: {
|
|
92
|
-
'50': '#ecfdf5',
|
|
93
|
-
'
|
|
192
|
+
'50': '#ecfdf5',
|
|
193
|
+
'100': '#d1fae5',
|
|
194
|
+
'200': '#a7f3d0',
|
|
195
|
+
'300': '#6ee7b7',
|
|
196
|
+
'400': '#34d399',
|
|
197
|
+
'500': '#10b981',
|
|
198
|
+
'600': '#059669',
|
|
199
|
+
'700': '#047857',
|
|
200
|
+
'800': '#065f46',
|
|
201
|
+
'900': '#064e3b',
|
|
202
|
+
'950': '#022c22',
|
|
94
203
|
},
|
|
95
204
|
teal: {
|
|
96
|
-
'50': '#f0fdfa',
|
|
97
|
-
'
|
|
205
|
+
'50': '#f0fdfa',
|
|
206
|
+
'100': '#ccfbf1',
|
|
207
|
+
'200': '#99f6e4',
|
|
208
|
+
'300': '#5eead4',
|
|
209
|
+
'400': '#2dd4bf',
|
|
210
|
+
'500': '#14b8a6',
|
|
211
|
+
'600': '#0d9488',
|
|
212
|
+
'700': '#0f766e',
|
|
213
|
+
'800': '#115e59',
|
|
214
|
+
'900': '#134e4a',
|
|
215
|
+
'950': '#042f2e',
|
|
98
216
|
},
|
|
99
217
|
cyan: {
|
|
100
|
-
'50': '#ecfeff',
|
|
101
|
-
'
|
|
218
|
+
'50': '#ecfeff',
|
|
219
|
+
'100': '#cffafe',
|
|
220
|
+
'200': '#a5f3fc',
|
|
221
|
+
'300': '#67e8f9',
|
|
222
|
+
'400': '#22d3ee',
|
|
223
|
+
'500': '#06b6d4',
|
|
224
|
+
'600': '#0891b2',
|
|
225
|
+
'700': '#0e7490',
|
|
226
|
+
'800': '#155e75',
|
|
227
|
+
'900': '#164e63',
|
|
228
|
+
'950': '#083344',
|
|
102
229
|
},
|
|
103
230
|
sky: {
|
|
104
|
-
'50': '#f0f9ff',
|
|
105
|
-
'
|
|
231
|
+
'50': '#f0f9ff',
|
|
232
|
+
'100': '#e0f2fe',
|
|
233
|
+
'200': '#bae6fd',
|
|
234
|
+
'300': '#7dd3fc',
|
|
235
|
+
'400': '#38bdf8',
|
|
236
|
+
'500': '#0ea5e9',
|
|
237
|
+
'600': '#0284c7',
|
|
238
|
+
'700': '#0369a1',
|
|
239
|
+
'800': '#075985',
|
|
240
|
+
'900': '#0c4a6e',
|
|
241
|
+
'950': '#082f49',
|
|
106
242
|
},
|
|
107
243
|
blue: {
|
|
108
|
-
'50': '#eff6ff',
|
|
109
|
-
'
|
|
244
|
+
'50': '#eff6ff',
|
|
245
|
+
'100': '#dbeafe',
|
|
246
|
+
'200': '#bfdbfe',
|
|
247
|
+
'300': '#93c5fd',
|
|
248
|
+
'400': '#60a5fa',
|
|
249
|
+
'500': '#3b82f6',
|
|
250
|
+
'600': '#2563eb',
|
|
251
|
+
'700': '#1d4ed8',
|
|
252
|
+
'800': '#1e40af',
|
|
253
|
+
'900': '#1e3a8a',
|
|
254
|
+
'950': '#172554',
|
|
110
255
|
},
|
|
111
256
|
indigo: {
|
|
112
|
-
'50': '#eef2ff',
|
|
113
|
-
'
|
|
257
|
+
'50': '#eef2ff',
|
|
258
|
+
'100': '#e0e7ff',
|
|
259
|
+
'200': '#c7d2fe',
|
|
260
|
+
'300': '#a5b4fc',
|
|
261
|
+
'400': '#818cf8',
|
|
262
|
+
'500': '#6366f1',
|
|
263
|
+
'600': '#4f46e5',
|
|
264
|
+
'700': '#4338ca',
|
|
265
|
+
'800': '#3730a3',
|
|
266
|
+
'900': '#312e81',
|
|
267
|
+
'950': '#1e1b4b',
|
|
114
268
|
},
|
|
115
269
|
violet: {
|
|
116
|
-
'50': '#f5f3ff',
|
|
117
|
-
'
|
|
270
|
+
'50': '#f5f3ff',
|
|
271
|
+
'100': '#ede9fe',
|
|
272
|
+
'200': '#ddd6fe',
|
|
273
|
+
'300': '#c4b5fd',
|
|
274
|
+
'400': '#a78bfa',
|
|
275
|
+
'500': '#8b5cf6',
|
|
276
|
+
'600': '#7c3aed',
|
|
277
|
+
'700': '#6d28d9',
|
|
278
|
+
'800': '#5b21b6',
|
|
279
|
+
'900': '#4c1d95',
|
|
280
|
+
'950': '#2e1065',
|
|
118
281
|
},
|
|
119
282
|
purple: {
|
|
120
|
-
'50': '#faf5ff',
|
|
121
|
-
'
|
|
283
|
+
'50': '#faf5ff',
|
|
284
|
+
'100': '#f3e8ff',
|
|
285
|
+
'200': '#e9d5ff',
|
|
286
|
+
'300': '#d8b4fe',
|
|
287
|
+
'400': '#c084fc',
|
|
288
|
+
'500': '#a855f7',
|
|
289
|
+
'600': '#9333ea',
|
|
290
|
+
'700': '#7e22ce',
|
|
291
|
+
'800': '#6b21a8',
|
|
292
|
+
'900': '#581c87',
|
|
293
|
+
'950': '#3b0764',
|
|
122
294
|
},
|
|
123
295
|
fuchsia: {
|
|
124
|
-
'50': '#fdf4ff',
|
|
125
|
-
'
|
|
296
|
+
'50': '#fdf4ff',
|
|
297
|
+
'100': '#fae8ff',
|
|
298
|
+
'200': '#f5d0fe',
|
|
299
|
+
'300': '#f0abfc',
|
|
300
|
+
'400': '#e879f9',
|
|
301
|
+
'500': '#d946ef',
|
|
302
|
+
'600': '#c026d3',
|
|
303
|
+
'700': '#a21caf',
|
|
304
|
+
'800': '#86198f',
|
|
305
|
+
'900': '#701a75',
|
|
306
|
+
'950': '#4a044e',
|
|
126
307
|
},
|
|
127
308
|
pink: {
|
|
128
|
-
'50': '#fdf2f8',
|
|
129
|
-
'
|
|
309
|
+
'50': '#fdf2f8',
|
|
310
|
+
'100': '#fce7f3',
|
|
311
|
+
'200': '#fbcfe8',
|
|
312
|
+
'300': '#f9a8d4',
|
|
313
|
+
'400': '#f472b6',
|
|
314
|
+
'500': '#ec4899',
|
|
315
|
+
'600': '#db2777',
|
|
316
|
+
'700': '#be185d',
|
|
317
|
+
'800': '#9d174d',
|
|
318
|
+
'900': '#831843',
|
|
319
|
+
'950': '#500724',
|
|
130
320
|
},
|
|
131
321
|
rose: {
|
|
132
|
-
'50': '#fff1f2',
|
|
133
|
-
'
|
|
322
|
+
'50': '#fff1f2',
|
|
323
|
+
'100': '#ffe4e6',
|
|
324
|
+
'200': '#fecdd3',
|
|
325
|
+
'300': '#fda4af',
|
|
326
|
+
'400': '#fb7185',
|
|
327
|
+
'500': '#f43f5e',
|
|
328
|
+
'600': '#e11d48',
|
|
329
|
+
'700': '#be123c',
|
|
330
|
+
'800': '#9f1239',
|
|
331
|
+
'900': '#881337',
|
|
332
|
+
'950': '#4c0519',
|
|
134
333
|
},
|
|
135
334
|
}
|
|
136
335
|
|
|
@@ -214,12 +413,13 @@ const COLOR_CLASS_PATTERNS = {
|
|
|
214
413
|
border: buildColorPattern('border'),
|
|
215
414
|
hoverBg: buildColorPattern('hover:bg'),
|
|
216
415
|
hoverText: buildColorPattern('hover:text'),
|
|
416
|
+
hoverBorder: buildColorPattern('hover:border'),
|
|
217
417
|
}
|
|
218
418
|
|
|
219
419
|
/**
|
|
220
420
|
* Parse Tailwind v4 CSS config to extract available colors with their values.
|
|
221
421
|
*/
|
|
222
|
-
export async function parseTailwindConfig(projectRoot: string =
|
|
422
|
+
export async function parseTailwindConfig(projectRoot: string = getProjectRoot()): Promise<AvailableColors> {
|
|
223
423
|
// Tailwind v4 CSS files to search
|
|
224
424
|
const cssFiles = [
|
|
225
425
|
'src/styles/global.css',
|
|
@@ -324,7 +524,7 @@ function extractColorsFromCss(content: string): TailwindColor[] {
|
|
|
324
524
|
/**
|
|
325
525
|
* Parse Tailwind v4 CSS config to extract available text styles.
|
|
326
526
|
*/
|
|
327
|
-
export async function parseTextStyles(projectRoot: string =
|
|
527
|
+
export async function parseTextStyles(projectRoot: string = getProjectRoot()): Promise<AvailableTextStyles> {
|
|
328
528
|
// Tailwind v4 CSS files to search
|
|
329
529
|
const cssFiles = [
|
|
330
530
|
'src/styles/global.css',
|
|
@@ -471,8 +671,9 @@ export function extractColorClasses(classAttr: string | null | undefined): Color
|
|
|
471
671
|
const match = cls.match(pattern)
|
|
472
672
|
if (match) {
|
|
473
673
|
allColorClasses.push(cls)
|
|
474
|
-
|
|
475
|
-
|
|
674
|
+
const colorKey = key as keyof Omit<ColorClasses, 'allColorClasses'>
|
|
675
|
+
if (!(colorKey in colorClasses)) {
|
|
676
|
+
colorClasses[colorKey] = cls
|
|
476
677
|
}
|
|
477
678
|
break
|
|
478
679
|
}
|
package/src/types.ts
CHANGED
|
@@ -91,6 +91,8 @@ export interface ColorClasses {
|
|
|
91
91
|
hoverBg?: string
|
|
92
92
|
/** Hover text color class (e.g., 'hover:text-gray-100') */
|
|
93
93
|
hoverText?: string
|
|
94
|
+
/** Hover border color class (e.g., 'hover:border-blue-700') */
|
|
95
|
+
hoverBorder?: string
|
|
94
96
|
/** All color-related classes as found in the element */
|
|
95
97
|
allColorClasses?: string[]
|
|
96
98
|
}
|
|
@@ -147,10 +149,6 @@ export interface ManifestEntry {
|
|
|
147
149
|
collectionSlug?: string
|
|
148
150
|
/** Path to the markdown content file (e.g., 'src/content/blog/my-post.md') */
|
|
149
151
|
contentPath?: string
|
|
150
|
-
/** Image source URL (for image entries) - deprecated, use imageMetadata */
|
|
151
|
-
imageSrc?: string
|
|
152
|
-
/** Image alt text (for image entries) - deprecated, use imageMetadata */
|
|
153
|
-
imageAlt?: string
|
|
154
152
|
|
|
155
153
|
// === Robustness fields ===
|
|
156
154
|
|
package/src/vite-plugin.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Plugin } from 'vite'
|
|
2
|
-
import { createAstroTransformPlugin } from './astro-transform'
|
|
3
2
|
import type { ManifestWriter } from './manifest-writer'
|
|
4
3
|
import type { CmsMarkerOptions, ComponentDefinition } from './types'
|
|
5
4
|
|
|
@@ -12,7 +11,7 @@ export interface VitePluginContext {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
export function createVitePlugin(context: VitePluginContext): Plugin[] {
|
|
15
|
-
const { manifestWriter, componentDefinitions
|
|
14
|
+
const { manifestWriter, componentDefinitions } = context
|
|
16
15
|
|
|
17
16
|
const virtualManifestPlugin: Plugin = {
|
|
18
17
|
name: 'cms-marker-virtual-manifest',
|
|
@@ -34,17 +33,10 @@ export function createVitePlugin(context: VitePluginContext): Plugin[] {
|
|
|
34
33
|
},
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
// Create the Astro transform plugin to inject source location attributes
|
|
38
|
-
// NOTE: Disabled - Astro's native compiler already injects source location
|
|
39
|
-
// attributes (data-astro-source-file, data-astro-source-loc) in dev mode.
|
|
40
|
-
// Our html-processor recognizes these native attributes automatically.
|
|
41
|
-
const astroTransformPlugin = createAstroTransformPlugin({
|
|
42
|
-
markComponents: config.markComponents,
|
|
43
|
-
enabled: false, // Not needed - Astro provides source attributes natively
|
|
44
|
-
})
|
|
45
|
-
|
|
46
36
|
// Note: We cannot use transformIndexHtml for static Astro builds because
|
|
47
37
|
// Astro generates HTML files directly without going through Vite's HTML pipeline.
|
|
48
38
|
// HTML processing is done in build-processor.ts after pages are generated.
|
|
49
|
-
|
|
39
|
+
// Source location attributes are provided natively by Astro's compiler
|
|
40
|
+
// (data-astro-source-file, data-astro-source-loc) in dev mode.
|
|
41
|
+
return [virtualManifestPlugin]
|
|
50
42
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
export interface AstroTransformOptions {
|
|
3
|
-
markComponents?: boolean;
|
|
4
|
-
enabled?: boolean;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Vite plugin that transforms .astro files to inject source location metadata.
|
|
8
|
-
*
|
|
9
|
-
* NOTE: This plugin is currently DISABLED because Astro's native compiler already
|
|
10
|
-
* injects `data-astro-source-file` and `data-astro-source-loc` attributes in dev mode.
|
|
11
|
-
* Our html-processor now recognizes both Astro's native attributes and our custom ones.
|
|
12
|
-
*
|
|
13
|
-
* HISTORICAL CONTEXT: This plugin was created before we discovered Astro's native
|
|
14
|
-
* source tracking. It caused Vite's build-import-analysis to fail with parsing errors
|
|
15
|
-
* because modifying .astro source files confuses Vite's JavaScript parser.
|
|
16
|
-
*
|
|
17
|
-
* KEEPING FOR: Potential future use cases where custom source attribute injection
|
|
18
|
-
* might be needed, or for testing purposes.
|
|
19
|
-
*/
|
|
20
|
-
export declare function createAstroTransformPlugin(options?: AstroTransformOptions): Plugin;
|
|
21
|
-
//# sourceMappingURL=astro-transform.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"astro-transform.d.ts","sourceRoot":"","sources":["../../src/astro-transform.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,MAAM,WAAW,qBAAqB;IACrC,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAgDtF"}
|
package/src/astro-transform.ts
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { parse as parseAstro } from '@astrojs/compiler'
|
|
2
|
-
import fs from 'node:fs/promises'
|
|
3
|
-
import path from 'node:path'
|
|
4
|
-
import type { Plugin } from 'vite'
|
|
5
|
-
|
|
6
|
-
export interface AstroTransformOptions {
|
|
7
|
-
markComponents?: boolean
|
|
8
|
-
enabled?: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Vite plugin that transforms .astro files to inject source location metadata.
|
|
13
|
-
*
|
|
14
|
-
* NOTE: This plugin is currently DISABLED because Astro's native compiler already
|
|
15
|
-
* injects `data-astro-source-file` and `data-astro-source-loc` attributes in dev mode.
|
|
16
|
-
* Our html-processor now recognizes both Astro's native attributes and our custom ones.
|
|
17
|
-
*
|
|
18
|
-
* HISTORICAL CONTEXT: This plugin was created before we discovered Astro's native
|
|
19
|
-
* source tracking. It caused Vite's build-import-analysis to fail with parsing errors
|
|
20
|
-
* because modifying .astro source files confuses Vite's JavaScript parser.
|
|
21
|
-
*
|
|
22
|
-
* KEEPING FOR: Potential future use cases where custom source attribute injection
|
|
23
|
-
* might be needed, or for testing purposes.
|
|
24
|
-
*/
|
|
25
|
-
export function createAstroTransformPlugin(options: AstroTransformOptions = {}): Plugin {
|
|
26
|
-
// Component marking is intentionally disabled at the transform level
|
|
27
|
-
// const { markComponents = true } = options;
|
|
28
|
-
const { enabled = true } = options
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
name: 'astro-cms-source-injector',
|
|
32
|
-
enforce: 'pre', // Run before Astro's own transforms
|
|
33
|
-
|
|
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
|
-
|
|
40
|
-
if (!id.endsWith('.astro')) {
|
|
41
|
-
return null
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (id.includes('node_modules')) {
|
|
45
|
-
return null
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
const rawCode = await fs.readFile(id, 'utf-8')
|
|
50
|
-
const relativePath = path.relative(process.cwd(), id)
|
|
51
|
-
const result = await parseAstro(rawCode, { position: true })
|
|
52
|
-
|
|
53
|
-
if (!result.ast) {
|
|
54
|
-
return null
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const transformed = injectSourceAttributes(rawCode, result.ast, relativePath)
|
|
58
|
-
|
|
59
|
-
if (transformed !== rawCode) {
|
|
60
|
-
return {
|
|
61
|
-
code: transformed,
|
|
62
|
-
map: null,
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return null
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.warn(`[astro-cms-marker] Failed to transform ${id}:`, error)
|
|
69
|
-
return null
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Inject source location attributes into HTML elements
|
|
77
|
-
* NOTE: Component marking is NOT done here - it breaks Astro's parser
|
|
78
|
-
*/
|
|
79
|
-
function injectSourceAttributes(code: string, ast: any, filePath: string): string {
|
|
80
|
-
const lines = code.split('\n')
|
|
81
|
-
const modifications: Array<{ line: number; column: number; insertion: string }> = []
|
|
82
|
-
|
|
83
|
-
// Find the template section (after frontmatter)
|
|
84
|
-
let inFrontmatter = false
|
|
85
|
-
let frontmatterEnd = -1
|
|
86
|
-
|
|
87
|
-
for (let i = 0; i < lines.length; i++) {
|
|
88
|
-
if (lines[i]?.trim() === '---') {
|
|
89
|
-
if (!inFrontmatter) {
|
|
90
|
-
inFrontmatter = true
|
|
91
|
-
} else {
|
|
92
|
-
frontmatterEnd = i
|
|
93
|
-
break
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// If no frontmatter, start from line 0 (all lines are template)
|
|
99
|
-
if (frontmatterEnd === -1) {
|
|
100
|
-
frontmatterEnd = -1 // Will make check start.line > 0
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Walk the AST and collect modifications
|
|
104
|
-
const collectElements = (node: any, depth: number = 0) => {
|
|
105
|
-
if (!node) {
|
|
106
|
-
return
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Only process regular HTML elements, NOT components
|
|
110
|
-
if (node.type === 'element' && node.position) {
|
|
111
|
-
const { start } = node.position
|
|
112
|
-
const tagName = node.name?.toLowerCase()
|
|
113
|
-
|
|
114
|
-
// Only process elements in template section (after frontmatter or from start if no frontmatter)
|
|
115
|
-
const templateStartLine = frontmatterEnd === -1 ? 0 : frontmatterEnd + 1
|
|
116
|
-
if (start.line > templateStartLine) {
|
|
117
|
-
// Skip certain elements
|
|
118
|
-
if (['html', 'head', 'body', 'script', 'style', 'slot', 'fragment'].includes(tagName)) {
|
|
119
|
-
// Still process children
|
|
120
|
-
if (node.children && Array.isArray(node.children)) {
|
|
121
|
-
for (const child of node.children) {
|
|
122
|
-
collectElements(child, depth + 1)
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Find where to insert the attribute (after tag name, before other attributes or >)
|
|
129
|
-
const lineIndex = start.line - 1
|
|
130
|
-
if (lineIndex < 0 || lineIndex >= lines.length) {
|
|
131
|
-
return
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const line = lines[lineIndex]
|
|
135
|
-
const tagStartCol = start.column - 1
|
|
136
|
-
|
|
137
|
-
// Find the position after the tag name
|
|
138
|
-
const tagMatch = line?.slice(tagStartCol).match(/^<(\w+)/)
|
|
139
|
-
if (!tagMatch) {
|
|
140
|
-
return
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const insertCol = tagStartCol + tagMatch[0].length
|
|
144
|
-
const sourceAttr = ` data-astro-source-file="${filePath}" data-astro-source-line="${start.line}"`
|
|
145
|
-
|
|
146
|
-
modifications.push({
|
|
147
|
-
line: lineIndex,
|
|
148
|
-
column: insertCol,
|
|
149
|
-
insertion: sourceAttr,
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Recursively process children
|
|
155
|
-
if (node.children && Array.isArray(node.children)) {
|
|
156
|
-
for (const child of node.children) {
|
|
157
|
-
collectElements(child, depth + 1)
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Start walking from root children
|
|
163
|
-
if (ast.children && Array.isArray(ast.children)) {
|
|
164
|
-
for (const child of ast.children) {
|
|
165
|
-
collectElements(child, 0)
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Sort modifications by position (reverse order so we can apply them without recalculating positions)
|
|
170
|
-
modifications.sort((a, b) => {
|
|
171
|
-
if (a.line !== b.line) {
|
|
172
|
-
return b.line - a.line
|
|
173
|
-
}
|
|
174
|
-
return b.column - a.column
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
// Apply modifications
|
|
178
|
-
const modifiedLines = [...lines]
|
|
179
|
-
for (const mod of modifications) {
|
|
180
|
-
const line = modifiedLines[mod.line]
|
|
181
|
-
|
|
182
|
-
// Validate line exists - if not, there's a bug in AST positions or bounds checking
|
|
183
|
-
if (line === undefined) {
|
|
184
|
-
console.error(
|
|
185
|
-
`[astro-cms-marker] Invalid modification at line ${mod.line + 1} in ${filePath}. `
|
|
186
|
-
+ `This indicates a bug in @astrojs/compiler AST positions or bounds checking. Skipping modification.`,
|
|
187
|
-
)
|
|
188
|
-
continue
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Validate column is within line bounds
|
|
192
|
-
if (mod.column < 0 || mod.column > line.length) {
|
|
193
|
-
console.error(
|
|
194
|
-
`[astro-cms-marker] Invalid column ${mod.column} at line ${mod.line + 1} in ${filePath}. `
|
|
195
|
-
+ `Line length is ${line.length}. Skipping modification.`,
|
|
196
|
-
)
|
|
197
|
-
continue
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Apply the modification safely
|
|
201
|
-
modifiedLines[mod.line] = line.slice(0, mod.column) + mod.insertion + line.slice(mod.column)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return modifiedLines.join('\n')
|
|
205
|
-
}
|