Utopia Detector
Detects a project's packager, runtime, framework and rendering from its file names, languages and manifests.
This library is maintained by the Appwrite team.
Getting started
[]
= { = "https://github.com/appwrite/appwrite" }
Before a project can be built, something has to work out what it is: which package manager it uses, which runtime runs it, which framework builds it, and whether the build is served by a server or as files. Each of these is a detector: add the options it may choose from and the inputs you have (file names, languages, a manifest), then call detect. This guide covers the common tasks.
Find the package manager
PackagerDetector returns the first option, in the order you added them, that has one of its files among the inputs. Put the more specific lockfiles first, since every npm-compatible project has a package.json.
use ;
let mut detector = new;
detector.add_option.add_option.add_option;
for file in
assert_eq!;
Find the runtime
A RuntimeDetector matches by a Strategy: file names (FileMatch), their extensions (Extension) or language names (Languages). The packager you pass shapes the install command of runtimes that depend on it.
use ;
let mut detector = new;
detector.add_option.add_option.add_option;
detector.add_input.add_input;
let runtime = detector.detect.expect;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert!;
Find the framework from files and dependencies
A FrameworkDetector scores every framework: a point for each of its files among the file inputs, and a point for each of its packages in each manifest. Feed it the repository's file names and the content of package.json or pubspec.yaml.
use ;
let mut detector = new;
detector.add_option.add_option.add_option.add_option;
detector.add_file;
detector.add_manifest;
let framework = detector.detect.expect;
assert_eq!;
assert_eq!;
assert_eq!;
Read how a framework is configured to render
Some frameworks say in their configuration whether they render on a server. config_files lists the files to read, in priority order, and adapter reads one.
use ;
let astro = Astro;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Tell server-rendered builds from static ones
A RenderingDetector looks at a framework's build output. It returns the first option with one of that framework's server files; otherwise the build is static, with its only HTML file as the fallback page when there is exactly one.
use ;
let mut detector = new;
detector.add_option.add_option;
detector.add_input.add_input;
assert_eq!;
let mut detector = new;
detector.add_option.add_option;
detector.add_input.add_input;
let rendering = detector.detect;
assert_eq!;
Contributing
Development happens in appwrite/appwrite, where this crate lives at crates/utopia/detector. Run these commands from a checkout of it. The contributing guide covers each step.
Test
Compare with PHP
Replay the results PHP recorded for every case against Rust, without PHP:
COMPAT_LIB=detector
Run every case on both runtimes, fuzz both with generated inputs, then run the whole conversion check. These need the dev stack (docker compose up -d):
Benchmark
This times every benchmark on PHP and on a release build of Rust, both in containers on the dev stack. It fails if Rust is slower. Add --write to record the run in tests/compat/detector/bench.json. Run it on a quiet machine, one library at a time.
License
BSD-3-Clause. See LICENSE.