@@ -5,11 +5,17 @@ import path from "node:path";
5
5
6
6
import type { AnalysisPort } from "@/application/ports/analysis.port" ;
7
7
import type { FileSystemPort } from "@/application/ports/file-system.port" ;
8
- import type { AnalysisResult , PackageConfig , PackageExports , ScriptConfig } from "@/domain/entities/package-config" ;
8
+ import type {
9
+ AnalysisResult ,
10
+ PackageConfig ,
11
+ PackageExports ,
12
+ PackageJson ,
13
+ ScriptConfig ,
14
+ } from "@/domain/entities/package-config" ;
9
15
import type { PackageRepository } from "@/domain/interfaces/package.repository" ;
10
16
import type { FileSystemUtility } from "@/infrastructure/utilities/file-system-utility" ;
11
17
12
- import { packageJsonSchema , scriptConfigSchema } from "@/domain/entities/package-config" ;
18
+ import { scriptConfigSchema } from "@/domain/entities/package-config" ;
13
19
import { TYPES } from "@/ioc/types" ;
14
20
15
21
@injectable ( )
@@ -42,7 +48,9 @@ export class FileSystemPackageRepository implements PackageRepository {
42
48
@inject ( TYPES . FileSystemUtility ) private fileSystemUtility : FileSystemUtility ,
43
49
) { }
44
50
45
- async findAllPackages ( config : ScriptConfig ) : Promise < string [ ] > {
51
+ async findAllPackages ( configPath ?: string ) : Promise < string [ ] > {
52
+ const config = this . getConfig ( configPath ) ;
53
+
46
54
return await glob ( config . packagesGlob , {
47
55
ignore : this . DEFAULT_IGNORE_PATTERN ,
48
56
} ) ;
@@ -60,7 +68,7 @@ export class FileSystemPackageRepository implements PackageRepository {
60
68
let packageJson ;
61
69
62
70
try {
63
- packageJson = packageJsonSchema . parse ( JSON . parse ( this . fileSystemPort . readFile ( packageJsonPath ) ) ) ;
71
+ packageJson = JSON . parse ( this . fileSystemPort . readFile ( packageJsonPath ) ) as PackageJson ;
64
72
} catch ( error ) {
65
73
console . error ( `Failed to parse ${ packageJsonPath } : ${ error instanceof Error ? error . message : "Unknown error" } ` ) ;
66
74
@@ -75,28 +83,28 @@ export class FileSystemPackageRepository implements PackageRepository {
75
83
return false ;
76
84
}
77
85
78
- console . info ( `Processing package: ${ packageName } ` ) ;
86
+ console . info ( `♢‒ Processing package: ${ packageName } ` ) ;
79
87
80
88
const config = this . getConfig ( options . configPath ) ;
81
89
const packageConfig = this . getPackageConfig ( packageName , config ) ;
82
90
const srcIndexPath = path . join ( packageDir , packageConfig . srcIndexPath ) ;
83
91
84
92
if ( ! this . fileSystemPort . exists ( srcIndexPath ) ) {
85
- console . error ( `Source file not found at ${ srcIndexPath } ` ) ;
93
+ console . error ( `⎹ ⛔︎ Source file not found at ${ srcIndexPath } ` ) ;
86
94
87
95
return false ;
88
96
}
89
97
90
- console . info ( `Analyzing imports from ${ srcIndexPath } ...` ) ;
98
+ console . info ( `⎹ Analyzing imports from ${ srcIndexPath } ...` ) ;
91
99
const analysis = this . analyzeImports ( srcIndexPath , packageConfig ) ;
92
100
93
101
if ( analysis . imports . length === 0 ) {
94
- console . warn ( `No imports found to analyze in ${ packageName } ` ) ;
102
+ console . warn ( `⎹ ⛔︎ No imports found to analyze in ${ packageName } ` ) ;
95
103
96
104
return false ;
97
105
}
98
106
99
- console . log ( `Analysis complete. Found ${ analysis . imports . length } subpath exports.` ) ;
107
+ console . log ( `⎹ Analysis complete. Found ${ analysis . imports . length } subpath exports.` ) ;
100
108
101
109
this . saveExportsAnalysis ( packageDir , analysis ) ;
102
110
@@ -105,23 +113,23 @@ export class FileSystemPackageRepository implements PackageRepository {
105
113
const currentExportsCount = packageJson . exports ? Object . keys ( packageJson . exports ) . length : 0 ;
106
114
const newExportsCount = Object . keys ( newExports ) . length ;
107
115
108
- console . info ( `Exports: ${ currentExportsCount } -> ${ newExportsCount } ` ) ;
116
+ console . info ( `⎹ Exports: ${ currentExportsCount } -> ${ newExportsCount } ` ) ;
109
117
110
118
if ( options . dryRun ) {
111
119
this . saveExportsPreview ( packageDir , newExports ) ;
112
- console . warn ( `Saved exports preview to .exports-analysis` ) ;
113
- console . warn ( `Dry run: no changes saved for ${ packageName } ` ) ;
120
+ console . warn ( `⎹ Saved exports preview to .exports-analysis` ) ;
121
+ console . warn ( `⎹ Dry run: no changes saved for ${ packageName } ` ) ;
114
122
115
123
return true ;
116
124
}
117
125
118
126
this . fileSystemUtility . backupFile ( packageJsonPath , ".exports-analysis" ) ;
119
- console . log ( `Backed up ${ packageJsonPath } ` ) ;
127
+ console . log ( `⎹ Backed up ${ packageJsonPath } ` ) ;
120
128
121
129
const updatedPackageJson = { ...packageJson , exports : newExports } ;
122
130
123
- this . fileSystemPort . writeFile ( packageJsonPath , JSON . stringify ( updatedPackageJson , null , 2 ) ) ;
124
- console . log ( `Updated exports for ${ packageName } ` ) ;
131
+ this . fileSystemPort . writeFile ( packageJsonPath , ` ${ JSON . stringify ( updatedPackageJson , null , 2 ) } \n` ) ;
132
+ console . log ( `⎹ Updated exports for ${ packageName } ` ) ;
125
133
126
134
return true ;
127
135
}
0 commit comments