@@ -82,6 +82,13 @@ export class MonorepoUtils {
8282 private static countPackageJsonFiles ( rootPath : string ) : number {
8383 try {
8484 let count = 0 ;
85+
86+ // Check if rootPath itself has a package.json
87+ const rootPackageJsonPath = path . join ( rootPath , 'package.json' ) ;
88+ if ( fs . existsSync ( rootPackageJsonPath ) ) {
89+ count ++ ;
90+ }
91+
8592 const items = fs . readdirSync ( rootPath ) ;
8693
8794 for ( const item of items ) {
@@ -137,6 +144,24 @@ export class MonorepoUtils {
137144 */
138145 private static discoverPackagesRecursive ( rootPath : string , currentDir : string , packages : MonorepoPackage [ ] ) : void {
139146 try {
147+ // Check if currentDir itself has a package.json
148+ const packageJsonPath = path . join ( currentDir , 'package.json' ) ;
149+ if ( fs . existsSync ( packageJsonPath ) ) {
150+ try {
151+ const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf-8' ) ) ;
152+ const relativePath = path . relative ( rootPath , currentDir ) ;
153+
154+ packages . push ( {
155+ path : relativePath ,
156+ absolutePath : currentDir ,
157+ shouldPublish : false , // Default to false for generic discovery
158+ name : packageJson . name
159+ } ) ;
160+ } catch ( error ) {
161+ console . warn ( `Failed to parse package.json at ${ packageJsonPath } :` , error ) ;
162+ }
163+ }
164+
140165 const items = fs . readdirSync ( currentDir , { withFileTypes : true } ) ;
141166
142167 for ( const item of items ) {
@@ -152,24 +177,6 @@ export class MonorepoUtils {
152177 continue ;
153178 }
154179
155- // Check if this directory has a package.json
156- const packageJsonPath = path . join ( fullPath , 'package.json' ) ;
157- if ( fs . existsSync ( packageJsonPath ) ) {
158- try {
159- const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf-8' ) ) ;
160- const relativePath = path . relative ( rootPath , fullPath ) ;
161-
162- packages . push ( {
163- path : relativePath ,
164- absolutePath : fullPath ,
165- shouldPublish : false , // Default to false for generic discovery
166- name : packageJson . name
167- } ) ;
168- } catch ( error ) {
169- console . warn ( `Failed to parse package.json at ${ packageJsonPath } :` , error ) ;
170- }
171- }
172-
173180 // Recursively search in subdirectories
174181 this . discoverPackagesRecursive ( rootPath , fullPath , packages ) ;
175182 }
0 commit comments