Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

fix: detect Dart/Flutter projects in project-detect.js

Beksultan Pirmatov11a970e11e5f
diff --git a/scripts/lib/project-detect.js b/scripts/lib/project-detect.js
index 98308fa0a..a7f625847 100644
--- a/scripts/lib/project-detect.js
+++ b/scripts/lib/project-detect.js
@@ -84,6 +84,11 @@ const LANGUAGE_RULES = [
type: 'php',
markers: ['composer.json', 'composer.lock'],
extensions: ['.php']
+ },
+ {
+ type: 'dart',
+ markers: ['pubspec.yaml', 'pubspec.lock'],
+ extensions: ['.dart']
}
];
@@ -129,7 +134,10 @@ const FRAMEWORK_RULES = [
{ framework: 'symfony', language: 'php', markers: ['symfony.lock'], packageKeys: ['symfony/framework-bundle'] },
// Elixir frameworks
- { framework: 'phoenix', language: 'elixir', markers: [], packageKeys: ['phoenix'] }
+ { framework: 'phoenix', language: 'elixir', markers: [], packageKeys: ['phoenix'] },
+
+ // Dart frameworks
+ { framework: 'flutter', language: 'dart', markers: [], packageKeys: [], customCheck: hasFlutterSdkDependency }
];
/**
@@ -330,6 +338,27 @@ function getElixirDeps(projectDir) {
}
}
+/**
+ * Check whether pubspec.yaml declares the Flutter SDK as a dependency,
+ * which distinguishes a Flutter app from a plain Dart package.
+ * @param {string} projectDir - Project root directory
+ * @returns {boolean}
+ */
+function hasFlutterSdkDependency(projectDir) {
+ try {
+ const pubspecPath = path.join(projectDir, 'pubspec.yaml');
+ if (!fs.existsSync(pubspecPath)) return false;
+ const content = fs.readFileSync(pubspecPath, 'utf8');
+ // Matches the standard Flutter pubspec shape:
+ // dependencies:
+ // flutter:
+ // sdk: flutter
+ return /^\s*flutter:\s*$/m.test(content) && /sdk:\s*flutter/.test(content);
+ } catch {
+ return false;
+ }
+}
+
/**
* Detect project languages and frameworks
* @param {string} [projectDir] - Project directory (defaults to cwd)
@@ -409,7 +438,9 @@ function detectProjectType(projectDir) {
});
}
- if (hasMarker || hasDep) {
+ const hasCustom = typeof rule.customCheck === 'function' ? rule.customCheck(projectDir) : false;
+
+ if (hasMarker || hasDep || hasCustom) {
frameworks.push(rule.framework);
}
}
diff --git a/tests/lib/project-detect.test.js b/tests/lib/project-detect.test.js
index 30727f360..100e1c6c3 100644
--- a/tests/lib/project-detect.test.js
+++ b/tests/lib/project-detect.test.js
@@ -493,6 +493,57 @@ function runTests() {
}
})) passed++; else failed++;
+ // Dart/Flutter detection
+ console.log('\nDart/Flutter Detection:');
+
+ if (test('detects dart from pubspec.yaml and .dart files', () => {
+ const dir = createTempDir();
+ try {
+ writeTestFile(dir, 'pubspec.yaml', 'name: test_pkg\nversion: 1.0.0\n');
+ writeTestFile(dir, 'main.dart', 'void main() {}\n');
+ const result = detectProjectType(dir);
+ assert.ok(result.languages.includes('dart'));
+ } finally {
+ cleanupDir(dir);
+ }
+ })) passed++; else failed++;
+
+ if (test('detects flutter framework when pubspec.yaml depends on the Flutter SDK', () => {
+ const dir = createTempDir();
+ try {
+ writeTestFile(dir, 'pubspec.yaml', [
+ 'name: halal_cosmetics_app',
+ 'dependencies:',
+ ' flutter:',
+ ' sdk: flutter',
+ ' cupertino_icons: ^1.0.2'
+ ].join('\n'));
+ const result = detectProjectType(dir);
+ assert.ok(result.languages.includes('dart'));
+ assert.ok(result.frameworks.includes('flutter'), `flutter not detected: ${JSON.stringify(result.frameworks)}`);
+ assert.strictEqual(result.primary, 'flutter');
+ } finally {
+ cleanupDir(dir);
+ }
+ })) passed++; else failed++;
+
+ if (test('does not misclassify a plain Dart package as flutter', () => {
+ const dir = createTempDir();
+ try {
+ writeTestFile(dir, 'pubspec.yaml', [
+ 'name: plain_dart_pkg',
+ 'dependencies:',
+ ' http: ^1.0.0'
+ ].join('\n'));
+ const result = detectProjectType(dir);
+ assert.ok(result.languages.includes('dart'));
+ assert.ok(!result.frameworks.includes('flutter'), `plain Dart package wrongly detected as flutter: ${JSON.stringify(result.frameworks)}`);
+ assert.strictEqual(result.primary, 'dart');
+ } finally {
+ cleanupDir(dir);
+ }
+ })) passed++; else failed++;
+
// Edge cases
console.log('\nEdge Cases:');