@nuasite/cms-core 0.64.3 → 0.65.1
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/asset-paths.d.ts.map +1 -0
- package/dist/asset-paths.js +55 -0
- package/dist/astro-source-analysis.d.ts.map +1 -0
- package/dist/astro-source-analysis.js +503 -0
- package/dist/byte-range.d.ts.map +1 -0
- package/dist/byte-range.js +31 -0
- package/dist/{types/check-entries.d.ts → check-entries.d.ts} +3 -3
- package/dist/check-entries.d.ts.map +1 -0
- package/dist/check-entries.js +98 -0
- package/dist/{types/check-live.d.ts → check-live.d.ts} +4 -4
- package/dist/check-live.d.ts.map +1 -0
- package/dist/check-live.js +49 -0
- package/dist/{types/check-shape.d.ts → check-shape.d.ts} +4 -4
- package/dist/check-shape.d.ts.map +1 -0
- package/dist/check-shape.js +119 -0
- package/dist/{types/check-write.d.ts → check-write.d.ts} +4 -4
- package/dist/check-write.d.ts.map +1 -0
- package/dist/check-write.js +273 -0
- package/dist/{types/check.d.ts → check.d.ts} +2 -2
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +366 -0
- package/dist/{types/collection-scanner.d.ts → collection-scanner.d.ts} +2 -2
- package/dist/collection-scanner.d.ts.map +1 -0
- package/dist/collection-scanner.js +1483 -0
- package/dist/{types/component-registry.d.ts → component-registry.d.ts} +1 -1
- package/dist/component-registry.d.ts.map +1 -0
- package/dist/component-registry.js +271 -0
- package/dist/{types/content-config-ast.d.ts → content-config-ast.d.ts} +1 -1
- package/dist/content-config-ast.d.ts.map +1 -0
- package/dist/content-config-ast.js +1614 -0
- package/dist/{types/core.d.ts → core.d.ts} +3 -3
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +94 -0
- package/dist/editor-write-model.d.ts.map +1 -0
- package/dist/editor-write-model.js +101 -0
- package/dist/fs/glob.d.ts.map +1 -0
- package/dist/fs/glob.js +79 -0
- package/dist/{types/fs → fs}/node-fs.d.ts +1 -1
- package/dist/fs/node-fs.d.ts.map +1 -0
- package/dist/fs/node-fs.js +199 -0
- package/dist/{types/fs → fs}/staged.d.ts +1 -1
- package/dist/fs/staged.d.ts.map +1 -0
- package/dist/fs/staged.js +203 -0
- package/dist/fs/types.d.ts.map +1 -0
- package/dist/fs/types.js +0 -0
- package/dist/{types/handlers → handlers}/entry-ops.d.ts +2 -2
- package/dist/handlers/entry-ops.d.ts.map +1 -0
- package/dist/handlers/entry-ops.js +846 -0
- package/dist/{types/handlers → handlers}/page-ops.d.ts +1 -1
- package/dist/handlers/page-ops.d.ts.map +1 -0
- package/dist/handlers/page-ops.js +165 -0
- package/dist/{types/handlers → handlers}/redirect-ops.d.ts +1 -1
- package/dist/handlers/redirect-ops.d.ts.map +1 -0
- package/dist/handlers/redirect-ops.js +111 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/media/contember.d.ts.map +1 -0
- package/dist/media/contember.js +79 -0
- package/dist/media/errors.d.ts.map +1 -0
- package/dist/media/errors.js +22 -0
- package/dist/{types/media → media}/file-system.d.ts +1 -1
- package/dist/media/file-system.d.ts.map +1 -0
- package/dist/media/file-system.js +124 -0
- package/dist/{types/media → media}/index.d.ts +8 -8
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/index.js +8 -0
- package/dist/media/local.d.ts.map +1 -0
- package/dist/media/local.js +209 -0
- package/dist/media/mime.d.ts.map +1 -0
- package/dist/media/mime.js +21 -0
- package/dist/media/names.d.ts.map +1 -0
- package/dist/media/names.js +23 -0
- package/dist/{types/media → media}/project-images.d.ts +1 -1
- package/dist/media/project-images.d.ts.map +1 -0
- package/dist/media/project-images.js +99 -0
- package/dist/media/s3.d.ts.map +1 -0
- package/dist/media/s3.js +160 -0
- package/dist/media/type-filter.d.ts.map +1 -0
- package/dist/media/type-filter.js +164 -0
- package/dist/{types/portable.d.ts → portable.d.ts} +25 -25
- package/dist/portable.d.ts.map +1 -0
- package/dist/portable.js +27 -0
- package/dist/{types/project-config-ast.d.ts → project-config-ast.d.ts} +1 -1
- package/dist/project-config-ast.d.ts.map +1 -0
- package/dist/project-config-ast.js +324 -0
- package/dist/public-static-file.d.ts.map +1 -0
- package/dist/public-static-file.js +40 -0
- package/dist/redirects.d.ts.map +1 -0
- package/dist/redirects.js +185 -0
- package/dist/route-scan.d.ts.map +1 -0
- package/dist/route-scan.js +23 -0
- package/dist/schema-port.d.ts.map +1 -0
- package/dist/schema-port.js +30 -0
- package/dist/{types/schema-probe.d.ts → schema-probe.d.ts} +2 -2
- package/dist/schema-probe.d.ts.map +1 -0
- package/dist/schema-probe.js +119 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +163 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +12 -12
- package/src/check-entries.ts +4 -4
- package/src/check-live.ts +4 -4
- package/src/check-shape.ts +5 -5
- package/src/check-write.ts +6 -6
- package/src/check.ts +15 -9
- package/src/collection-scanner.ts +3 -3
- package/src/component-registry.ts +1 -1
- package/src/content-config-ast.ts +1 -1
- package/src/core.ts +8 -8
- package/src/editor-write-model.ts +1 -1
- package/src/fs/node-fs.ts +2 -2
- package/src/fs/staged.ts +6 -3
- package/src/handlers/entry-ops.ts +7 -7
- package/src/handlers/page-ops.ts +2 -2
- package/src/handlers/redirect-ops.ts +2 -2
- package/src/index.ts +4 -4
- package/src/media/contember.ts +1 -1
- package/src/media/file-system.ts +4 -4
- package/src/media/index.ts +8 -8
- package/src/media/local.ts +3 -3
- package/src/media/project-images.ts +2 -2
- package/src/media/s3.ts +3 -3
- package/src/portable.ts +25 -25
- package/src/project-config-ast.ts +1 -1
- package/src/route-scan.ts +1 -1
- package/src/schema-probe.ts +2 -2
- package/src/tsconfig.json +5 -1
- package/dist/types/asset-paths.d.ts.map +0 -1
- package/dist/types/astro-source-analysis.d.ts.map +0 -1
- package/dist/types/byte-range.d.ts.map +0 -1
- package/dist/types/check-entries.d.ts.map +0 -1
- package/dist/types/check-live.d.ts.map +0 -1
- package/dist/types/check-shape.d.ts.map +0 -1
- package/dist/types/check-write.d.ts.map +0 -1
- package/dist/types/check.d.ts.map +0 -1
- package/dist/types/collection-scanner.d.ts.map +0 -1
- package/dist/types/component-registry.d.ts.map +0 -1
- package/dist/types/content-config-ast.d.ts.map +0 -1
- package/dist/types/core.d.ts.map +0 -1
- package/dist/types/editor-write-model.d.ts.map +0 -1
- package/dist/types/fs/glob.d.ts.map +0 -1
- package/dist/types/fs/node-fs.d.ts.map +0 -1
- package/dist/types/fs/staged.d.ts.map +0 -1
- package/dist/types/fs/types.d.ts.map +0 -1
- package/dist/types/handlers/entry-ops.d.ts.map +0 -1
- package/dist/types/handlers/page-ops.d.ts.map +0 -1
- package/dist/types/handlers/redirect-ops.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/media/contember.d.ts.map +0 -1
- package/dist/types/media/errors.d.ts.map +0 -1
- package/dist/types/media/file-system.d.ts.map +0 -1
- package/dist/types/media/index.d.ts.map +0 -1
- package/dist/types/media/local.d.ts.map +0 -1
- package/dist/types/media/mime.d.ts.map +0 -1
- package/dist/types/media/names.d.ts.map +0 -1
- package/dist/types/media/project-images.d.ts.map +0 -1
- package/dist/types/media/s3.d.ts.map +0 -1
- package/dist/types/media/type-filter.d.ts.map +0 -1
- package/dist/types/portable.d.ts.map +0 -1
- package/dist/types/project-config-ast.d.ts.map +0 -1
- package/dist/types/public-static-file.d.ts.map +0 -1
- package/dist/types/redirects.d.ts.map +0 -1
- package/dist/types/route-scan.d.ts.map +0 -1
- package/dist/types/schema-port.d.ts.map +0 -1
- package/dist/types/schema-probe.d.ts.map +0 -1
- package/dist/types/shared.d.ts.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- /package/dist/{types/asset-paths.d.ts → asset-paths.d.ts} +0 -0
- /package/dist/{types/astro-source-analysis.d.ts → astro-source-analysis.d.ts} +0 -0
- /package/dist/{types/byte-range.d.ts → byte-range.d.ts} +0 -0
- /package/dist/{types/editor-write-model.d.ts → editor-write-model.d.ts} +0 -0
- /package/dist/{types/fs → fs}/glob.d.ts +0 -0
- /package/dist/{types/fs → fs}/types.d.ts +0 -0
- /package/dist/{types/media → media}/contember.d.ts +0 -0
- /package/dist/{types/media → media}/errors.d.ts +0 -0
- /package/dist/{types/media → media}/local.d.ts +0 -0
- /package/dist/{types/media → media}/mime.d.ts +0 -0
- /package/dist/{types/media → media}/names.d.ts +0 -0
- /package/dist/{types/media → media}/s3.d.ts +0 -0
- /package/dist/{types/media → media}/type-filter.d.ts +0 -0
- /package/dist/{types/public-static-file.d.ts → public-static-file.d.ts} +0 -0
- /package/dist/{types/redirects.d.ts → redirects.d.ts} +0 -0
- /package/dist/{types/route-scan.d.ts → route-scan.d.ts} +0 -0
- /package/dist/{types/schema-port.d.ts → schema-port.d.ts} +0 -0
- /package/dist/{types/shared.d.ts → shared.d.ts} +0 -0
package/dist/check.js
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content check — validates collections without building the site.
|
|
3
|
+
*
|
|
4
|
+
* `astro sync` is the ground truth, but it costs a cold content-layer parse (20 s on a
|
|
5
|
+
* 1.5k-entry site) and it aborts on the FIRST bad entry. This walks the declared
|
|
6
|
+
* collections directly: it reports every problem in one pass, in about a second, which is
|
|
7
|
+
* what makes it usable as the check an agent runs after an edit instead of a full build.
|
|
8
|
+
*
|
|
9
|
+
* Only fields the content config types explicitly (`n.number()`, `n.select()`, …) are
|
|
10
|
+
* type-checked. A plain zod field parses to `type: undefined` here, and guessing at those
|
|
11
|
+
* would trade the one thing this has to get right — no false positives — for coverage that
|
|
12
|
+
* `astro sync` already provides.
|
|
13
|
+
*/
|
|
14
|
+
import { assetBaseDir, resolveAssetCandidates } from "./asset-paths.js";
|
|
15
|
+
import { isPlainObject, loadCollections } from "./check-entries.js";
|
|
16
|
+
import { checkAgainstSchemas } from "./check-live.js";
|
|
17
|
+
import { checkFieldShapes } from "./check-shape.js";
|
|
18
|
+
import { checkEditorWrites } from "./check-write.js";
|
|
19
|
+
import { classifyEmptyContentConfig, CONTENT_CONFIG_PATHS, parseContentConfig, } from "./content-config-ast.js";
|
|
20
|
+
import { schemaFor } from "./schema-port.js";
|
|
21
|
+
import { computePathnameFromSpec } from "./shared.js";
|
|
22
|
+
const typeName = (value) => {
|
|
23
|
+
if (value === null)
|
|
24
|
+
return 'null';
|
|
25
|
+
if (Array.isArray(value))
|
|
26
|
+
return 'array';
|
|
27
|
+
if (value instanceof Date)
|
|
28
|
+
return 'date';
|
|
29
|
+
return typeof value;
|
|
30
|
+
};
|
|
31
|
+
/** Whether a value satisfies a field's declared type. `null` means "no opinion". */
|
|
32
|
+
function typeMismatch(field, value) {
|
|
33
|
+
switch (field.type) {
|
|
34
|
+
case 'number':
|
|
35
|
+
case 'year':
|
|
36
|
+
case 'month':
|
|
37
|
+
return typeof value === 'number' ? null : `expected a number, found ${typeName(value)}`;
|
|
38
|
+
case 'boolean':
|
|
39
|
+
return typeof value === 'boolean' ? null : `expected true/false, found ${typeName(value)}`;
|
|
40
|
+
case 'select': {
|
|
41
|
+
if (typeof value !== 'string')
|
|
42
|
+
return `expected one of the allowed values, found ${typeName(value)}`;
|
|
43
|
+
const options = field.options ?? [];
|
|
44
|
+
if (options.length === 0 || options.includes(value))
|
|
45
|
+
return null;
|
|
46
|
+
return `"${value}" is not one of: ${options.join(', ')}`;
|
|
47
|
+
}
|
|
48
|
+
case 'date':
|
|
49
|
+
case 'datetime':
|
|
50
|
+
if (value instanceof Date)
|
|
51
|
+
return Number.isNaN(value.getTime()) ? 'is not a valid date' : null;
|
|
52
|
+
if (typeof value !== 'string')
|
|
53
|
+
return `expected a date, found ${typeName(value)}`;
|
|
54
|
+
return Number.isNaN(Date.parse(value)) ? `"${value}" is not a valid date` : null;
|
|
55
|
+
case 'array':
|
|
56
|
+
return Array.isArray(value) ? null : `expected a list, found ${typeName(value)}`;
|
|
57
|
+
case 'object':
|
|
58
|
+
return isPlainObject(value) ? null : `expected an object, found ${typeName(value)}`;
|
|
59
|
+
case 'text':
|
|
60
|
+
case 'textarea':
|
|
61
|
+
case 'markdown':
|
|
62
|
+
case 'url':
|
|
63
|
+
case 'email':
|
|
64
|
+
case 'tel':
|
|
65
|
+
case 'color':
|
|
66
|
+
case 'time':
|
|
67
|
+
case 'reference':
|
|
68
|
+
return typeof value === 'string' ? null : `expected text, found ${typeName(value)}`;
|
|
69
|
+
// `image`/`file` resolve through astro:assets and may hold an object once processed.
|
|
70
|
+
default:
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The on-disk path an `image` value names, or `null` when it names none: the s3/contember
|
|
76
|
+
* media adapters store absolute URLs, and a `~/…`/`@…` value is a Vite alias, which Astro
|
|
77
|
+
* hands to Vite's resolver (see `astro/src/content/utils.ts`) and this cannot follow.
|
|
78
|
+
* A cache-busting `?v=2`/`#frag` is trimmed off rather than discarding the whole value.
|
|
79
|
+
*/
|
|
80
|
+
function projectAssetPath(value) {
|
|
81
|
+
if (value === '' || value.startsWith('//'))
|
|
82
|
+
return null;
|
|
83
|
+
// A scheme — `https:`, `data:`, `file:`.
|
|
84
|
+
if (/^[a-z][a-z\d+\-.]*:/i.test(value))
|
|
85
|
+
return null;
|
|
86
|
+
// A Vite alias or a `#imports` subpath — an import specifier, not a path.
|
|
87
|
+
if (/^[~@#]/.test(value))
|
|
88
|
+
return null;
|
|
89
|
+
const withoutQuery = value.split(/[?#]/)[0] ?? '';
|
|
90
|
+
return withoutQuery === '' ? null : withoutQuery;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Report `image` and `video` values pointing at no file, walking nested objects and object-array items
|
|
94
|
+
* the same way the field data is shaped. Resolution goes through `resolveAssetCandidates`
|
|
95
|
+
* with the entry's own directory, which is what `getEntryAsset` serves a relative value
|
|
96
|
+
* from — the check therefore looks exactly where serving the asset looks.
|
|
97
|
+
*/
|
|
98
|
+
async function checkAssets(fs, fields, data, file, prefix, findings) {
|
|
99
|
+
for (const field of fields) {
|
|
100
|
+
const value = data[field.name];
|
|
101
|
+
if (value === undefined || value === null)
|
|
102
|
+
continue;
|
|
103
|
+
const label = prefix === '' ? field.name : `${prefix}.${field.name}`;
|
|
104
|
+
if (field.type === 'object' && field.fields && isPlainObject(value)) {
|
|
105
|
+
await checkAssets(fs, field.fields, value, file, label, findings);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (field.type === 'array' && field.itemType === 'object' && field.fields && Array.isArray(value)) {
|
|
109
|
+
for (const [index, item] of value.entries()) {
|
|
110
|
+
if (isPlainObject(item))
|
|
111
|
+
await checkAssets(fs, field.fields, item, file, `${label}[${index}]`, findings);
|
|
112
|
+
}
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if ((field.type !== 'image' && field.type !== 'video') || typeof value !== 'string')
|
|
116
|
+
continue;
|
|
117
|
+
const assetPath = projectAssetPath(value);
|
|
118
|
+
if (assetPath === null)
|
|
119
|
+
continue;
|
|
120
|
+
const candidates = resolveAssetCandidates(assetBaseDir(file), assetPath);
|
|
121
|
+
// No candidates left means the path climbs above the project root — outside what this can judge.
|
|
122
|
+
if (candidates.length === 0)
|
|
123
|
+
continue;
|
|
124
|
+
let found = false;
|
|
125
|
+
for (const candidate of candidates) {
|
|
126
|
+
if (await fs.exists(candidate)) {
|
|
127
|
+
found = true;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (found)
|
|
132
|
+
continue;
|
|
133
|
+
findings.push({
|
|
134
|
+
severity: 'warning',
|
|
135
|
+
code: 'entry/missing-asset',
|
|
136
|
+
file,
|
|
137
|
+
field: label,
|
|
138
|
+
message: `${label}: "${value}" points at no file (tried ${candidates.join(', ')}).`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Entries whose declarative `cms.pathname` rule resolves to a URL another entry already took —
|
|
144
|
+
* the later ones render over the first, so only one of them is reachable. A warning, not an
|
|
145
|
+
* error: this builds green and only goes wrong at render time.
|
|
146
|
+
*
|
|
147
|
+
* `collection-scanner.ts` warns about the same thing on the dev-server path; the duplication
|
|
148
|
+
* is deliberate, because this check must stay scanner-free.
|
|
149
|
+
*/
|
|
150
|
+
function pathnameCollisions(collection, entries) {
|
|
151
|
+
// `fragment` needs no guard here — parsing already drops the `pathname` of a fragment collection.
|
|
152
|
+
if (!collection.pathname)
|
|
153
|
+
return [];
|
|
154
|
+
const findings = [];
|
|
155
|
+
const firstAt = new Map();
|
|
156
|
+
for (const entry of entries) {
|
|
157
|
+
if (!entry.frontmatter)
|
|
158
|
+
continue;
|
|
159
|
+
const pathname = computePathnameFromSpec(collection.pathname, entry.frontmatter);
|
|
160
|
+
// An unresolved spec (a missing/uncoercible field) yields no URL, so there is nothing to collide.
|
|
161
|
+
if (pathname === undefined)
|
|
162
|
+
continue;
|
|
163
|
+
const first = firstAt.get(pathname);
|
|
164
|
+
if (!first) {
|
|
165
|
+
firstAt.set(pathname, entry);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
findings.push({
|
|
169
|
+
severity: 'warning',
|
|
170
|
+
code: 'entry/pathname-collision',
|
|
171
|
+
file: entry.file,
|
|
172
|
+
field: collection.name,
|
|
173
|
+
// The path, not the stem: bundle entries are all named `index`.
|
|
174
|
+
message: `The pathname rule maps this entry and ${first.file} to ${pathname} — they collide on one page.`,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return findings;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Validate every declared collection against what is on disk.
|
|
181
|
+
*
|
|
182
|
+
* Errors are things that fail the build; warnings are things that pass it and then go wrong
|
|
183
|
+
* at render time (a reference pointing at nothing is the documented example).
|
|
184
|
+
*/
|
|
185
|
+
export async function checkContent(fs, options = {}) {
|
|
186
|
+
const findings = [];
|
|
187
|
+
const config = await parseContentConfig(fs, new Map());
|
|
188
|
+
if (config.size === 0) {
|
|
189
|
+
// A config that reads fine and declares nothing is a site without content collections. It
|
|
190
|
+
// builds, so by this function's own contract it is not an error — and reporting it as one
|
|
191
|
+
// blocked the publish of every such site and sent the agent chasing a defect that was not there.
|
|
192
|
+
const reason = await classifyEmptyContentConfig(fs);
|
|
193
|
+
if (reason !== 'no-collections') {
|
|
194
|
+
findings.push({
|
|
195
|
+
severity: 'error',
|
|
196
|
+
code: reason === 'missing' ? 'config/missing' : 'config/unreadable',
|
|
197
|
+
file: 'src/content.config.ts',
|
|
198
|
+
message: reason === 'missing'
|
|
199
|
+
? `No content config found — expected one of ${CONTENT_CONFIG_PATHS.join(' or ')}.`
|
|
200
|
+
: 'The content config could not be parsed.',
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return { findings, collections: 0, entries: 0 };
|
|
204
|
+
}
|
|
205
|
+
// Read everything first: a reference can point at a collection checked later.
|
|
206
|
+
const collections = await loadCollections(fs, config);
|
|
207
|
+
const stems = new Map();
|
|
208
|
+
for (const [name, loaded] of collections) {
|
|
209
|
+
stems.set(name, new Set(loaded.entries.map(entry => entry.stem)));
|
|
210
|
+
if (!loaded.exists) {
|
|
211
|
+
findings.push({
|
|
212
|
+
severity: 'error',
|
|
213
|
+
code: 'config/missing-dir',
|
|
214
|
+
file: 'src/content.config.ts',
|
|
215
|
+
field: name,
|
|
216
|
+
message: `Collection "${name}" loads from ${loaded.base}/, which does not exist.`,
|
|
217
|
+
});
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (loaded.unreadable !== undefined) {
|
|
221
|
+
// An error, not a shorter count: nothing was checked, and the build reads the same directory.
|
|
222
|
+
findings.push({
|
|
223
|
+
severity: 'error',
|
|
224
|
+
code: 'config/unreadable-dir',
|
|
225
|
+
file: loaded.base,
|
|
226
|
+
field: name,
|
|
227
|
+
message: `Collection "${name}" could not be read: ${loaded.unreadable}. `
|
|
228
|
+
+ `Make the directory readable, or narrow the loader's base or pattern so it does not reach there.`,
|
|
229
|
+
});
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (loaded.entries.length === 0) {
|
|
233
|
+
findings.push({
|
|
234
|
+
severity: 'warning',
|
|
235
|
+
code: 'config/empty-collection',
|
|
236
|
+
file: loaded.base,
|
|
237
|
+
field: name,
|
|
238
|
+
message: `Collection "${name}" matched no entries under ${loaded.base}/.`,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
let entries = 0;
|
|
243
|
+
for (const [name, collection] of config) {
|
|
244
|
+
// A bare `reference()` carries no field type, so it has to be kept explicitly.
|
|
245
|
+
const typedFields = collection.fields.filter(field => field.type !== undefined || field.required || field.reference);
|
|
246
|
+
const declared = new Set(collection.fields.map(field => field.name));
|
|
247
|
+
const loadedEntries = collections.get(name)?.entries ?? [];
|
|
248
|
+
/**
|
|
249
|
+
* Whether the real schema is available to judge this collection's entries.
|
|
250
|
+
*
|
|
251
|
+
* When it is, `entry/missing-required` and `entry/field-type` stand down: both infer a rule
|
|
252
|
+
* from the config's *surface* and are wrong wherever the surface and the schema differ.
|
|
253
|
+
* `required` is only "no `.optional()` was visible" — a field schema wrapped in a helper call
|
|
254
|
+
* hides it. And a type name does not fix a type: `n.date()` is
|
|
255
|
+
* `z.preprocess(toISODate, z.string())` with no validation, so `date: ''` is legal content
|
|
256
|
+
* that this rule called a broken date. Both produced build-failing errors on production sites
|
|
257
|
+
* that build. `entry/schema-rejected` answers properly, and `cms/required-drift` reports the
|
|
258
|
+
* disagreement itself, once, against the config rather than once per entry.
|
|
259
|
+
*/
|
|
260
|
+
const schemaJudgesEntries = options.schemas !== undefined && schemaFor(options.schemas, name) !== undefined;
|
|
261
|
+
for (const entry of loadedEntries) {
|
|
262
|
+
entries++;
|
|
263
|
+
const file = entry.file;
|
|
264
|
+
if (entry.frontmatter === undefined) {
|
|
265
|
+
findings.push({ severity: 'error', code: 'entry/syntax', file, message: `Frontmatter does not parse: ${entry.parseError}` });
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
for (const field of typedFields) {
|
|
269
|
+
const value = entry.frontmatter[field.name];
|
|
270
|
+
if (value === undefined || value === null) {
|
|
271
|
+
if (field.required && !schemaJudgesEntries) {
|
|
272
|
+
findings.push({
|
|
273
|
+
severity: 'error',
|
|
274
|
+
code: 'entry/missing-required',
|
|
275
|
+
file,
|
|
276
|
+
field: field.name,
|
|
277
|
+
message: `Required field "${field.name}" is missing.`,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
const mismatch = field.type === undefined || schemaJudgesEntries ? null : typeMismatch(field, value);
|
|
283
|
+
if (mismatch) {
|
|
284
|
+
findings.push({ severity: 'error', code: 'entry/field-type', file, field: field.name, message: `${field.name}: ${mismatch}` });
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const reference = field.reference;
|
|
288
|
+
if (!reference)
|
|
289
|
+
continue;
|
|
290
|
+
const targets = stems.get(reference.target);
|
|
291
|
+
// An unresolvable target collection is already reported once by config/missing-dir
|
|
292
|
+
// or config/unreadable-dir.
|
|
293
|
+
if (!targets || targets.size === 0)
|
|
294
|
+
continue;
|
|
295
|
+
const values = reference.isArray ? (Array.isArray(value) ? value : [value]) : [value];
|
|
296
|
+
for (const item of values) {
|
|
297
|
+
if (typeof item !== 'string' || targets.has(item))
|
|
298
|
+
continue;
|
|
299
|
+
findings.push({
|
|
300
|
+
severity: 'warning',
|
|
301
|
+
code: 'entry/dangling-reference',
|
|
302
|
+
file,
|
|
303
|
+
field: field.name,
|
|
304
|
+
// reference() validates the shape, not the target — a wrong id builds green and renders nothing.
|
|
305
|
+
message: `${field.name}: "${item}" is not an entry of "${reference.target}".`,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
await checkAssets(fs, collection.fields, entry.frontmatter, file, '', findings);
|
|
310
|
+
// Only a field list known to be complete can call a key unknown. It is short when the
|
|
311
|
+
// schema never unwrapped at all (renamed import, an unsupported wrapper) and when a
|
|
312
|
+
// spread or computed key was skipped — warning on every key of a valid project is the
|
|
313
|
+
// false positive this check exists to avoid.
|
|
314
|
+
if (declared.size > 0 && !collection.partialFields) {
|
|
315
|
+
for (const key of Object.keys(entry.frontmatter)) {
|
|
316
|
+
if (declared.has(key))
|
|
317
|
+
continue;
|
|
318
|
+
findings.push({
|
|
319
|
+
severity: 'warning',
|
|
320
|
+
code: 'entry/unknown-key',
|
|
321
|
+
file,
|
|
322
|
+
field: key,
|
|
323
|
+
// Astro's schema strips what it does not declare, so the value is written and then never read.
|
|
324
|
+
message: `"${key}" is not a field of "${name}" — nothing reads it.`,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
findings.push(...pathnameCollisions(collection, loadedEntries));
|
|
330
|
+
}
|
|
331
|
+
if (options.schemas) {
|
|
332
|
+
const input = { config, collections, schemas: options.schemas };
|
|
333
|
+
findings.push(...await checkAgainstSchemas(input), ...await checkEditorWrites(input), ...await checkFieldShapes(input));
|
|
334
|
+
}
|
|
335
|
+
return { findings, collections: config.size, entries };
|
|
336
|
+
}
|
|
337
|
+
/** Human-readable report. Returns '' when there is nothing to say. */
|
|
338
|
+
export function formatCheckReport(report) {
|
|
339
|
+
if (report.findings.length === 0)
|
|
340
|
+
return '';
|
|
341
|
+
const byFile = new Map();
|
|
342
|
+
for (const finding of report.findings) {
|
|
343
|
+
const bucket = byFile.get(finding.file);
|
|
344
|
+
if (bucket)
|
|
345
|
+
bucket.push(finding);
|
|
346
|
+
else
|
|
347
|
+
byFile.set(finding.file, [finding]);
|
|
348
|
+
}
|
|
349
|
+
const lines = [];
|
|
350
|
+
for (const [file, findings] of byFile) {
|
|
351
|
+
lines.push(file);
|
|
352
|
+
// One remedy usually covers a run of findings — five missing fields in one collection get the
|
|
353
|
+
// same sentence. Printed once per run, and reset per file so a block never opens without it.
|
|
354
|
+
let lastHint;
|
|
355
|
+
for (const finding of findings) {
|
|
356
|
+
// eslint's shape: position, severity, message, rule. Familiar, and greppable by column.
|
|
357
|
+
const at = finding.line === undefined ? '' : `${finding.line}:${finding.column ?? 0}`;
|
|
358
|
+
lines.push(` ${at.padEnd(8)}${(finding.severity === 'error' ? 'error' : 'warn').padEnd(6)} ${finding.message} [${finding.code}]`);
|
|
359
|
+
// Indented under its finding, so the proposal never reads as another observation.
|
|
360
|
+
if (finding.hint !== undefined && finding.hint !== lastHint)
|
|
361
|
+
lines.push(` ${' '.repeat(14)}→ ${finding.hint}`);
|
|
362
|
+
lastHint = finding.hint;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return lines.join('\n');
|
|
366
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CollectionDefinition, CollectionScanReport } from '@nuasite/cms-types';
|
|
2
|
-
import { type ParseCache } from './content-config-ast';
|
|
3
|
-
import type { CmsFileSystem } from './fs/types';
|
|
2
|
+
import { type ParseCache } from './content-config-ast.ts';
|
|
3
|
+
import type { CmsFileSystem } from './fs/types.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Normalize a glob loader `base` (`./src/content/x`, `src/content/x/`) into a
|
|
6
6
|
* root-relative path comparable with a collection definition's `path`. The project
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection-scanner.d.ts","sourceRoot":"","sources":["../src/collection-scanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EAEpB,oBAAoB,EAIpB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAMN,KAAK,UAAU,EAKf,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,eAAe,CAAA;AA6jC/D;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAqCD;;;;;;GAMG;AACH,wBAAsB,eAAe,CACpC,EAAE,EAAE,aAAa,EACjB,UAAU,GAAE,MAAsB,EAClC,UAAU,GAAE,UAAsB,EAClC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAChC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CA6G/C;AAKD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,GAAG,oBAAoB,GAAG,SAAS,CAExH"}
|