File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 11import { readdir } from 'fs/promises' ;
22import path from 'path' ;
3+ import pLimit from 'p-limit' ;
34
45/**
56 * @returns Array of file paths
@@ -10,4 +11,18 @@ const getAllFilesRecursively = async (folder: string): Promise<string[]> => {
1011 . map ( dirent => path . join ( dirent . parentPath || dirent . path , dirent . name ) ) ;
1112} ;
1213
14+ /**
15+ * Utility function to limit concurrency of async operations
16+ * @param fn - The async function to limit
17+ * @param options - Options including concurrency limit
18+ * @returns A limited version of the function
19+ */
20+ export function limitFunction < T extends ( ...args : any [ ] ) => Promise < any > > (
21+ fn : T ,
22+ options : { concurrency : number }
23+ ) : T {
24+ const limit = pLimit ( options . concurrency ) ;
25+ return ( ( ...args : Parameters < T > ) => limit ( ( ) => fn ( ...args ) ) ) as T ;
26+ }
27+
1328export default getAllFilesRecursively ;
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ import {
1717 createBrotliCompress ,
1818 createBrotliDecompress ,
1919} from 'node:zlib' ;
20- import { limitFunction } from 'p-limit' ;
2120import rehypeAutolinkHeadings from 'rehype-autolink-headings' ;
2221import rehypePresetMinify from 'rehype-preset-minify' ;
2322import rehypePrismDiff from 'rehype-prism-diff' ;
@@ -28,7 +27,7 @@ import remarkMdxImages from 'remark-mdx-images';
2827import getAppRegistry from './build/appRegistry' ;
2928import getPackageRegistry from './build/packageRegistry' ;
3029import { apiCategories } from './build/resolveOpenAPI' ;
31- import getAllFilesRecursively from './files' ;
30+ import getAllFilesRecursively , { limitFunction } from './files' ;
3231import remarkDefList from './mdx-deflist' ;
3332import rehypeOnboardingLines from './rehype-onboarding-lines' ;
3433import rehypeSlug from './rehype-slug.js' ;
You can’t perform that action at this time.
0 commit comments