Repository navigation
Description
Moved from utopia-php/detector#16 (by @HarshMN2345) after detector moved to packages/detector.
Summary
Framework::detect() never returns null for any repository containing a package.json, even when no framework is present. It returns angular.
Cause
package.json is listed in getFiles() for every framework detection — Angular, React, NextJs, SvelteKit, Astro, Analog and the rest. So for a repo with a package.json and no framework dependencies, every detector scores exactly one path match.
detect() then filters to the joint-highest scorers, and since all fourteen tie at 1, falls through to the fewest-parents tie-break in src/Detector/Framework.php:
$bestFrameworks = \array_keys($frameworkMatches);
usort($bestFrameworks, fn ($a, $b) => $fameworkParents[$a] <=> $fameworkParents[$b]);
$bestFramework = $bestFrameworks[0];Angular extends JS directly, so it has the fewest parents and wins. The count($frameworkMatches) <= 0 early return never fires, because the tie is at 1 rather than 0.
Reproduction
Against utopia-php/detector 0.2.6, with all fourteen detections registered as in Appwrite's detection endpoint:
$detector = new Framework('npm');
$detector->addInput('{"dependencies":{"lodash":"^4"}}', Framework::INPUT_PACKAGES);
$detector->addInput('package.json', Framework::INPUT_FILE);
// ... addOption() for all 14 detections
$detector->detect()->getName(); // => "angular"| Input | Expected | Actual |
|---|---|---|
{"dependencies":{"lodash":"^4"}} |
null |
angular |
{"devDependencies":{"turbo":"^2"}} |
null |
angular |
{} |
null |
angular |
Real repositories affected
Both are turborepo monorepos whose root package.json holds only tooling, with the apps under apps/*:
sunshineLixun/ShipFullStack→angularmohebifar/tooscut→angular
Consumers that map a detection to a build configuration will pick Angular's install/build commands and an output directory of ./dist/angular for these, which no build produces.
Note on the fix
This is a design call rather than an obvious patch, which is why this is an issue and not a PR. package.json cannot discriminate between frameworks, so the options I can see each have a blast radius across all fourteen detections:
- Drop
package.jsonfromgetFiles()and rely ongetPackages()for JS frameworks. Cleanest, but changes scores everywhere. - Require at least one package match before a detection is eligible, keeping
package.jsonas a tiebreak-only signal. - Weight path matches so a universal file scores below a discriminating one.
Happy to send a PR for whichever direction you prefer.
Found while testing Appwrite's framework detection against open-source repositories.
Activity
avinash-git-24 commentedon Sep 28, 2026
Hi team! I examined
Framework::detect()inpackages/detector(src/Detector/Framework.php) and howpackage.jsonis scored across all JS framework classes.Because
package.jsonis listed ingetFiles()for all 14 JS framework detectors, any plain repository with apackage.jsonand zero matching framework packages still receives a score of1on every detector, causing a 14-way tie at1that falls through to the parent-depth tie-breaker and falsely returnsangularinstead ofnull.Proposed fix:
package.json) as a container/prerequisite for package inspection rather than a standalone positive framework signal, or require at least one framework-specific config file or package dependency match before awarding a positive detection score inFramework::detect().packages/detectorcovering:package.jsonand no framework dependencies returningnull.package.jsondependencies vs. framework config files.(I also noticed the related
packages/detectorissue in #13912 whereTanStackStart::getAdapter()matches anyprerendertoken including partial route prerender configs—happy to submit clean PRs for one or both!)fix(detector): stop scoring bare package.json as a framework hit