@mintlify/common 1.0.638 → 1.0.640

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.
@@ -17,4 +17,4 @@ export declare function isGatedFormat(params: {
17
17
  filePath?: undefined;
18
18
  ext: string;
19
19
  }): boolean;
20
- export declare const getFileCategory: (filePath: string) => PotentialFileCategory;
20
+ export declare const getFileCategory: (filePath: string, snippetPatterns?: string[]) => PotentialFileCategory;
@@ -1,5 +1,6 @@
1
1
  import { parse } from 'path';
2
2
  import { SNIPPET_EXTENSIONS } from './mdx/snippets/constants.js';
3
+ import { isSnippetPath } from './snippetPatterns.js';
3
4
  const excludedMdFiles = ['readme', 'license', 'contributing', 'contribute'];
4
5
  export const generatedStaticFiles = [
5
6
  'llms.txt',
@@ -73,7 +74,7 @@ export function isGatedFormat({ filePath, ext }) {
73
74
  ext = ext.startsWith('.') ? ext : `.${ext}`;
74
75
  return gatedStaticAssetExtensions.includes(ext.toLowerCase());
75
76
  }
76
- export const getFileCategory = (filePath) => {
77
+ export const getFileCategory = (filePath, snippetPatterns) => {
77
78
  filePath = filePath.toLowerCase();
78
79
  const parsed = parse(filePath);
79
80
  if (parsed.base === 'mint.json') {
@@ -90,16 +91,16 @@ export const getFileCategory = (filePath) => {
90
91
  if (generatedStaticFiles.includes(parsed.base)) {
91
92
  return 'generatedStaticFile';
92
93
  }
93
- if ((filePath.startsWith('_snippets/') || filePath.startsWith('snippets/')) &&
94
- (SNIPPET_EXTENSIONS.some((ext) => extension === ext) || extension === '.md')) {
94
+ const hasSnippetExtension = SNIPPET_EXTENSIONS.some((ext) => extension === ext) || extension === '.md';
95
+ if (hasSnippetExtension) {
95
96
  if (filePath.startsWith('_snippets/')) {
96
97
  return 'snippet';
97
98
  }
98
- else if (filePath.startsWith('snippets/')) {
99
+ if (isSnippetPath(filePath, snippetPatterns)) {
99
100
  return 'snippet-v2';
100
101
  }
101
102
  }
102
- else if (extension === '.mdx') {
103
+ if (extension === '.mdx') {
103
104
  return 'page';
104
105
  }
105
106
  else if (extension === '.md') {
package/dist/index.d.ts CHANGED
@@ -27,3 +27,4 @@ export * from './truncateAtWordBoundary.js';
27
27
  export * from './api-reference/parseApiTargetFromMetadata.js';
28
28
  export * from './mintIgnore.js';
29
29
  export * from './getDisplayDomain.js';
30
+ export * from './snippetPatterns.js';
package/dist/index.js CHANGED
@@ -27,3 +27,4 @@ export * from './truncateAtWordBoundary.js';
27
27
  export * from './api-reference/parseApiTargetFromMetadata.js';
28
28
  export * from './mintIgnore.js';
29
29
  export * from './getDisplayDomain.js';
30
+ export * from './snippetPatterns.js';
@@ -3,4 +3,5 @@ import type { FileType, FileWithImports } from '../../types/mdx/index.js';
3
3
  export declare const resolveAllImports: (params: {
4
4
  snippets: FileType[];
5
5
  fileWithImports: FileWithImports;
6
+ snippetPatterns?: string[];
6
7
  }) => Promise<Root>;
@@ -11,13 +11,13 @@ import { getExportMapFromTree } from './getExportMap.js';
11
11
  import { resolveImport } from './resolveImport/index.js';
12
12
  import { resolveSnippetImportPath } from './resolveSnippetImportPath.js';
13
13
  export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, function* () {
14
- const { snippets, fileWithImports } = params;
14
+ const { snippets, fileWithImports, snippetPatterns } = params;
15
15
  let ast = fileWithImports.tree;
16
16
  const exportMap = getExportMapFromTree(ast);
17
17
  for (const source of Object.keys(fileWithImports.importMap)) {
18
- const resolvedPath = resolveSnippetImportPath(source, fileWithImports.filename);
18
+ const resolvedPath = resolveSnippetImportPath(source, fileWithImports.filename, snippetPatterns);
19
19
  if (resolvedPath == null) {
20
- console.log(`Invalid import path ${source} in ${fileWithImports.filename}. Import must resolve to a file in /snippets/.`);
20
+ console.log(`Invalid import path ${source} in ${fileWithImports.filename}. Import must resolve to a valid snippet location.`);
21
21
  continue;
22
22
  }
23
23
  const importedSnippet = snippets.find((snippet) => snippet.filename === resolvedPath);
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * Resolves an import path to an absolute path with leading slash.
3
- * Only allows imports that resolve to files in /snippets/.
3
+ * Only allows imports that resolve to files in valid snippet locations.
4
4
  *
5
5
  * @param source The import source path (e.g., '/snippets/foo.mdx' or '../snippets/bar.mdx')
6
6
  * @param importingFilePath The path of the file containing the import
7
+ * @param snippetPatterns Optional custom snippet patterns from docs.json config
7
8
  * @returns The resolved absolute path with leading slash, or null if invalid or not in snippets folder
8
9
  */
9
- export declare const resolveSnippetImportPath: (source: string, importingFilePath: string) => string | null;
10
+ export declare const resolveSnippetImportPath: (source: string, importingFilePath: string, snippetPatterns?: string[]) => string | null;
@@ -1,19 +1,18 @@
1
1
  import { posix } from 'path';
2
+ import { isSnippetPath } from '../../snippetPatterns.js';
2
3
  const isRelativeImport = (source) => {
3
4
  return source.startsWith('./') || source.startsWith('../');
4
5
  };
5
- const isInSnippetsFolder = (resolvedPath) => {
6
- return resolvedPath.startsWith('/snippets/');
7
- };
8
6
  /**
9
7
  * Resolves an import path to an absolute path with leading slash.
10
- * Only allows imports that resolve to files in /snippets/.
8
+ * Only allows imports that resolve to files in valid snippet locations.
11
9
  *
12
10
  * @param source The import source path (e.g., '/snippets/foo.mdx' or '../snippets/bar.mdx')
13
11
  * @param importingFilePath The path of the file containing the import
12
+ * @param snippetPatterns Optional custom snippet patterns from docs.json config
14
13
  * @returns The resolved absolute path with leading slash, or null if invalid or not in snippets folder
15
14
  */
16
- export const resolveSnippetImportPath = (source, importingFilePath) => {
15
+ export const resolveSnippetImportPath = (source, importingFilePath, snippetPatterns) => {
17
16
  let resolvedPath;
18
17
  if (source.startsWith('/')) {
19
18
  resolvedPath = posix.normalize(source);
@@ -25,7 +24,7 @@ export const resolveSnippetImportPath = (source, importingFilePath) => {
25
24
  else {
26
25
  return null;
27
26
  }
28
- if (!isInSnippetsFolder(resolvedPath)) {
27
+ if (!isSnippetPath(resolvedPath, snippetPatterns)) {
29
28
  return null;
30
29
  }
31
30
  return resolvedPath;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Default snippet patterns that are always included. Always includes the /snippets/ pattern.
3
+ */
4
+ export declare const DEFAULT_SNIPPET_PATTERNS: string[];
5
+ /**
6
+ * Checks if a file path matches the snippet patterns.
7
+ * Always includes the default /snippets/ pattern in addition to any custom patterns.
8
+ *
9
+ * @param filePath The path of the file to check (with or without leading slash)
10
+ * @param customPatterns Optional array of custom glob patterns from docs.json
11
+ * @returns True if the file matches any of the snippet patterns
12
+ */
13
+ export declare function isSnippetPath(filePath: string, customPatterns?: string[]): boolean;
@@ -0,0 +1,18 @@
1
+ import { minimatch } from 'minimatch';
2
+ /**
3
+ * Default snippet patterns that are always included. Always includes the /snippets/ pattern.
4
+ */
5
+ export const DEFAULT_SNIPPET_PATTERNS = ['snippets/**'];
6
+ /**
7
+ * Checks if a file path matches the snippet patterns.
8
+ * Always includes the default /snippets/ pattern in addition to any custom patterns.
9
+ *
10
+ * @param filePath The path of the file to check (with or without leading slash)
11
+ * @param customPatterns Optional array of custom glob patterns from docs.json
12
+ * @returns True if the file matches any of the snippet patterns
13
+ */
14
+ export function isSnippetPath(filePath, customPatterns) {
15
+ const normalizedPath = filePath.startsWith('/') ? filePath.slice(1) : filePath;
16
+ const allPatterns = [...DEFAULT_SNIPPET_PATTERNS, ...(customPatterns !== null && customPatterns !== void 0 ? customPatterns : [])];
17
+ return allPatterns.some((pattern) => minimatch(normalizedPath, pattern, { nocase: true }));
18
+ }