@mintlify/common 1.0.1266 → 1.0.1267

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.
@@ -25,19 +25,27 @@ const parse = (content, path) => {
25
25
  return messageOf(error);
26
26
  }
27
27
  };
28
- const topLevelImports = (tree) => tree.children.flatMap((node) => {
28
+ const IMPORT_STATEMENTS = new Set(['ImportDeclaration']);
29
+ const MODULE_SOURCE_STATEMENTS = new Set([
30
+ 'ImportDeclaration',
31
+ 'ExportNamedDeclaration',
32
+ 'ExportAllDeclaration',
33
+ ]);
34
+ const topLevelSources = (tree, statementTypes = IMPORT_STATEMENTS) => tree.children.flatMap((node) => {
29
35
  var _a, _b, _c;
30
36
  if (!isMdxJsEsm(node))
31
37
  return [];
32
38
  return ((_c = (_b = (_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) === null || _b === void 0 ? void 0 : _b.body) !== null && _c !== void 0 ? _c : []).flatMap((statement) => {
33
- var _a, _b, _c;
34
- if (statement.type !== 'ImportDeclaration' || typeof statement.source.value !== 'string') {
39
+ var _a, _b, _c, _d;
40
+ if (!statementTypes.has(statement.type) ||
41
+ !('source' in statement) ||
42
+ typeof ((_a = statement.source) === null || _a === void 0 ? void 0 : _a.value) !== 'string') {
35
43
  return [];
36
44
  }
37
45
  return [
38
46
  {
39
47
  source: statement.source.value,
40
- line: (_b = (_a = statement.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : (_c = node.position) === null || _c === void 0 ? void 0 : _c.start.line,
48
+ line: (_c = (_b = statement.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _c !== void 0 ? _c : (_d = node.position) === null || _d === void 0 ? void 0 : _d.start.line,
41
49
  },
42
50
  ];
43
51
  });
@@ -46,14 +54,14 @@ export const sortPackageProblems = (problems) => [...problems].sort((a, b) => {
46
54
  export const classifyPackageSources = (files, { packageNames, variables, normalizeImportSource = (source) => source, }) => {
47
55
  var _a;
48
56
  const resolve = (source, importer) => resolveImportPath(normalizeImportSource(source, importer), importer);
49
- const usesPackages = ({ path, content }) => [...replaceVariables(content, variables).matchAll(IMPORT_SOURCE)].some(([, from, bare]) => {
50
- var _a;
51
- const source = normalizeImportSource((_a = from !== null && from !== void 0 ? from : bare) !== null && _a !== void 0 ? _a : '', path);
57
+ const importsPackage = (from, path) => {
58
+ const source = normalizeImportSource(from, path);
52
59
  if (isDeclaredPackageImport(source, packageNames))
53
60
  return true;
54
61
  const resolved = resolveImportPath(source, path);
55
62
  return resolved !== null && isPackageSnippetPath(resolved);
56
- });
63
+ };
64
+ const textUsesPackages = ({ path, content }) => [...replaceVariables(content, variables).matchAll(IMPORT_SOURCE)].some(([, from, bare]) => { var _a; return importsPackage((_a = from !== null && from !== void 0 ? from : bare) !== null && _a !== void 0 ? _a : '', path); });
57
65
  const parsed = [];
58
66
  const failed = [];
59
67
  for (const file of [...files].sort((a, b) => compare(a.path, b.path))) {
@@ -61,7 +69,7 @@ export const classifyPackageSources = (files, { packageNames, variables, normali
61
69
  if (typeof tree === 'string')
62
70
  failed.push(Object.assign(Object.assign({}, file), { message: tree }));
63
71
  else
64
- parsed.push(Object.assign(Object.assign({}, file), { tree, imports: topLevelImports(tree) }));
72
+ parsed.push(Object.assign(Object.assign({}, file), { tree, imports: topLevelSources(tree) }));
65
73
  }
66
74
  const importedFiles = new Set();
67
75
  for (const file of parsed) {
@@ -90,12 +98,13 @@ export const classifyPackageSources = (files, { packageNames, variables, normali
90
98
  for (const file of failed) {
91
99
  const category = categoryOf(file.path);
92
100
  result.unparsed.push({ path: file.path, content: file.content, category });
93
- if (usesPackages(file))
101
+ if (textUsesPackages(file))
94
102
  result.errors.push({ file: file.path, message: file.message });
95
103
  }
96
104
  for (const file of parsed) {
97
105
  const category = categoryOf(file.path);
98
- if (category === 'legacySnippet' && usesPackages(file)) {
106
+ if (category === 'legacySnippet' &&
107
+ topLevelSources(file.tree, MODULE_SOURCE_STATEMENTS).some(({ source }) => importsPackage(source, file.path))) {
99
108
  result.errors.push({
100
109
  file: file.path,
101
110
  message: "uses npm package components, which don't work in files included with <Snippet>. Import it into the page instead.",