mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 05:22:17 +00:00
fix(project-detect): read all Go require directives
This commit is contained in:
1 parent
d2ef268059
commit
bbdfd133e0
2 files changed
+106
-9
No files matched your search
@@ -256,15 +256,23 @@ function getGoDeps(projectDir) {
|
||||
if (!fs.existsSync(modPath)) return [];
|
||||
const content = fs.readFileSync(modPath, 'utf8');
|
||||
const deps = [];
|
||||
const requireBlock = content.match(/require\s*\(([\s\S]*?)\)/);
|
||||
if (requireBlock) {
|
||||
requireBlock[1].split('\n').forEach(line => {
|
||||
const trimmed = line.trim();
|
||||
if (trimmed && !trimmed.startsWith('//')) {
|
||||
const parts = trimmed.split(/\s+/);
|
||||
if (parts[0]) deps.push(parts[0]);
|
||||
}
|
||||
});
|
||||
let inRequireBlock = false;
|
||||
for (const rawLine of content.split(/\r?\n/)) {
|
||||
const line = rawLine.split('//')[0].trim();
|
||||
if (!line) continue;
|
||||
if (line === ')' && inRequireBlock) {
|
||||
inRequireBlock = false;
|
||||
continue;
|
||||
}
|
||||
const directive = line.match(/^require(?:\s+|(?=\())(.+)$/);
|
||||
if (directive?.[1] === '(') {
|
||||
inRequireBlock = true;
|
||||
continue;
|
||||
}
|
||||
if (!directive && !inRequireBlock) continue;
|
||||
const requirement = (directive ? directive[1] : line)
|
||||
.match(/^(?:"([^"]+)"|`([^`]+)`|(\S+))\s+\S+/);
|
||||
if (requirement) deps.push(requirement[1] || requirement[2] || requirement[3]);
|
||||
}
|
||||
return deps;
|
||||
} catch {
|
||||
|
||||
Reference in new issue
Block a user