Skip to content

Commit 7bacaaf

Browse files
authored
fix: no record packagejson in project root path (#160)
1 parent eb47fba commit 7bacaaf

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

ts-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "abcoder-ts-parser",
3-
"version": "0.0.24",
3+
"version": "0.0.28",
44
"description": "TypeScript AST parser for UNIAST specification",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

ts-parser/src/utils/monorepo.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)