@mintlify/common 1.0.1309 → 1.0.1310

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.
@@ -5,6 +5,7 @@ import { type PackageImportOptions } from '../islands/packageImports.js';
5
5
  export type ResolveImportsWarning = {
6
6
  type: 'invalid-import-path' | 'missing-file' | 'import-resolution-error' | 'default-import-no-default-export' | 'export-collision' | 'undeclared-package' | 'package-import-conflict';
7
7
  message: string;
8
+ file?: string;
8
9
  };
9
10
  export declare const resolveAllImports: (params: {
10
11
  snippets: (FileType & {
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { jsx, toJs } from 'estree-util-to-js';
11
11
  import { remove } from 'unist-util-remove';
12
12
  import { visit } from 'unist-util-visit';
13
+ import { normalizeRelativePath } from '../../fs/normalizeRelativePath.js';
13
14
  import { MdxImportSpecifier } from '../../types/mdx/snippets/import.js';
14
15
  import { createImportNode, isDeclaredPackageImport, isNonHostBareImport, mergeImports, } from '../islands/packageImports.js';
15
16
  import { estreeIsProgram, isImportDeclaration, isMdxJsEsm } from '../utils.js';
@@ -109,6 +110,7 @@ export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, f
109
110
  var _a;
110
111
  var _b, _c, _d, _e;
111
112
  const { snippets, fileWithImports, onWarning, packages } = params;
113
+ const file = normalizeRelativePath(fileWithImports.filename);
112
114
  let ast = fileWithImports.tree;
113
115
  const kept = packages && /\.mdx?$/.test(fileWithImports.filename)
114
116
  ? takePackageReExports(ast, packages.packageNames)
@@ -125,7 +127,7 @@ export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, f
125
127
  }
126
128
  const message = `Package ${(_c = getSpecifierPackageName(source)) !== null && _c !== void 0 ? _c : source} imported in ${fileWithImports.filename} is not declared in package.json dependencies.`;
127
129
  if (onWarning) {
128
- onWarning({ type: 'undeclared-package', message });
130
+ onWarning({ type: 'undeclared-package', message, file });
129
131
  }
130
132
  else {
131
133
  console.log(message);
@@ -139,7 +141,7 @@ export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, f
139
141
  if (resolvedPath == null) {
140
142
  const message = `Invalid import path ${source} in ${fileWithImports.filename}. Only local imports are supported.`;
141
143
  if (onWarning) {
142
- onWarning({ type: 'invalid-import-path', message });
144
+ onWarning({ type: 'invalid-import-path', message, file });
143
145
  }
144
146
  else {
145
147
  console.log(message);
@@ -150,7 +152,7 @@ export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, f
150
152
  if (foundSnippet == undefined) {
151
153
  const message = `Could not find file ${resolvedPath} - imported from ${fileWithImports.filename}`;
152
154
  if (onWarning) {
153
- onWarning({ type: 'missing-file', message });
155
+ onWarning({ type: 'missing-file', message, file });
154
156
  }
155
157
  else {
156
158
  console.log(message);
@@ -178,7 +180,7 @@ export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, f
178
180
  importedSnippet.tree.children.every((node) => node.type === 'yaml' || node.type === 'mdxjsEsm')) {
179
181
  const message = `Default import "${specifier.name}" in ${fileWithImports.filename} will not render — ${resolvedPath} has no default export. Use a named import instead: import { ExportName } from '${source}'`;
180
182
  if (onWarning) {
181
- onWarning({ type: 'default-import-no-default-export', message });
183
+ onWarning({ type: 'default-import-no-default-export', message, file });
182
184
  }
183
185
  else {
184
186
  console.log(message);
@@ -187,7 +189,7 @@ export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, f
187
189
  try {
188
190
  const contentWithResolvedImport = yield resolveImport(specifier, ast, importedSnippet.tree, exportMap, (warning) => {
189
191
  // the collision itself doesn't know which page it happened in, so add it here
190
- const located = Object.assign(Object.assign({}, warning), { message: `${warning.message} (in ${fileWithImports.filename}, importing ${resolvedPath})` });
192
+ const located = Object.assign(Object.assign({}, warning), { message: `${warning.message} (in ${fileWithImports.filename}, importing ${resolvedPath})`, file });
191
193
  if (onWarning) {
192
194
  onWarning(located);
193
195
  }
@@ -203,7 +205,7 @@ export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, f
203
205
  catch (err) {
204
206
  const message = `Error resolving import "${specifier.name}" in ${fileWithImports.filename}: ${err instanceof Error ? err.message : String(err)}`;
205
207
  if (onWarning) {
206
- onWarning({ type: 'import-resolution-error', message });
208
+ onWarning({ type: 'import-resolution-error', message, file });
207
209
  }
208
210
  else {
209
211
  console.log(message);
@@ -221,7 +223,7 @@ export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, f
221
223
  for (const { local, first, second } of conflicts) {
222
224
  const message = `${local} is imported twice in ${fileWithImports.filename}, as ${first} and as ${second}. Snippets inlined into a page share its imports, so import one of them under another name.`;
223
225
  if (onWarning) {
224
- onWarning({ type: 'package-import-conflict', message });
226
+ onWarning({ type: 'package-import-conflict', message, file });
225
227
  }
226
228
  else {
227
229
  console.log(message);