Skip to content

detector: Framework detection can never return null for a repo with a package.json #13911

Closed

Description

@ChiragAgg5k

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/*:

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:

  1. Drop package.json from getFiles() and rely on getPackages() for JS frameworks. Cleanest, but changes scores everywhere.
  2. Require at least one package match before a detection is eligible, keeping package.json as a tiebreak-only signal.
  3. 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

  1. added
    product / auth
    product / databases
    product / sites
    product / storage
    product / vcs
    on Sep 25, 2026
  2. avinash-git-24 commented on Sep 28, 2026

    @avinash-git-24

    Hi team! I examined Framework::detect() in packages/detector (src/Detector/Framework.php) and how package.json is scored across all JS framework classes.

    Because package.json is listed in getFiles() for all 14 JS framework detectors, any plain repository with a package.json and zero matching framework packages still receives a score of 1 on every detector, causing a 14-way tie at 1 that falls through to the parent-depth tie-breaker and falsely returns angular instead of null.

    Proposed fix:

    1. Treat generic manifest files (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 in Framework::detect().
    2. Add regression tests in packages/detector covering:
      • A repo with a plain package.json and no framework dependencies returning null.
      • Framework repos detected solely via package.json dependencies vs. framework config files.

    (I also noticed the related packages/detector issue in #13912 where TanStackStart::getAdapter() matches any prerender token including partial route prerender configs—happy to submit clean PRs for one or both!)

  3. added a commit that references this issue on Sep 29, 2026
    5fd5f53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / authproduct / databasesproduct / sitesproduct / storageproduct / vcs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions