@mintlify/common 1.0.571 → 1.0.573

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.
@@ -3,6 +3,7 @@ import type { PageMetaTags, PageType } from '@mintlify/models';
3
3
  import { CodeStyling, DocsConfig } from '@mintlify/validation';
4
4
  import { MdxExtracts } from '../../index.js';
5
5
  import { createSnippetTreeMap, type Snippet } from './getMdx/snippets.js';
6
+ type RunWithTracingFn = <T>(spanName: string, fn: () => Promise<T>) => Promise<T>;
6
7
  export type GetMdxType = {
7
8
  mdxSource: SerializeSuccess;
8
9
  mdxSourceWithNoJs: SerializeSuccess;
@@ -10,7 +11,7 @@ export type GetMdxType = {
10
11
  panelMdxSource?: SerializeSuccess;
11
12
  panelMdxSourceWithNoJs?: SerializeSuccess;
12
13
  };
13
- export declare function getMdx({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors, pageType, }: {
14
+ export declare function getMdx({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors, pageType, trace, }: {
14
15
  path: string;
15
16
  content: string;
16
17
  metadata: PageMetaTags;
@@ -20,5 +21,6 @@ export declare function getMdx({ path, content, metadata, snippets, subdomain, c
20
21
  config?: Pick<DocsConfig, 'api' | '$schema'>;
21
22
  tailwindSelectors?: string[] | undefined;
22
23
  pageType?: PageType;
24
+ trace?: RunWithTracingFn;
23
25
  }): Promise<GetMdxType>;
24
26
  export { createSnippetTreeMap, type Snippet };
@@ -13,10 +13,11 @@ import { getMDXOptions, remarkMdxRemoveJs, remarkExpandContent, remarkSplitCodeG
13
13
  import { codeStylingToThemeOrThemes } from '../getCodeStyling.js';
14
14
  import { createSnippetTreeMap } from './getMdx/snippets.js';
15
15
  export function getMdx(_a) {
16
- return __awaiter(this, arguments, void 0, function* ({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors = undefined, pageType = 'default', }) {
16
+ return __awaiter(this, arguments, void 0, function* ({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors = undefined, pageType = 'default', trace = undefined, }) {
17
+ const traceFn = trace !== null && trace !== void 0 ? trace : ((_name, fn) => fn());
17
18
  if (!tailwindSelectors)
18
- tailwindSelectors = yield getTailwindSelectors({ content });
19
- const snippetTreeMap = yield createSnippetTreeMap(snippets);
19
+ tailwindSelectors = yield traceFn('getMdx.getTailwindSelectors', () => __awaiter(this, void 0, void 0, function* () { return getTailwindSelectors({ content }); }));
20
+ const snippetTreeMap = yield traceFn('getMdx.createSnippetTreeMap', () => __awaiter(this, void 0, void 0, function* () { return createSnippetTreeMap(snippets); }));
20
21
  const mdxOptionsData = {
21
22
  subdomain,
22
23
  snippetTreeMap,
@@ -40,13 +41,13 @@ export function getMdx(_a) {
40
41
  config,
41
42
  pageMetadata: metadata,
42
43
  };
43
- const { mdxSource, mdxSourceWithNoJs } = yield compileMdx(content, scope, mdxOptions, mdxOptionsNoJs, codeStyling, path);
44
+ const { mdxSource, mdxSourceWithNoJs } = yield traceFn('getMdx.compileMdx.mainContent', () => __awaiter(this, void 0, void 0, function* () { return compileMdx(content, scope, mdxOptions, mdxOptionsNoJs, codeStyling, path, traceFn); }));
44
45
  const originalMdxExtracts = structuredClone(mdxExtracts);
45
46
  let panelMdxSource;
46
47
  let panelMdxSourceWithNoJs;
47
48
  if (mdxExtracts.panel && mdxExtracts.panel.content) {
48
49
  const panelContent = mdxExtracts.panel.content;
49
- const compiledMdx = yield compileMdx(panelContent, scope, mdxOptions, mdxOptionsNoJs, codeStyling, path);
50
+ const compiledMdx = yield traceFn('getMdx.compileMdx.panelContent', () => __awaiter(this, void 0, void 0, function* () { return compileMdx(panelContent, scope, mdxOptions, mdxOptionsNoJs, codeStyling, path, traceFn); }));
50
51
  panelMdxSource = compiledMdx.mdxSource;
51
52
  panelMdxSourceWithNoJs = compiledMdx.mdxSourceWithNoJs;
52
53
  // serializing mdx content with the panel content will remove the original mdxExtracts
@@ -62,23 +63,25 @@ export function getMdx(_a) {
62
63
  };
63
64
  });
64
65
  }
65
- function compileMdx(content, scope, mdxOptions, mdxOptionsNoJs, codeStyling, path) {
66
+ function compileMdx(content, scope, mdxOptions, mdxOptionsNoJs, codeStyling, path, traceFn) {
66
67
  return __awaiter(this, void 0, void 0, function* () {
67
- const mdxSource = yield getCompiledMdxWithFallback(content, scope, mdxOptions, codeStyling, path);
68
- const mdxSourceWithNoJs = yield getCompiledMdxWithFallback(content, scope, mdxOptionsNoJs, codeStyling, path);
68
+ const mdxSource = yield traceFn('compileMdx.withJs', () => __awaiter(this, void 0, void 0, function* () { return getCompiledMdxWithFallback(content, scope, mdxOptions, codeStyling, path, traceFn); }));
69
+ const mdxSourceWithNoJs = yield traceFn('compileMdx.withoutJs', () => __awaiter(this, void 0, void 0, function* () { return getCompiledMdxWithFallback(content, scope, mdxOptionsNoJs, codeStyling, path, traceFn); }));
69
70
  return { mdxSource, mdxSourceWithNoJs };
70
71
  });
71
72
  }
72
- function getCompiledMdxWithFallback(source, scope, mdxOptions, codeStyling, path) {
73
+ function getCompiledMdxWithFallback(source, scope, mdxOptions, codeStyling, path, traceFn) {
73
74
  return __awaiter(this, void 0, void 0, function* () {
74
75
  const themeOrThemes = codeStylingToThemeOrThemes(codeStyling);
75
76
  try {
76
- const result = yield serialize({
77
- source,
78
- scope,
79
- mdxOptions,
80
- syntaxHighlightingOptions: Object.assign({}, themeOrThemes),
81
- });
77
+ const result = yield traceFn('getCompiledMdxWithFallback.serialize', () => __awaiter(this, void 0, void 0, function* () {
78
+ return serialize({
79
+ source,
80
+ scope,
81
+ mdxOptions,
82
+ syntaxHighlightingOptions: Object.assign({}, themeOrThemes),
83
+ });
84
+ }));
82
85
  if ('error' in result) {
83
86
  throw result.error;
84
87
  }
@@ -89,11 +92,13 @@ function getCompiledMdxWithFallback(source, scope, mdxOptions, codeStyling, path
89
92
  if (path)
90
93
  console.log(`⚠️ Warning: MDX failed to parse page ${path}: `, err);
91
94
  // placeholder content for when there is a syntax error.
92
- const fallbackResult = yield serialize({
93
- source: '🚧 A parsing error occured. Please contact the owner of this website. They can use the Mintlify CLI to test this website locally and see the errors that occur.',
94
- scope,
95
- mdxOptions,
96
- });
95
+ const fallbackResult = yield traceFn('getCompiledMdxWithFallback.serialize.fallback', () => __awaiter(this, void 0, void 0, function* () {
96
+ return serialize({
97
+ source: '🚧 A parsing error occured. Please contact the owner of this website. They can use the Mintlify CLI to test this website locally and see the errors that occur.',
98
+ scope,
99
+ mdxOptions,
100
+ });
101
+ }));
97
102
  if ('error' in fallbackResult) {
98
103
  throw fallbackResult.error;
99
104
  }