@mintlify/common 1.0.697 → 1.0.704

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,6 +1,11 @@
1
1
  import type { Root } from 'mdast';
2
2
  import type { FileType, FileWithImports } from '../../types/mdx/index.js';
3
+ export type ResolveImportsWarning = {
4
+ type: 'invalid-import-path' | 'missing-file' | 'import-resolution-error';
5
+ message: string;
6
+ };
3
7
  export declare const resolveAllImports: (params: {
4
8
  snippets: FileType[];
5
9
  fileWithImports: FileWithImports;
10
+ onWarning?: (warning: ResolveImportsWarning) => void;
6
11
  }) => Promise<Root>;
@@ -11,18 +11,30 @@ import { getExportMapFromTree } from './getExportMap.js';
11
11
  import { resolveImport } from './resolveImport/index.js';
12
12
  import { resolveImportPath } from './resolveImportPath.js';
13
13
  export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, function* () {
14
- const { snippets, fileWithImports } = params;
14
+ const { snippets, fileWithImports, onWarning } = params;
15
15
  let ast = fileWithImports.tree;
16
16
  const exportMap = getExportMapFromTree(ast);
17
17
  for (const source of Object.keys(fileWithImports.importMap)) {
18
18
  const resolvedPath = resolveImportPath(source, fileWithImports.filename);
19
19
  if (resolvedPath == null) {
20
- console.log(`Invalid import path ${source} in ${fileWithImports.filename}. Only local imports are supported.`);
20
+ const message = `Invalid import path ${source} in ${fileWithImports.filename}. Only local imports are supported.`;
21
+ if (onWarning) {
22
+ onWarning({ type: 'invalid-import-path', message });
23
+ }
24
+ else {
25
+ console.log(message);
26
+ }
21
27
  continue;
22
28
  }
23
29
  const importedSnippet = snippets.find((snippet) => snippet.filename === resolvedPath);
24
30
  if (importedSnippet == undefined) {
25
- console.log(`Could not find file ${resolvedPath} - imported from ${fileWithImports.filename}`);
31
+ const message = `Could not find file ${resolvedPath} - imported from ${fileWithImports.filename}`;
32
+ if (onWarning) {
33
+ onWarning({ type: 'missing-file', message });
34
+ }
35
+ else {
36
+ console.log(message);
37
+ }
26
38
  continue;
27
39
  }
28
40
  const specifiers = fileWithImports.importMap[source];
@@ -37,8 +49,13 @@ export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, f
37
49
  ast = contentWithResolvedImport;
38
50
  }
39
51
  catch (err) {
40
- console.log(`Error resolving import "${specifier.name}" in ${fileWithImports.filename}`);
41
- console.log(err);
52
+ const message = `Error resolving import "${specifier.name}" in ${fileWithImports.filename}: ${err instanceof Error ? err.message : String(err)}`;
53
+ if (onWarning) {
54
+ onWarning({ type: 'import-resolution-error', message });
55
+ }
56
+ else {
57
+ console.log(message);
58
+ }
42
59
  }
43
60
  }
44
61
  }