Skip to content

Commit 5365c8b

Browse files
committed
fix: handle absolute paths in findMatchingFilesFallback method
- Added isAbsolute check to handle both absolute and relative search paths - Fixed test to use relative path like the actual code does - Should resolve the fallback method returning 0 files issue
1 parent b9e3201 commit 5365c8b

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/core/modules/auto-discovery.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Auto-discovery system for Moro modules
22
import { readdirSync, statSync } from 'fs';
3-
import { join, extname, relative } from 'path';
3+
import { join, extname, relative, isAbsolute } from 'path';
44
import { ModuleConfig } from '../../types/module';
55
import { DiscoveryOptions } from '../../types/discovery';
66
import { ModuleDefaultsConfig } from '../../types/config';
@@ -431,8 +431,8 @@ export class ModuleDiscovery {
431431
recursive: true,
432432
} as ModuleDefaultsConfig['autoDiscovery'];
433433

434-
// Resolve the full search path
435-
const fullSearchPath = join(this.baseDir, searchPath);
434+
// Handle both absolute and relative paths
435+
const fullSearchPath = isAbsolute(searchPath) ? searchPath : join(this.baseDir, searchPath);
436436
console.error(`FALLBACK: Full search path: ${fullSearchPath}`);
437437

438438
// Check if search path exists

tests/unit/core/auto-discovery.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ describe('Enhanced Module Auto-Discovery System', () => {
107107
let modules: any[] = [];
108108
let discoveryError: any = null;
109109
let debugInfo: string[] = [];
110-
110+
111111
try {
112112
debugInfo.push('=== TESTING CORE LOGIC DIRECTLY ===');
113-
113+
114114
// Test the individual methods to see where it fails
115115
const testSearchPath = join(tempDir, 'modules');
116116
debugInfo.push(`Testing search path: ${testSearchPath}`);
117-
117+
118118
// Check if the ModuleDiscovery instance can access the path
119119
const { access } = await import('fs/promises');
120120
try {
@@ -123,40 +123,40 @@ describe('Enhanced Module Auto-Discovery System', () => {
123123
} catch (e) {
124124
debugInfo.push(`Search path accessible: NO - ${e}`);
125125
}
126-
126+
127127
// Test the glob detection logic directly
128128
const isCI = process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true';
129129
const nodeVersion = process.version;
130130
debugInfo.push(`CI detected: ${isCI}, Node: ${nodeVersion}`);
131-
132-
// DIRECTLY TEST THE FALLBACK METHOD
131+
132+
// DIRECTLY TEST THE FALLBACK METHOD (use relative path like the real code)
133133
const fallbackFiles = await (discovery as any).findMatchingFilesFallback(
134-
testSearchPath,
134+
'modules', // Use relative path, not absolute
135135
config.patterns,
136136
config.ignorePatterns,
137137
config.maxDepth
138138
);
139139
debugInfo.push(`Fallback found ${fallbackFiles.length} files: ${JSON.stringify(fallbackFiles)}`);
140-
140+
141141
// DIRECTLY TEST PATTERN MATCHING
142142
const testPaths = ['modules/users/index.ts', 'modules/orders/index.ts'];
143143
const testPatterns = ['**/index.{ts,js}', '**/*.module.{ts,js}'];
144-
144+
145145
for (const testPath of testPaths) {
146146
for (const testPattern of testPatterns) {
147147
const matches = (discovery as any).matchesSimplePattern(testPath, testPattern);
148148
debugInfo.push(`Pattern test: "${testPath}" vs "${testPattern}" = ${matches}`);
149149
}
150150
}
151-
151+
152152
// Now call the discovery method
153153
modules = await discovery.discoverModulesAdvanced(config);
154154
debugInfo.push('=== DISCOVERY COMPLETED ===');
155155
} catch (error) {
156156
debugInfo.push(`=== ERROR === ${error}`);
157157
discoveryError = error;
158158
}
159-
159+
160160
debugInfo.push(`Final modules count: ${modules.length}`);
161161
debugInfo.push(`Final modules: ${JSON.stringify(modules.map(m => ({ name: m.name, version: m.version })))}`);
162162
debugInfo.push(`Discovery error: ${discoveryError}`);

0 commit comments

Comments
 (0)