@mintlify/prebuild 1.0.820 → 1.0.822
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.
|
@@ -1,12 +1,45 @@
|
|
|
1
1
|
import { isAbsolute, sep, relative } from 'path';
|
|
2
|
+
const getPosition = (error) => {
|
|
3
|
+
const err = error;
|
|
4
|
+
if (typeof err.line === 'number') {
|
|
5
|
+
return { line: err.line, column: err.column };
|
|
6
|
+
}
|
|
7
|
+
const pos = err.position;
|
|
8
|
+
const start = pos?.start;
|
|
9
|
+
if (typeof start?.line === 'number') {
|
|
10
|
+
return start;
|
|
11
|
+
}
|
|
12
|
+
// Parse position from string manually because mdast-util-mdx-jsx has a bug where they attempt to use the
|
|
13
|
+
// closing tag position in the error handler for when there is no closing tag
|
|
14
|
+
// https://github.com/syntax-tree/mdast-util-mdx-jsx/blob/998d98d0aa29fe9ed12c636ddf1ed39f9a018096/lib/index.js#L454
|
|
15
|
+
const reason = typeof err.reason === 'string' ? err.reason : '';
|
|
16
|
+
const lastParen = reason.lastIndexOf('(');
|
|
17
|
+
if (lastParen !== -1 && reason.endsWith(')')) {
|
|
18
|
+
const inside = reason.slice(lastParen + 1, -1);
|
|
19
|
+
const firstPart = inside.split('-')[0] || '';
|
|
20
|
+
const [lineStr, colStr] = firstPart.split(':');
|
|
21
|
+
const line = Number(lineStr);
|
|
22
|
+
if (!isNaN(line) && line > 0) {
|
|
23
|
+
return { line, column: Number(colStr) || undefined };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
2
28
|
export const getLocationErrString = (filePath, contentDirectoryPath, error) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
29
|
+
if (isAbsolute(filePath)) {
|
|
30
|
+
filePath = relative(contentDirectoryPath, filePath);
|
|
31
|
+
}
|
|
32
|
+
if (!filePath.startsWith(`.${sep}`) && !isAbsolute(filePath)) {
|
|
33
|
+
filePath = `.${sep}${filePath}`;
|
|
34
|
+
}
|
|
35
|
+
if (error && typeof error === 'object') {
|
|
36
|
+
const pos = getPosition(error);
|
|
37
|
+
if (pos?.line != null) {
|
|
38
|
+
filePath += `:${pos.line}`;
|
|
39
|
+
if (pos.column != null) {
|
|
40
|
+
filePath += `:${pos.column}`;
|
|
41
|
+
}
|
|
9
42
|
}
|
|
10
43
|
}
|
|
11
|
-
return
|
|
44
|
+
return filePath;
|
|
12
45
|
};
|
|
@@ -2,6 +2,7 @@ import { validate, validateAsyncApi, buildImportMap, getFileCategory, isSnippetE
|
|
|
2
2
|
import { readFile } from 'fs/promises';
|
|
3
3
|
import yaml from 'js-yaml';
|
|
4
4
|
import * as path from 'path';
|
|
5
|
+
import { formatError } from '../errorMessages/formatError.js';
|
|
5
6
|
import { getFileList } from '../fs/index.js';
|
|
6
7
|
import { getFileExtension } from '../utils.js';
|
|
7
8
|
export const categorizeFilePaths = async (contentDirectoryPath, mintIgnore = [], disableOpenApi) => {
|
|
@@ -13,8 +14,13 @@ export const categorizeFilePaths = async (contentDirectoryPath, mintIgnore = [],
|
|
|
13
14
|
if (isSnippetExtension(extension)) {
|
|
14
15
|
const filePath = path.join(contentDirectoryPath, filename);
|
|
15
16
|
const content = await readFile(filePath, 'utf8');
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
try {
|
|
18
|
+
const tree = getAST(content, filePath);
|
|
19
|
+
mdxFiles.push({ path: filename, tree });
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error(formatError(error, filePath, contentDirectoryPath));
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
else {
|
|
20
26
|
nonMdxFiles.push({ filename, extension });
|