1- import * as fs from " node:fs" ;
2- import * as path from " node:path" ;
3- import { fileURLToPath } from " node:url" ;
1+ import * as fs from ' node:fs' ;
2+ import * as path from ' node:path' ;
3+ import { fileURLToPath } from ' node:url' ;
44
55interface Package {
66 name : string ;
@@ -9,23 +9,23 @@ interface Package {
99 hasVitePlusConfig : boolean ;
1010}
1111
12- const __dirname = path . join ( fileURLToPath ( import . meta. url ) , ".." ) ;
12+ const __dirname = path . join ( fileURLToPath ( import . meta. url ) , '..' ) ;
1313
1414class MonorepoGenerator {
1515 private packages : Map < string , Package > = new Map ( ) ;
1616 private readonly PACKAGE_COUNT = 1000 ;
1717 private readonly MAX_DEPS_PER_PACKAGE = 8 ;
1818 private readonly MIN_DEPS_PER_PACKAGE = 2 ;
1919 private readonly SCRIPT_NAMES = [
20- " build" ,
21- " test" ,
22- " lint" ,
23- " dev" ,
24- " start" ,
25- " prepare" ,
26- " compile" ,
20+ ' build' ,
21+ ' test' ,
22+ ' lint' ,
23+ ' dev' ,
24+ ' start' ,
25+ ' prepare' ,
26+ ' compile' ,
2727 ] ;
28- private readonly CATEGORIES = [ " core" , " util" , " feature" , " service" , " app" ] ;
28+ private readonly CATEGORIES = [ ' core' , ' util' , ' feature' , ' service' , ' app' ] ;
2929
3030 constructor ( private rootDir : string ) { }
3131
@@ -39,7 +39,7 @@ class MonorepoGenerator {
3939
4040 private generatePackageName ( index : number ) : string {
4141 const category = this . getRandomElement ( this . CATEGORIES ) ;
42- const paddedIndex = index . toString ( ) . padStart ( 2 , "0" ) ;
42+ const paddedIndex = index . toString ( ) . padStart ( 2 , '0' ) ;
4343 return `${ category } -${ paddedIndex } ` ;
4444 }
4545
@@ -66,7 +66,7 @@ class MonorepoGenerator {
6666 selectedCommands . push ( this . getRandomElement ( commands ) ) ;
6767 }
6868
69- return selectedCommands . join ( " && " ) ;
69+ return selectedCommands . join ( ' && ' ) ;
7070 }
7171
7272 private generateScripts ( packageName : string ) : Record < string , string > {
@@ -100,7 +100,7 @@ class MonorepoGenerator {
100100 // Create a complex graph by selecting dependencies from different layers
101101 // Prefer packages with lower indices (creates deeper dependency chains)
102102 const eligiblePackages = availablePackages . filter ( ( pkg ) => {
103- const pkgIndex = parseInt ( pkg . split ( "-" ) [ 1 ] ) ;
103+ const pkgIndex = parseInt ( pkg . split ( '-' ) [ 1 ] ) ;
104104 return pkgIndex < currentIndex ;
105105 } ) ;
106106
@@ -119,8 +119,8 @@ class MonorepoGenerator {
119119 // Add some cross-category dependencies for complexity
120120 if ( Math . random ( ) > 0.3 ) {
121121 const crossCategoryDeps = availablePackages . filter ( ( pkg ) => {
122- const category = pkg . split ( "-" ) [ 0 ] ;
123- return category !== currentIndex . toString ( ) . split ( "-" ) [ 0 ] ;
122+ const category = pkg . split ( '-' ) [ 0 ] ;
123+ return category !== currentIndex . toString ( ) . split ( '-' ) [ 0 ] ;
124124 } ) ;
125125
126126 if ( crossCategoryDeps . length > 0 ) {
@@ -196,74 +196,74 @@ class MonorepoGenerator {
196196 }
197197
198198 private writePackage ( pkg : Package ) : void {
199- const packageDir = path . join ( this . rootDir , " packages" , pkg . name ) ;
199+ const packageDir = path . join ( this . rootDir , ' packages' , pkg . name ) ;
200200
201201 // Create directory structure
202202 fs . mkdirSync ( packageDir , { recursive : true } ) ;
203- fs . mkdirSync ( path . join ( packageDir , " src" ) , { recursive : true } ) ;
203+ fs . mkdirSync ( path . join ( packageDir , ' src' ) , { recursive : true } ) ;
204204
205205 // Write package.json
206206 const packageJson = {
207207 name : `@monorepo/${ pkg . name } ` ,
208- version : " 1.0.0" ,
209- main : " src/index.js" ,
208+ version : ' 1.0.0' ,
209+ main : ' src/index.js' ,
210210 scripts : pkg . scripts ,
211211 dependencies : pkg . dependencies . reduce (
212212 ( deps , dep ) => {
213- deps [ `@monorepo/${ dep } ` ] = " workspace:*" ;
213+ deps [ `@monorepo/${ dep } ` ] = ' workspace:*' ;
214214 return deps ;
215215 } ,
216216 { } as Record < string , string > ,
217217 ) ,
218218 } ;
219219
220220 fs . writeFileSync (
221- path . join ( packageDir , " package.json" ) ,
221+ path . join ( packageDir , ' package.json' ) ,
222222 JSON . stringify ( packageJson , null , 2 ) ,
223223 ) ;
224224
225225 // Write source file
226226 const indexContent = `// ${ pkg . name } module
227- export function ${ pkg . name . replace ( "-" , "_" ) } () {
227+ export function ${ pkg . name . replace ( '-' , '_' ) } () {
228228 console.log('Executing ${ pkg . name } ');
229- ${ pkg . dependencies . map ( ( dep ) => ` require('@monorepo/${ dep } ');` ) . join ( "\n" ) }
229+ ${ pkg . dependencies . map ( ( dep ) => ` require('@monorepo/${ dep } ');` ) . join ( '\n' ) }
230230}
231231
232- module.exports = { ${ pkg . name . replace ( "-" , "_" ) } };
232+ module.exports = { ${ pkg . name . replace ( '-' , '_' ) } };
233233` ;
234234
235- fs . writeFileSync ( path . join ( packageDir , " src" , " index.js" ) , indexContent ) ;
235+ fs . writeFileSync ( path . join ( packageDir , ' src' , ' index.js' ) , indexContent ) ;
236236
237237 // Write vite-plus.json if needed
238238 if ( pkg . hasVitePlusConfig ) {
239239 const vitePlusConfig = {
240- extends : " ../../vite-plus.json" ,
240+ extends : ' ../../vite-plus.json' ,
241241 tasks : {
242242 build : {
243243 cache : true ,
244244 env : {
245- NODE_ENV : " production" ,
245+ NODE_ENV : ' production' ,
246246 } ,
247247 } ,
248248 } ,
249249 } ;
250250
251251 fs . writeFileSync (
252- path . join ( packageDir , " vite-plus.json" ) ,
252+ path . join ( packageDir , ' vite-plus.json' ) ,
253253 JSON . stringify ( vitePlusConfig , null , 2 ) ,
254254 ) ;
255255 }
256256 }
257257
258258 public generate ( ) : void {
259- console . log ( " Generating monorepo structure..." ) ;
259+ console . log ( ' Generating monorepo structure...' ) ;
260260
261261 // Clean and create root directory
262262 if ( fs . existsSync ( this . rootDir ) ) {
263263 fs . rmSync ( this . rootDir , { recursive : true , force : true } ) ;
264264 }
265265 fs . mkdirSync ( this . rootDir , { recursive : true } ) ;
266- fs . mkdirSync ( path . join ( this . rootDir , " packages" ) , { recursive : true } ) ;
266+ fs . mkdirSync ( path . join ( this . rootDir , ' packages' ) , { recursive : true } ) ;
267267
268268 // Generate packages
269269 this . generatePackages ( ) ;
@@ -280,22 +280,22 @@ module.exports = { ${pkg.name.replace("-", "_")} };
280280
281281 // Write root package.json
282282 const rootPackageJson = {
283- name : " monorepo-benchmark" ,
284- version : " 1.0.0" ,
283+ name : ' monorepo-benchmark' ,
284+ version : ' 1.0.0' ,
285285 private : true ,
286- workspaces : [ " packages/*" ] ,
286+ workspaces : [ ' packages/*' ] ,
287287 scripts : {
288- " build:all" : " vite run build" ,
289- " test:all" : " vite run test" ,
290- " lint:all" : " vite run lint" ,
288+ ' build:all' : ' vite run build' ,
289+ ' test:all' : ' vite run test' ,
290+ ' lint:all' : ' vite run lint' ,
291291 } ,
292292 devDependencies : {
293- " @voidzero-dev/vite-plus" : "*" ,
293+ ' @voidzero-dev/vite-plus' : '*' ,
294294 } ,
295295 } ;
296296
297297 fs . writeFileSync (
298- path . join ( this . rootDir , " package.json" ) ,
298+ path . join ( this . rootDir , ' package.json' ) ,
299299 JSON . stringify ( rootPackageJson , null , 2 ) ,
300300 ) ;
301301
@@ -304,7 +304,7 @@ module.exports = { ${pkg.name.replace("-", "_")} };
304304 - 'packages/*'
305305` ;
306306 fs . writeFileSync (
307- path . join ( this . rootDir , " pnpm-workspace.yaml" ) ,
307+ path . join ( this . rootDir , ' pnpm-workspace.yaml' ) ,
308308 pnpmWorkspace ,
309309 ) ;
310310
@@ -327,7 +327,7 @@ module.exports = { ${pkg.name.replace("-", "_")} };
327327 } ;
328328
329329 fs . writeFileSync (
330- path . join ( this . rootDir , " vite-plus.json" ) ,
330+ path . join ( this . rootDir , ' vite-plus.json' ) ,
331331 JSON . stringify ( rootVitePlusConfig , null , 2 ) ,
332332 ) ;
333333
@@ -359,7 +359,7 @@ module.exports = { ${pkg.name.replace("-", "_")} };
359359 }
360360 }
361361
362- console . log ( " \nStatistics:" ) ;
362+ console . log ( ' \nStatistics:' ) ;
363363 console . log ( `- Total packages: ${ this . packages . size } ` ) ;
364364 console . log (
365365 `- Average dependencies per package: ${ (
@@ -368,14 +368,14 @@ module.exports = { ${pkg.name.replace("-", "_")} };
368368 ) ;
369369 console . log ( `- Max dependencies in a package: ${ maxDeps } ` ) ;
370370 console . log ( `- Packages with vite-plus.json: ${ packagesWithVitePlus } ` ) ;
371- console . log ( " - Script distribution:" ) ;
371+ console . log ( ' - Script distribution:' ) ;
372372 for ( const [ script , count ] of scriptCounts ) {
373373 console . log ( ` - ${ script } : ${ count } packages` ) ;
374374 }
375375 }
376376}
377377
378378// Main execution
379- const outputDir = path . join ( __dirname , " fixtures" , " monorepo" ) ;
379+ const outputDir = path . join ( __dirname , ' fixtures' , ' monorepo' ) ;
380380const generator = new MonorepoGenerator ( outputDir ) ;
381381generator . generate ( ) ;
0 commit comments