@mintlify/prebuild 1.0.1233 → 1.0.1235

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.
@@ -46,17 +46,20 @@ const extractImportSourcesFromContent = (content) => {
46
46
  }
47
47
  return { sources, needsAst };
48
48
  };
49
- const getImportSources = (content, filePath, lazyPages) => {
50
- if (lazyPages) {
51
- if (!MDX_IMPORT_PATTERN.test(content)) {
52
- return [];
53
- }
54
- const { sources, needsAst } = extractImportSourcesFromContent(content);
55
- if (!needsAst) {
56
- return sources;
57
- }
49
+ const getImportSources = (content, filePath) => {
50
+ if (!MDX_IMPORT_PATTERN.test(content)) {
51
+ return [];
52
+ }
53
+ const { sources, needsAst } = extractImportSourcesFromContent(content);
54
+ if (!needsAst) {
55
+ return sources;
56
+ }
57
+ try {
58
+ return extractImportSources(getAST(content, filePath));
59
+ }
60
+ catch {
61
+ return sources;
58
62
  }
59
- return extractImportSources(getAST(content, filePath));
60
63
  };
61
64
  export const categorizeFilePaths = async (contentDirectoryPath, mintIgnore = [], disableOpenApi, lazyPages) => {
62
65
  const allFilenames = [];
@@ -87,7 +90,7 @@ export const categorizeFilePaths = async (contentDirectoryPath, mintIgnore = [],
87
90
  try {
88
91
  const content = await readFile(filePath, 'utf8');
89
92
  const resolvedImports = new Set();
90
- for (const source of getImportSources(content, filePath, lazyPages)) {
93
+ for (const source of getImportSources(content, filePath)) {
91
94
  const resolved = resolveImportPath(source, filename);
92
95
  if (resolved) {
93
96
  const normalized = resolved.toLowerCase();
@@ -3,6 +3,7 @@ import { promises as _promises } from 'fs';
3
3
  import { outputFile } from 'fs-extra';
4
4
  import { join } from 'path';
5
5
  import { preparseMdxTree } from '../../../createPage/preparseMdx/index.js';
6
+ import { warnOnParseError } from '../../warnings.js';
6
7
  import { preserveAutoGeneratedMetadata } from '../preserveAutoGeneratedMetadata.js';
7
8
  const { readFile } = _promises;
8
9
  const PAGE_PARSE_CONCURRENCY = 8;
@@ -16,7 +17,7 @@ export const readPageContents = async ({ contentDirectoryPath, openApiFiles, asy
16
17
  let treeToWrite;
17
18
  try {
18
19
  const contentStr = (await readFile(sourcePath)).toString();
19
- const tree = await preparseMdxTree(contentStr, contentDirectoryPath, sourcePath);
20
+ const tree = await preparseMdxTree(contentStr, contentDirectoryPath, sourcePath, warnOnParseError);
20
21
  const importsResponse = await findAndRemoveImports(tree);
21
22
  if (hasImports(importsResponse)) {
22
23
  let metadata;
@@ -67,7 +68,7 @@ export const readSnippetsV2Contents = (contentDirectoryPath, snippetV2Filenames,
67
68
  const snippetV2Promises = snippetV2Filenames.map(async (filename) => {
68
69
  const sourcePath = join(contentDirectoryPath, filename);
69
70
  const contentStr = replaceVariables(await readFile(sourcePath, 'utf8'), variables);
70
- const tree = await preparseMdxTree(contentStr, contentDirectoryPath, sourcePath);
71
+ const tree = await preparseMdxTree(contentStr, contentDirectoryPath, sourcePath, warnOnParseError);
71
72
  return { filename, tree };
72
73
  });
73
74
  return Promise.all(snippetV2Promises);
@@ -1,7 +1,8 @@
1
1
  export type Warning = {
2
- type: 'missing-file' | 'missing-nav-page' | 'openapi' | 'invalid-import-path' | 'import-resolution-error' | 'default-import-no-default-export';
2
+ type: 'missing-file' | 'missing-nav-page' | 'openapi' | 'invalid-import-path' | 'import-resolution-error' | 'default-import-no-default-export' | 'parse-error';
3
3
  message: string;
4
4
  };
5
5
  export declare const clearWarnings: () => void;
6
6
  export declare const addWarning: (warning: Warning) => void;
7
+ export declare const warnOnParseError: (message: string) => void;
7
8
  export declare const checkStrictMode: (strict?: boolean) => void;
@@ -7,6 +7,9 @@ export const addWarning = (warning) => {
7
7
  warnings.push(warning);
8
8
  console.log(chalk.yellow.bold('warning') + ' - ' + warning.message);
9
9
  };
10
+ export const warnOnParseError = (message) => {
11
+ addWarning({ type: 'parse-error', message: message.trim() });
12
+ };
10
13
  export const checkStrictMode = (strict) => {
11
14
  if (strict && warnings.length > 0) {
12
15
  throw new Error(`Build validation failed with ${warnings.length} warning(s). See above for details.`);