Contents
use utopia_detector::Analog;pub struct Analog;Analog, the Angular meta-framework.
PHP: Utopia\Detector\Detection\Framework\Analog.
use utopia_detector::Angular;pub struct Angular;Angular.
PHP: Utopia\Detector\Detection\Framework\Angular.
use utopia_detector::Astro;pub struct Astro;Astro. It renders components of other frameworks, so their files and packages count for it too; a tie between Astro and another framework goes to the other one.
The adapter is server-side when the configuration sets output to
server or hybrid, and static otherwise.
PHP: Utopia\Detector\Detection\Framework\Astro.
use utopia_detector::Bun;pub struct Bun;Bun.
PHP: Utopia\Detector\Detection\Runtime\Bun.
use utopia_detector::Cpp;pub struct Cpp;C++.
PHP: Utopia\Detector\Detection\Runtime\CPP.
use utopia_detector::Dart;pub struct Dart;Dart.
PHP: Utopia\Detector\Detection\Runtime\Dart.
use utopia_detector::Deno;pub struct Deno;Deno.
PHP: Utopia\Detector\Detection\Runtime\Deno.
use utopia_detector::Detected;pub struct Detected<'a, T: ?Sized> {
// private fields
}A runtime or framework a detector chose, with the detector's packager:
its commands are the ones for that packager. Everything else is the
option itself, through Deref.
PHP: the detection object detect() returns after setPackager().
Deref, Clone, Debug.use utopia_detector::Dotnet;pub struct Dotnet;.NET.
PHP: Utopia\Detector\Detection\Runtime\Dotnet.
use utopia_detector::Flutter;pub struct Flutter;Flutter (web).
PHP: Utopia\Detector\Detection\Framework\Flutter.
use utopia_detector::FrameworkDetector;pub struct FrameworkDetector {
// private fields
}Finds a project's framework by scoring every option: one point per framework file among the file inputs, and one per framework package declared in each manifest input. The highest score wins; a tie goes to the framework with the fewest parents, except that Astro yields to the runner-up.
Options are scored by name: two options with one name share a score.
PHP: Utopia\Detector\Detector\Framework.
use utopia_detector::{FrameworkDetector, NextJs, React};
let mut detector = FrameworkDetector::new("npm");
detector.add_option(React).add_option(NextJs);
detector.add_file("next.config.js");
detector.add_manifest(r#"{"dependencies": {"react": "^18.0.0"}}"#);
let framework = detector.detect().expect("a framework");
assert_eq!(framework.name(), "nextjs");
assert_eq!(framework.install_command(), "npm install");
assert_eq!(framework.output_directory(), "./.next");use Utopia\Detector\Detection\Framework\NextJs;
use Utopia\Detector\Detection\Framework\React;
use Utopia\Detector\Detector\Framework;
$detector = new Framework('npm');
$detector->addOption(new React())->addOption(new NextJs());
$detector->addInput('next.config.js', Framework::INPUT_FILE);
$detector->addInput('{"dependencies": {"react": "^18.0.0"}}', Framework::INPUT_PACKAGES);
$framework = $detector->detect();
echo $framework->getName(), "\n"; // nextjs
echo $framework->getInstallCommand(), "\n"; // npm install
echo $framework->getOutputDirectory(), "\n"; // ./.nextDebug.use utopia_detector::Jaspr;pub struct Jaspr;Jaspr, the Dart web framework. It is detected from the same pubspec
files as Flutter and wins once a jaspr package appears, whatever
order the options were added in.
The adapter follows jaspr.mode in pubspec.yaml: server is
server-side, static and client are static.
PHP: Utopia\Detector\Detection\Framework\Jaspr.
use utopia_detector::Java;pub struct Java;Java.
PHP: Utopia\Detector\Detection\Runtime\Java.
use utopia_detector::Lynx;pub struct Lynx;Lynx.
PHP: Utopia\Detector\Detection\Framework\Lynx.
use utopia_detector::NextJs;pub struct NextJs;Next.js.
PHP: Utopia\Detector\Detection\Framework\NextJs.
use utopia_detector::Node;pub struct Node;Node.js: the only runtime whose install command follows the packager.
PHP: Utopia\Detector\Detection\Runtime\Node.
use utopia_detector::Npm;pub struct Npm;npm: package.json or package-lock.json.
PHP: Utopia\Detector\Detection\Packager\NPM.
use utopia_detector::Nuxt;pub struct Nuxt;Nuxt.
PHP: Utopia\Detector\Detection\Framework\Nuxt.
use utopia_detector::PackagerDetector;pub struct PackagerDetector {
// private fields
}Finds the packager of a project from its file names: the first option, in the order they were added, with one of its files among the inputs.
PHP: Utopia\Detector\Detector\Packager.
use utopia_detector::{Npm, PackagerDetector, Pnpm, Yarn};
let mut detector = PackagerDetector::new();
detector.add_option(Pnpm).add_option(Yarn).add_option(Npm);
detector.add_input("package.json").add_input("yarn.lock");
assert_eq!(detector.detect().map(|p| p.name()), Some("yarn"));use Utopia\Detector\Detection\Packager\NPM;
use Utopia\Detector\Detection\Packager\PNPM;
use Utopia\Detector\Detection\Packager\Yarn;
use Utopia\Detector\Detector\Packager;
$detector = new Packager();
$detector->addOption(new PNPM())->addOption(new Yarn())->addOption(new NPM());
$detector->addInput('package.json')->addInput('yarn.lock');
echo $detector->detect()?->getName(), "\n"; // yarnDebug.use utopia_detector::Php;pub struct Php;PHP.
PHP: Utopia\Detector\Detection\Runtime\PHP.
use utopia_detector::Pnpm;pub struct Pnpm;pnpm: pnpm-lock.yaml.
PHP: Utopia\Detector\Detection\Packager\PNPM.
use utopia_detector::Python;pub struct Python;Python.
PHP: Utopia\Detector\Detection\Runtime\Python.
use utopia_detector::React;pub struct React;React.
PHP: Utopia\Detector\Detection\Framework\React.
use utopia_detector::ReactNative;pub struct ReactNative;React Native.
PHP: Utopia\Detector\Detection\Framework\ReactNative.
use utopia_detector::Remix;pub struct Remix;Remix: always server-side.
PHP: Utopia\Detector\Detection\Framework\Remix.
use utopia_detector::RenderingDetector;pub struct RenderingDetector {
// private fields
}Tells how a framework's build is served from the build's file names: the first option, in the order they were added, with one of its files for the framework among the inputs; otherwise static output, falling back to the only HTML file when there is exactly one.
PHP: Utopia\Detector\Detector\Rendering.
use utopia_detector::{RenderingDetector, Ssr, Static};
let mut detector = RenderingDetector::new("nextjs");
detector.add_option(Ssr::new()).add_option(Static::new());
detector.add_input("server/pages/index.html").add_input("server/pages/api/users.js");
let rendering = detector.detect();
assert_eq!(rendering.name(), "static");
assert_eq!(rendering.fallback_file(), Some("server/pages/index.html"));use Utopia\Detector\Detection\Rendering\SSR;
use Utopia\Detector\Detection\Rendering\XStatic;
use Utopia\Detector\Detector\Rendering;
$detector = new Rendering('nextjs');
$detector->addOption(new SSR())->addOption(new XStatic());
$detector->addInput('server/pages/index.html')->addInput('server/pages/api/users.js');
$rendering = $detector->detect();
echo $rendering->getName(), "\n"; // static
echo $rendering->getFallbackFile(), "\n"; // server/pages/index.htmlDebug.use utopia_detector::Ruby;pub struct Ruby;Ruby.
PHP: Utopia\Detector\Detection\Runtime\Ruby.
use utopia_detector::RuntimeDetector;pub struct RuntimeDetector {
// private fields
}Finds the runtime of a project: the first option, in the order they were
added, that matches an input the way the Strategy says.
PHP: Utopia\Detector\Detector\Runtime.
use utopia_detector::{Node, Php, RuntimeDetector, Strategy};
let mut detector = RuntimeDetector::new(Strategy::Extension, "yarn");
detector.add_option(Php).add_option(Node);
detector.add_input("src/main.ts").add_input("Dockerfile");
let runtime = detector.detect().expect("a runtime");
assert_eq!(runtime.name(), "node");
assert_eq!(runtime.commands(), "yarn install");use Utopia\Detector\Detection\Runtime\Node;
use Utopia\Detector\Detection\Runtime\PHP;
use Utopia\Detector\Detector\Runtime;
use Utopia\Detector\Detector\Strategy;
$detector = new Runtime(new Strategy(Strategy::EXTENSION), 'yarn');
$detector->addOption(new PHP())->addOption(new Node());
$detector->addInput('src/main.ts')->addInput('Dockerfile');
$runtime = $detector->detect();
echo $runtime->getName(), "\n"; // node
echo $runtime->getCommands(), "\n"; // yarn installDebug.use utopia_detector::Score;pub struct Score<'a> {
pub name: &'a [u8],
pub matches: usize,
pub parents: usize,
}One option as a framework detector scores it.
PHP: the option's entries in detect()'s $frameworkMatches and
$fameworkParents.
use utopia_detector::Ssr;pub struct Ssr {
// private fields
}Server-side rendering: the build has a server entry for the framework.
PHP: Utopia\Detector\Detection\Rendering\SSR.
use utopia_detector::Static;pub struct Static {
// private fields
}Static output: plain files, with an optional fallback page.
PHP: Utopia\Detector\Detection\Rendering\XStatic.
use utopia_detector::Svelte;pub struct Svelte;Svelte.
PHP: Utopia\Detector\Detection\Framework\Svelte.
use utopia_detector::SvelteKit;pub struct SvelteKit;SvelteKit: static when the configuration (or package.json) uses
@sveltejs/adapter-static, server-side otherwise.
PHP: Utopia\Detector\Detection\Framework\SvelteKit.
use utopia_detector::Swift;pub struct Swift;Swift.
PHP: Utopia\Detector\Detection\Runtime\Swift.
use utopia_detector::TanStackStart;pub struct TanStackStart;TanStack Start: server-side with a Nitro plugin or without prerendering, static when it prerenders.
PHP: Utopia\Detector\Detection\Framework\TanStackStart.
use utopia_detector::Vue;pub struct Vue;Vue.
PHP: Utopia\Detector\Detection\Framework\Vue.
use utopia_detector::Yarn;pub struct Yarn;Yarn: yarn.lock.
PHP: Utopia\Detector\Detection\Packager\Yarn.
use utopia_detector::Adapter;pub enum Adapter {
Ssr,
Static,
}How a framework's build is served, as its configuration says.
PHP: the 'ssr' and 'static' strings getAdapter() returns (''
is None).
use utopia_detector::Error;pub enum Error {
InvalidArgument(String),
Exception(String),
}Why a detector refused an argument.
PHP: one variant per PHP exception class (see Error::php_class).
use utopia_detector::Input;pub enum Input {
File,
Packages,
}What a framework detector input is.
PHP: the $type of Framework::addInput().
use utopia_detector::Rendered;pub enum Rendered<'a> {
Option(&'a dyn Rendering),
Static(Static),
}What a RenderingDetector found: one of its options, or static output
it made up because none matched.
use utopia_detector::Strategy;pub enum Strategy {
FileMatch,
Extension,
Languages,
}What a RuntimeDetector's inputs are, and so how they are matched.
PHP: Utopia\Detector\Detector\Strategy.
use utopia_detector::Framework;pub trait Framework: Send + SyncA web framework, recognised by its configuration files and the packages a project depends on.
PHP: Utopia\Detector\Detection\Framework.
use utopia_detector::Packager;pub trait Packager: Send + SyncA package manager, recognised by the files it leaves in a project.
PHP: Utopia\Detector\Detection\Packager.
use utopia_detector::Rendering;pub trait Rendering: Send + SyncHow a framework's build output is served, recognised by the files the build leaves for a given framework.
PHP: Utopia\Detector\Detection\Rendering.
use utopia_detector::Runtime;pub trait Runtime: Send + SyncA language runtime, recognised by its languages, file extensions or files.
PHP: Utopia\Detector\Detection\Runtime.
use utopia_detector::best;pub fn best<'a>(scores: impl IntoIterator<Item = Score<'a>>) -> Option<&'a [u8]>The name of the framework a detector picks from scores, one per option
in the order the options were added: options sharing a name add up; the
most matches win; a tie goes to the fewest parents, except that Astro
yields to the runner-up. None when nothing matches.
PHP: the ranking in Framework::detect() (a stable arsort(), then a
stable usort() on parents).
use utopia_detector::dependencies;pub fn dependencies(manifest: &[u8]) -> Vec<Vec<u8>>The dependency names declared in a package.json (JSON) or
pubspec.yaml (YAML), section by section; none when it parses as
neither.
PHP: Framework::dependencies().
use utopia_detector::html_fallback;pub fn html_fallback<'a>(inputs: impl IntoIterator<Item = &'a [u8]>) -> Option<&'a [u8]>The only file among inputs with the extension html, the static
output's fallback; None with none or several.
PHP: the pathinfo($file, PATHINFO_EXTENSION) === 'html' scan at the end
of Rendering::detect().
use utopia_detector::matches;pub fn matches<'a>(
files: impl IntoIterator<Item = &'a [u8]>,
packages: impl IntoIterator<Item = &'a [u8]>,
inputs: &[&[u8]],
manifests: &[Vec<Vec<u8>>],
) -> usizeHow many of an option's files are among the file inputs, plus how many
of its packages each manifest's dependencies declare. A file or
package the option lists twice counts twice.
PHP: count(array_intersect($detector->getFiles(), $files)) plus the
in_array($packageNeeded, $dependencies, true) hits of detect().