@veluai/velu 0.1.13 → 0.1.15
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/README.md +80 -80
- package/dist/cli.js +21 -21
- package/package.json +3 -2
- package/runtime/velu-ui/components/Accordion.jsx +64 -64
- package/runtime/velu-ui/components/ApiClient.jsx +121 -121
- package/runtime/velu-ui/components/ApiField.jsx +87 -87
- package/runtime/velu-ui/components/ApiPath.jsx +63 -63
- package/runtime/velu-ui/components/ApiSidebar.jsx +122 -122
- package/runtime/velu-ui/components/AskBar.jsx +71 -71
- package/runtime/velu-ui/components/Callout.jsx +114 -114
- package/runtime/velu-ui/components/Card.jsx +131 -131
- package/runtime/velu-ui/components/Chatbot.jsx +596 -596
- package/runtime/velu-ui/components/CodeBlock.jsx +375 -375
- package/runtime/velu-ui/components/Columns.jsx +56 -56
- package/runtime/velu-ui/components/ErrorCard.jsx +138 -138
- package/runtime/velu-ui/components/Field.jsx +81 -81
- package/runtime/velu-ui/components/Image.jsx +163 -163
- package/runtime/velu-ui/components/Logo.jsx +31 -0
- package/runtime/velu-ui/components/MethodBadge.jsx +31 -31
- package/runtime/velu-ui/components/NavSelect.jsx +108 -108
- package/runtime/velu-ui/components/PageFeedback.jsx +219 -219
- package/runtime/velu-ui/components/PageFooter.jsx +145 -213
- package/runtime/velu-ui/components/PageHeader.jsx +422 -414
- package/runtime/velu-ui/components/PageNav.jsx +77 -77
- package/runtime/velu-ui/components/PoweredBy.jsx +51 -51
- package/runtime/velu-ui/components/Prompt.jsx +115 -115
- package/runtime/velu-ui/components/Search.jsx +411 -366
- package/runtime/velu-ui/components/Sidebar.jsx +191 -191
- package/runtime/velu-ui/components/SocialLinks.jsx +90 -0
- package/runtime/velu-ui/components/Steps.jsx +65 -65
- package/runtime/velu-ui/components/ThemeToggle.jsx +48 -48
- package/runtime/velu-ui/components/Toc.jsx +537 -537
- package/runtime/velu-ui/components/TocBar.jsx +195 -195
- package/runtime/velu-ui/components/Tree.jsx +87 -87
- package/runtime/velu-ui/components/TryItBar.jsx +90 -90
- package/runtime/velu-ui/components/accordion.css +92 -92
- package/runtime/velu-ui/components/api.css +479 -479
- package/runtime/velu-ui/components/ask-bar.css +94 -94
- package/runtime/velu-ui/components/card.css +105 -105
- package/runtime/velu-ui/components/chatbot.css +617 -617
- package/runtime/velu-ui/components/code-block.css +263 -263
- package/runtime/velu-ui/components/docs-layout.css +784 -775
- package/runtime/velu-ui/components/field.css +82 -82
- package/runtime/velu-ui/components/image.css +237 -237
- package/runtime/velu-ui/components/nav-select.css +157 -157
- package/runtime/velu-ui/components/page-feedback.css +241 -241
- package/runtime/velu-ui/components/page-footer.css +130 -130
- package/runtime/velu-ui/components/page-header.css +557 -520
- package/runtime/velu-ui/components/page-nav.css +50 -50
- package/runtime/velu-ui/components/powered-by.css +86 -66
- package/runtime/velu-ui/components/prompt.css +99 -99
- package/runtime/velu-ui/components/search.css +307 -307
- package/runtime/velu-ui/components/sidebar.css +144 -144
- package/runtime/velu-ui/components/steps.css +77 -77
- package/runtime/velu-ui/components/theme-toggle.css +101 -101
- package/runtime/velu-ui/components/toc-bar.css +234 -234
- package/runtime/velu-ui/components/tree.css +49 -49
- package/runtime/velu-ui/index.js +48 -46
- package/runtime/velu-ui/lib/component-schemas.js +100 -100
- package/runtime/velu-ui/lib/copyText.js +64 -64
- package/runtime/velu-ui/lib/lang-icons.jsx +147 -147
- package/runtime/velu-ui/lib/prism-langs.js +957 -957
- package/runtime/velu-ui/lib/prism-loader.js +74 -74
- package/runtime/velu-ui/lib/resolveIcon.jsx +29 -29
- package/runtime/velu-ui/lib/scrollIntoNearestView.js +66 -66
- package/runtime/velu-ui/mdx-components.jsx +105 -105
- package/runtime/velu-ui/primitives/Cluster.jsx +49 -49
- package/runtime/velu-ui/primitives/Stack.jsx +63 -63
- package/runtime/velu-ui/primitives/Switcher.jsx +57 -57
- package/runtime/velu-ui/primitives/stack.css +3 -3
- package/runtime/velu-ui/primitives/switcher.css +25 -25
- package/runtime/velu-ui/styles.css +43 -43
- package/runtime/velu-ui/tokens.css +4 -4
- package/schema/velu.schema.json +281 -167
- package/src/lib/extract-mdx-error.js +170 -170
- package/src/lib/issues.js +159 -159
- package/src/lib/known-components.js +34 -34
- package/src/navigation.js +434 -434
- package/src/runtime/App.jsx +1506 -1476
- package/src/runtime/ErrorBoundary.jsx +54 -54
- package/src/runtime/client-entry.jsx +22 -22
- package/src/runtime/server-entry.jsx +16 -16
- package/src/template.html +48 -48
- package/templates/starter/ai-tools/claude-code.mdx +26 -26
- package/templates/starter/ai-tools/cursor.mdx +17 -17
- package/templates/starter/api-reference/endpoint/create.mdx +24 -24
- package/templates/starter/api-reference/endpoint/get.mdx +27 -27
- package/templates/starter/api-reference/introduction.mdx +28 -28
- package/templates/starter/development.mdx +19 -19
- package/templates/starter/essentials/code.mdx +29 -29
- package/templates/starter/essentials/images.mdx +29 -29
- package/templates/starter/essentials/markdown.mdx +25 -25
- package/templates/starter/essentials/navigation.mdx +39 -39
- package/templates/starter/essentials/settings.mdx +30 -30
- package/templates/starter/favicon.svg +6 -6
- package/templates/starter/index.mdx +31 -31
- package/templates/starter/quickstart.mdx +31 -31
- package/templates/starter/velu.json +33 -33
|
@@ -1,170 +1,170 @@
|
|
|
1
|
-
// Normalize a thrown error — from a Vite/MDX transform, an SSR render, or a
|
|
2
|
-
// React error boundary — into the shared `issue` shape (see ./issues.js).
|
|
3
|
-
//
|
|
4
|
-
// Isomorphic: no Node `path` import (path handling is string-based) so the
|
|
5
|
-
// browser ErrorBoundary can reuse it. The single hard rule is PATH SAFETY:
|
|
6
|
-
// never surface an absolute path that isn't under the user's project — those
|
|
7
|
-
// are Velu/Vite internals and must be stripped.
|
|
8
|
-
import { makeIssue, suggestComponent } from './issues.js';
|
|
9
|
-
|
|
10
|
-
// Unwrap a few layers of `err.cause` when the outer message is generic.
|
|
11
|
-
function unwrap(err) {
|
|
12
|
-
let e = err;
|
|
13
|
-
let depth = 0;
|
|
14
|
-
while (e && e.cause && depth < 3) {
|
|
15
|
-
// Stop if the current layer already carries useful location info.
|
|
16
|
-
if (e.loc || e.line || /`[^`]+` to be defined/.test(e.message || '')) break;
|
|
17
|
-
e = e.cause;
|
|
18
|
-
depth += 1;
|
|
19
|
-
}
|
|
20
|
-
return e || err;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const toPosix = (p) => String(p).replace(/\\/g, '/');
|
|
24
|
-
|
|
25
|
-
// Make an absolute path project-relative; return null for anything that isn't
|
|
26
|
-
// inside the project (i.e. our internals — never shown).
|
|
27
|
-
function rel(rawPath, projectDir) {
|
|
28
|
-
if (!rawPath) return null;
|
|
29
|
-
let p = toPosix(rawPath).replace(/[?#].*$/, ''); // drop ?query / #hash
|
|
30
|
-
const root = projectDir ? toPosix(projectDir).replace(/\/+$/, '') : '';
|
|
31
|
-
if (root && p.toLowerCase().startsWith(root.toLowerCase())) {
|
|
32
|
-
return p.slice(root.length).replace(/^\/+/, '');
|
|
33
|
-
}
|
|
34
|
-
// Already-relative, project-owned path (no drive letter, no node_modules).
|
|
35
|
-
if (!/^([a-zA-Z]:\/|\/)/.test(p) && !/node_modules/.test(p)) return p;
|
|
36
|
-
return null; // absolute and outside the project → hide it
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Strip any absolute path (and node_modules refs) from a message so internals
|
|
40
|
-
// never leak; collapse them to "…".
|
|
41
|
-
function cleanMessage(msg) {
|
|
42
|
-
if (!msg) return '';
|
|
43
|
-
return String(msg)
|
|
44
|
-
.replace(/([a-zA-Z]:\\|\/)[^\s'"()]+/g, (m) => (/node_modules|[\\/]vite[\\/]|@veluai|velu-cli|velu-ui/.test(m) ? '…' : m))
|
|
45
|
-
.trim();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Pull a "(line:col)" / "(line:col-line:col)" position out of a message tail.
|
|
49
|
-
// MDX/vfile errors often carry the location only in the message string, with
|
|
50
|
-
// err.line/err.loc left undefined.
|
|
51
|
-
function parseLocFromMessage(msg) {
|
|
52
|
-
const m = /\((\d+):(\d+)(?:-\d+:\d+)?\)\s*$/.exec(String(msg || ''));
|
|
53
|
-
return m ? { line: Number(m[1]), column: Number(m[2]) } : null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Drop a trailing "(line:col-…)" from a message once we've surfaced it as a
|
|
57
|
-
// separate location, so it isn't shown twice.
|
|
58
|
-
function stripLocSuffix(msg) {
|
|
59
|
-
return String(msg || '').replace(/\s*\(\d+:\d+(?:-\d+:\d+)?\)\s*$/, '').trim();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Phrases that mark a genuine MDX *parse* error (vs a runtime throw).
|
|
63
|
-
const MDX_SYNTAX_RE =
|
|
64
|
-
/closing tag|unexpected closing|could not parse (?:expression|import|export)|unexpected character|unexpected end of|expected a closing|expected the closing|unexpected `|in expression|misnested|before name/i;
|
|
65
|
-
|
|
66
|
-
// Keep a code frame only when it clearly belongs to a project file; otherwise
|
|
67
|
-
// drop it (an internal frame would leak paths and confuse the author).
|
|
68
|
-
function safeFrame(frame, fileIsProjectOwned) {
|
|
69
|
-
if (!frame || !fileIsProjectOwned) return null;
|
|
70
|
-
const text = String(frame);
|
|
71
|
-
if (/node_modules|[\\/]vite[\\/]|@veluai[\\/]/.test(text)) return null;
|
|
72
|
-
return text;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function extractMdxError(rawErr, opts = {}) {
|
|
76
|
-
const { projectDir = '', knownComponents = [], file: fileHint = null } = opts;
|
|
77
|
-
|
|
78
|
-
// A component (runtime) or the compile-time prop check attaches a ready-made
|
|
79
|
-
// issue. Trust it directly — it already carries plain-language wording, a
|
|
80
|
-
// suggestion, and (from the compile-time check) a file:line. Walk the cause
|
|
81
|
-
// chain since Vite/rollup may re-wrap the thrown error.
|
|
82
|
-
let tagged = null;
|
|
83
|
-
for (let e = rawErr, depth = 0; e && depth < 6; e = e.cause, depth += 1) {
|
|
84
|
-
if (e.veluIssue) {
|
|
85
|
-
tagged = e.veluIssue;
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (tagged) return makeIssue({ ...tagged, file: tagged.file || fileHint });
|
|
90
|
-
|
|
91
|
-
const err = unwrap(rawErr) || {};
|
|
92
|
-
const message = err.message || String(rawErr || '');
|
|
93
|
-
|
|
94
|
-
// 1) Unknown component (MDX render: `_missingMdxReference`). The message
|
|
95
|
-
// tail carries the spot: "...referenced in your code at `7:1-7:54` in
|
|
96
|
-
// `<abs path>`" — pull the line/column + file out so the author knows
|
|
97
|
-
// exactly where to look (path relative-ized for safety).
|
|
98
|
-
const missing = /Expected component `([^`]+)` to be defined/.exec(message);
|
|
99
|
-
if (missing) {
|
|
100
|
-
const name = missing[1];
|
|
101
|
-
const at = /referenced in your code at `(\d+):(\d+)/.exec(message);
|
|
102
|
-
const inFile = /\bin `([^`]+)`/.exec(message);
|
|
103
|
-
const relFile = inFile ? rel(inFile[1], projectDir) : null;
|
|
104
|
-
return makeIssue({
|
|
105
|
-
category: 'unknown-component',
|
|
106
|
-
file: relFile || fileHint,
|
|
107
|
-
line: at ? Number(at[1]) : null,
|
|
108
|
-
column: at ? Number(at[2]) : null,
|
|
109
|
-
title: `<${name}> is not a built-in component`,
|
|
110
|
-
detail: '',
|
|
111
|
-
hint: 'Components are built in — check the spelling and capitalization (you don’t import them).',
|
|
112
|
-
suggestion: suggestComponent(name, knownComponents),
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// 2) Compile error carrying a source location (Vite plugin / MDX / vfile).
|
|
117
|
-
// The location may be on err.loc, on err.line/column, or only inside the
|
|
118
|
-
// message text — try all three.
|
|
119
|
-
const loc =
|
|
120
|
-
err.loc ||
|
|
121
|
-
(err.line != null ? { line: err.line, column: err.column, file: err.file } : null) ||
|
|
122
|
-
parseLocFromMessage(err.reason || message);
|
|
123
|
-
const rawFile = err.id || (loc && loc.file) || err.file || null;
|
|
124
|
-
const file = rel(rawFile, projectDir) || fileHint;
|
|
125
|
-
const fileIsProjectOwned = Boolean(file) && rel(rawFile, projectDir) != null;
|
|
126
|
-
const frame = safeFrame(err.frame, fileIsProjectOwned || Boolean(fileHint));
|
|
127
|
-
const detail = cleanMessage(stripLocSuffix(err.reason || message));
|
|
128
|
-
const isSyntax = MDX_SYNTAX_RE.test(message);
|
|
129
|
-
const isFrontmatter =
|
|
130
|
-
err.source === 'remark-frontmatter' ||
|
|
131
|
-
/\byaml\b|frontmatter/i.test(message) ||
|
|
132
|
-
(loc && loc.line === 1 && /unexpected|expected/i.test(message) && /---/.test(message));
|
|
133
|
-
|
|
134
|
-
if (loc || isSyntax || (frame && fileIsProjectOwned)) {
|
|
135
|
-
return makeIssue({
|
|
136
|
-
category: isFrontmatter ? 'frontmatter' : 'mdx-syntax',
|
|
137
|
-
file,
|
|
138
|
-
line: loc ? loc.line : null,
|
|
139
|
-
column: loc ? loc.column : null,
|
|
140
|
-
frame,
|
|
141
|
-
title: detail || (isFrontmatter ? 'Invalid frontmatter' : 'MDX syntax error'),
|
|
142
|
-
detail: '',
|
|
143
|
-
hint: isFrontmatter
|
|
144
|
-
? 'Check the YAML between the --- markers — indentation, quotes, and colons.'
|
|
145
|
-
: 'Make sure every <Component> has a matching closing tag and that { } braces are balanced.',
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// 3) Bad prop / option that threw at render time.
|
|
150
|
-
if (/\.map is not a function|is not iterable|reading '|undefined \(reading/i.test(message)) {
|
|
151
|
-
return makeIssue({
|
|
152
|
-
category: 'invalid-props',
|
|
153
|
-
file,
|
|
154
|
-
title: 'A component received an invalid value',
|
|
155
|
-
detail,
|
|
156
|
-
hint: 'Check the props/options you passed to a component on this page.',
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// 4) Anything else that threw while rendering.
|
|
161
|
-
return makeIssue({
|
|
162
|
-
category: 'render-crash',
|
|
163
|
-
file,
|
|
164
|
-
title: 'This page failed to render',
|
|
165
|
-
detail,
|
|
166
|
-
hint: 'Set VELU_DEBUG=1 for the full stack trace.',
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export default extractMdxError;
|
|
1
|
+
// Normalize a thrown error — from a Vite/MDX transform, an SSR render, or a
|
|
2
|
+
// React error boundary — into the shared `issue` shape (see ./issues.js).
|
|
3
|
+
//
|
|
4
|
+
// Isomorphic: no Node `path` import (path handling is string-based) so the
|
|
5
|
+
// browser ErrorBoundary can reuse it. The single hard rule is PATH SAFETY:
|
|
6
|
+
// never surface an absolute path that isn't under the user's project — those
|
|
7
|
+
// are Velu/Vite internals and must be stripped.
|
|
8
|
+
import { makeIssue, suggestComponent } from './issues.js';
|
|
9
|
+
|
|
10
|
+
// Unwrap a few layers of `err.cause` when the outer message is generic.
|
|
11
|
+
function unwrap(err) {
|
|
12
|
+
let e = err;
|
|
13
|
+
let depth = 0;
|
|
14
|
+
while (e && e.cause && depth < 3) {
|
|
15
|
+
// Stop if the current layer already carries useful location info.
|
|
16
|
+
if (e.loc || e.line || /`[^`]+` to be defined/.test(e.message || '')) break;
|
|
17
|
+
e = e.cause;
|
|
18
|
+
depth += 1;
|
|
19
|
+
}
|
|
20
|
+
return e || err;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const toPosix = (p) => String(p).replace(/\\/g, '/');
|
|
24
|
+
|
|
25
|
+
// Make an absolute path project-relative; return null for anything that isn't
|
|
26
|
+
// inside the project (i.e. our internals — never shown).
|
|
27
|
+
function rel(rawPath, projectDir) {
|
|
28
|
+
if (!rawPath) return null;
|
|
29
|
+
let p = toPosix(rawPath).replace(/[?#].*$/, ''); // drop ?query / #hash
|
|
30
|
+
const root = projectDir ? toPosix(projectDir).replace(/\/+$/, '') : '';
|
|
31
|
+
if (root && p.toLowerCase().startsWith(root.toLowerCase())) {
|
|
32
|
+
return p.slice(root.length).replace(/^\/+/, '');
|
|
33
|
+
}
|
|
34
|
+
// Already-relative, project-owned path (no drive letter, no node_modules).
|
|
35
|
+
if (!/^([a-zA-Z]:\/|\/)/.test(p) && !/node_modules/.test(p)) return p;
|
|
36
|
+
return null; // absolute and outside the project → hide it
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Strip any absolute path (and node_modules refs) from a message so internals
|
|
40
|
+
// never leak; collapse them to "…".
|
|
41
|
+
function cleanMessage(msg) {
|
|
42
|
+
if (!msg) return '';
|
|
43
|
+
return String(msg)
|
|
44
|
+
.replace(/([a-zA-Z]:\\|\/)[^\s'"()]+/g, (m) => (/node_modules|[\\/]vite[\\/]|@veluai|velu-cli|velu-ui/.test(m) ? '…' : m))
|
|
45
|
+
.trim();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Pull a "(line:col)" / "(line:col-line:col)" position out of a message tail.
|
|
49
|
+
// MDX/vfile errors often carry the location only in the message string, with
|
|
50
|
+
// err.line/err.loc left undefined.
|
|
51
|
+
function parseLocFromMessage(msg) {
|
|
52
|
+
const m = /\((\d+):(\d+)(?:-\d+:\d+)?\)\s*$/.exec(String(msg || ''));
|
|
53
|
+
return m ? { line: Number(m[1]), column: Number(m[2]) } : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Drop a trailing "(line:col-…)" from a message once we've surfaced it as a
|
|
57
|
+
// separate location, so it isn't shown twice.
|
|
58
|
+
function stripLocSuffix(msg) {
|
|
59
|
+
return String(msg || '').replace(/\s*\(\d+:\d+(?:-\d+:\d+)?\)\s*$/, '').trim();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Phrases that mark a genuine MDX *parse* error (vs a runtime throw).
|
|
63
|
+
const MDX_SYNTAX_RE =
|
|
64
|
+
/closing tag|unexpected closing|could not parse (?:expression|import|export)|unexpected character|unexpected end of|expected a closing|expected the closing|unexpected `|in expression|misnested|before name/i;
|
|
65
|
+
|
|
66
|
+
// Keep a code frame only when it clearly belongs to a project file; otherwise
|
|
67
|
+
// drop it (an internal frame would leak paths and confuse the author).
|
|
68
|
+
function safeFrame(frame, fileIsProjectOwned) {
|
|
69
|
+
if (!frame || !fileIsProjectOwned) return null;
|
|
70
|
+
const text = String(frame);
|
|
71
|
+
if (/node_modules|[\\/]vite[\\/]|@veluai[\\/]/.test(text)) return null;
|
|
72
|
+
return text;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function extractMdxError(rawErr, opts = {}) {
|
|
76
|
+
const { projectDir = '', knownComponents = [], file: fileHint = null } = opts;
|
|
77
|
+
|
|
78
|
+
// A component (runtime) or the compile-time prop check attaches a ready-made
|
|
79
|
+
// issue. Trust it directly — it already carries plain-language wording, a
|
|
80
|
+
// suggestion, and (from the compile-time check) a file:line. Walk the cause
|
|
81
|
+
// chain since Vite/rollup may re-wrap the thrown error.
|
|
82
|
+
let tagged = null;
|
|
83
|
+
for (let e = rawErr, depth = 0; e && depth < 6; e = e.cause, depth += 1) {
|
|
84
|
+
if (e.veluIssue) {
|
|
85
|
+
tagged = e.veluIssue;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (tagged) return makeIssue({ ...tagged, file: tagged.file || fileHint });
|
|
90
|
+
|
|
91
|
+
const err = unwrap(rawErr) || {};
|
|
92
|
+
const message = err.message || String(rawErr || '');
|
|
93
|
+
|
|
94
|
+
// 1) Unknown component (MDX render: `_missingMdxReference`). The message
|
|
95
|
+
// tail carries the spot: "...referenced in your code at `7:1-7:54` in
|
|
96
|
+
// `<abs path>`" — pull the line/column + file out so the author knows
|
|
97
|
+
// exactly where to look (path relative-ized for safety).
|
|
98
|
+
const missing = /Expected component `([^`]+)` to be defined/.exec(message);
|
|
99
|
+
if (missing) {
|
|
100
|
+
const name = missing[1];
|
|
101
|
+
const at = /referenced in your code at `(\d+):(\d+)/.exec(message);
|
|
102
|
+
const inFile = /\bin `([^`]+)`/.exec(message);
|
|
103
|
+
const relFile = inFile ? rel(inFile[1], projectDir) : null;
|
|
104
|
+
return makeIssue({
|
|
105
|
+
category: 'unknown-component',
|
|
106
|
+
file: relFile || fileHint,
|
|
107
|
+
line: at ? Number(at[1]) : null,
|
|
108
|
+
column: at ? Number(at[2]) : null,
|
|
109
|
+
title: `<${name}> is not a built-in component`,
|
|
110
|
+
detail: '',
|
|
111
|
+
hint: 'Components are built in — check the spelling and capitalization (you don’t import them).',
|
|
112
|
+
suggestion: suggestComponent(name, knownComponents),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 2) Compile error carrying a source location (Vite plugin / MDX / vfile).
|
|
117
|
+
// The location may be on err.loc, on err.line/column, or only inside the
|
|
118
|
+
// message text — try all three.
|
|
119
|
+
const loc =
|
|
120
|
+
err.loc ||
|
|
121
|
+
(err.line != null ? { line: err.line, column: err.column, file: err.file } : null) ||
|
|
122
|
+
parseLocFromMessage(err.reason || message);
|
|
123
|
+
const rawFile = err.id || (loc && loc.file) || err.file || null;
|
|
124
|
+
const file = rel(rawFile, projectDir) || fileHint;
|
|
125
|
+
const fileIsProjectOwned = Boolean(file) && rel(rawFile, projectDir) != null;
|
|
126
|
+
const frame = safeFrame(err.frame, fileIsProjectOwned || Boolean(fileHint));
|
|
127
|
+
const detail = cleanMessage(stripLocSuffix(err.reason || message));
|
|
128
|
+
const isSyntax = MDX_SYNTAX_RE.test(message);
|
|
129
|
+
const isFrontmatter =
|
|
130
|
+
err.source === 'remark-frontmatter' ||
|
|
131
|
+
/\byaml\b|frontmatter/i.test(message) ||
|
|
132
|
+
(loc && loc.line === 1 && /unexpected|expected/i.test(message) && /---/.test(message));
|
|
133
|
+
|
|
134
|
+
if (loc || isSyntax || (frame && fileIsProjectOwned)) {
|
|
135
|
+
return makeIssue({
|
|
136
|
+
category: isFrontmatter ? 'frontmatter' : 'mdx-syntax',
|
|
137
|
+
file,
|
|
138
|
+
line: loc ? loc.line : null,
|
|
139
|
+
column: loc ? loc.column : null,
|
|
140
|
+
frame,
|
|
141
|
+
title: detail || (isFrontmatter ? 'Invalid frontmatter' : 'MDX syntax error'),
|
|
142
|
+
detail: '',
|
|
143
|
+
hint: isFrontmatter
|
|
144
|
+
? 'Check the YAML between the --- markers — indentation, quotes, and colons.'
|
|
145
|
+
: 'Make sure every <Component> has a matching closing tag and that { } braces are balanced.',
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 3) Bad prop / option that threw at render time.
|
|
150
|
+
if (/\.map is not a function|is not iterable|reading '|undefined \(reading/i.test(message)) {
|
|
151
|
+
return makeIssue({
|
|
152
|
+
category: 'invalid-props',
|
|
153
|
+
file,
|
|
154
|
+
title: 'A component received an invalid value',
|
|
155
|
+
detail,
|
|
156
|
+
hint: 'Check the props/options you passed to a component on this page.',
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 4) Anything else that threw while rendering.
|
|
161
|
+
return makeIssue({
|
|
162
|
+
category: 'render-crash',
|
|
163
|
+
file,
|
|
164
|
+
title: 'This page failed to render',
|
|
165
|
+
detail,
|
|
166
|
+
hint: 'Set VELU_DEBUG=1 for the full stack trace.',
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export default extractMdxError;
|