@manojkmfsi/monodog 1.0.20 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,12 +46,14 @@ exports.findCircularDependencies = findCircularDependencies;
46
46
  exports.generateDependencyGraph = generateDependencyGraph;
47
47
  exports.checkOutdatedDependencies = checkOutdatedDependencies;
48
48
  exports.getPackageSize = getPackageSize;
49
+ exports.findMonorepoRoot = findMonorepoRoot;
49
50
  // import { Package } from '@prisma/client';
50
51
  const fs = __importStar(require("fs"));
51
52
  const path_1 = __importDefault(require("path"));
52
53
  const config_loader_1 = require("../config-loader");
53
54
  const health_utils_1 = require("./health-utils");
54
55
  Object.defineProperty(exports, "calculatePackageHealth", { enumerable: true, get: function () { return health_utils_1.calculatePackageHealth; } });
56
+ const yaml = __importStar(require("js-yaml"));
55
57
  /**
56
58
  * Resolves simple workspace globs (like 'packages/*', 'apps/*') into actual package directory paths.
57
59
  * Note: This implementation only handles the 'folder/*' pattern and is not a full glob resolver.
@@ -80,27 +82,65 @@ function resolveWorkspaceGlobs(rootDir, globs) {
80
82
  return resolvedPaths;
81
83
  }
82
84
  /**
83
- * Reads the root package.json and extracts the 'workspaces' field (array of globs).
85
+ * Parses pnpm-workspace.yaml and extracts workspace globs
84
86
  */
85
- function getWorkspacesFromRoot(rootDir) {
86
- const packageJsonPath = path_1.default.join(rootDir, 'package.json');
87
- if (!fs.existsSync(packageJsonPath)) {
88
- console.warn(`\n⚠️ Warning: No package.json found at root directory: ${rootDir}`);
87
+ function getWorkspacesFromPnpmYaml(rootDir) {
88
+ const workspaceYamlPath = path_1.default.join(rootDir, 'pnpm-workspace.yaml');
89
+ if (!fs.existsSync(workspaceYamlPath)) {
89
90
  return undefined;
90
91
  }
91
92
  try {
92
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
93
- // Handle both standard array and object format (used by yarn/pnpm)
94
- if (Array.isArray(packageJson.workspaces)) {
95
- return packageJson.workspaces;
96
- }
97
- else if (packageJson.workspaces && Array.isArray(packageJson.workspaces.packages)) {
98
- return packageJson.workspaces.packages;
93
+ const yamlContent = fs.readFileSync(workspaceYamlPath, 'utf-8');
94
+ const yamlData = yaml.load(yamlContent);
95
+ if (yamlData && yamlData.packages) {
96
+ // Filter out exclusion patterns (lines starting with '!')
97
+ const packages = Array.isArray(yamlData.packages)
98
+ ? yamlData.packages.filter((pkg) => typeof pkg === 'string' && !pkg.startsWith('!'))
99
+ : [];
100
+ if (packages.length > 0) {
101
+ return packages;
102
+ }
99
103
  }
100
104
  }
101
105
  catch (e) {
102
- console.error(`\n❌ Error parsing package.json at ${packageJsonPath}. Skipping workspace detection.`);
106
+ console.error(`\n❌ Error parsing pnpm-workspace.yaml at ${workspaceYamlPath}:`, e);
107
+ }
108
+ return undefined;
109
+ }
110
+ /**
111
+ * Reads workspace configuration from package.json or pnpm-workspace.yaml
112
+ * Priority: package.json (if exists) -> pnpm-workspace.yaml
113
+ */
114
+ function getWorkspacesFromRoot(rootDir) {
115
+ const packageJsonPath = path_1.default.join(rootDir, 'package.json');
116
+ // Try package.json first
117
+ if (fs.existsSync(packageJsonPath)) {
118
+ try {
119
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
120
+ // Handle both standard array and object format (used by yarn/pnpm)
121
+ if (Array.isArray(packageJson.workspaces)) {
122
+ console.log('✅ Workspace configuration found in package.json');
123
+ return packageJson.workspaces;
124
+ }
125
+ else if (packageJson.workspaces && Array.isArray(packageJson.workspaces.packages)) {
126
+ console.log('✅ Workspace configuration found in package.json');
127
+ return packageJson.workspaces.packages;
128
+ }
129
+ }
130
+ catch (e) {
131
+ console.error(`\n❌ Error parsing package.json at ${packageJsonPath}. Attempting to read pnpm-workspace.yaml...`);
132
+ }
133
+ }
134
+ else {
135
+ console.warn(`\n⚠️ Warning: No package.json found at root directory: ${rootDir}`);
136
+ }
137
+ // Fallback to pnpm-workspace.yaml
138
+ const pnpmWorkspaces = getWorkspacesFromPnpmYaml(rootDir);
139
+ if (pnpmWorkspaces && pnpmWorkspaces.length > 0) {
140
+ console.log('✅ Workspace configuration found in pnpm-workspace.yaml');
141
+ return pnpmWorkspaces;
103
142
  }
143
+ console.warn('\n⚠️ No workspace configuration found in package.json or pnpm-workspace.yaml');
104
144
  return undefined;
105
145
  }
106
146
  /**
@@ -110,7 +150,7 @@ function scanMonorepo(rootDir) {
110
150
  const packages = [];
111
151
  console.log('rootDir:', rootDir);
112
152
  const workspacesGlobs = config_loader_1.appConfig.workspaces;
113
- // Use provided workspaces globs if given, otherwise attempt to detect from root package.json
153
+ // Use provided workspaces globs if given, otherwise attempt to detect from root package.json or pnpm-workspace.yaml
114
154
  const detectedWorkspacesGlobs = workspacesGlobs.length > 0 ? workspacesGlobs : getWorkspacesFromRoot(rootDir);
115
155
  if (detectedWorkspacesGlobs && detectedWorkspacesGlobs.length > 0) {
116
156
  if (workspacesGlobs.length) {
@@ -326,3 +366,41 @@ function getPackageSize(packagePath) {
326
366
  return { size: 0, files: 0 };
327
367
  }
328
368
  }
369
+ /**
370
+ * Find the monorepo root by looking for package.json with workspaces or pnpm-workspace.yaml
371
+ */
372
+ function findMonorepoRoot() {
373
+ let currentDir = __dirname;
374
+ while (currentDir !== path_1.default.parse(currentDir).root) {
375
+ const packageJsonPath = path_1.default.join(currentDir, 'package.json');
376
+ const pnpmWorkspacePath = path_1.default.join(currentDir, 'pnpm-workspace.yaml');
377
+ // Check if this directory has package.json with workspaces or pnpm-workspace.yaml
378
+ if (fs.existsSync(packageJsonPath)) {
379
+ try {
380
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
381
+ // If it has workspaces or is the root monorepo package
382
+ if (packageJson.workspaces || fs.existsSync(pnpmWorkspacePath)) {
383
+ console.log('✅ Found monorepo root:', currentDir);
384
+ return currentDir;
385
+ }
386
+ }
387
+ catch (error) {
388
+ // Continue searching if package.json is invalid
389
+ }
390
+ }
391
+ // Check if we're at the git root
392
+ const gitPath = path_1.default.join(currentDir, '.git');
393
+ if (fs.existsSync(gitPath)) {
394
+ console.log('✅ Found git root (likely monorepo root):', currentDir);
395
+ return currentDir;
396
+ }
397
+ // Go up one directory
398
+ const parentDir = path_1.default.dirname(currentDir);
399
+ if (parentDir === currentDir)
400
+ break; // Prevent infinite loop
401
+ currentDir = parentDir;
402
+ }
403
+ // Fallback to process.cwd() if we can't find the root
404
+ console.log('⚠️ Could not find monorepo root, using process.cwd():', process.cwd());
405
+ return process.cwd();
406
+ }
@@ -1,7 +1,5 @@
1
1
  {
2
- "workspaces": [
3
- "packages/*"
4
- ],
2
+ "workspaces": [],
5
3
  "database": {
6
4
  "path": "file:./monodog.db"
7
5
  },
@@ -13,4 +11,4 @@
13
11
  "host": "0.0.0.0",
14
12
  "port": 8999
15
13
  }
16
- }
14
+ }