Rust

Crate root

Module
What utopia_detector defines at its root.

Contents

Structs
AnalogAnalog, the Angular meta-framework.AngularAngular.AstroAstro. 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.BunBun.CppC++.DartDart.DenoDeno.DetectedA 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`.Dotnet.NET.FlutterFlutter (web).FrameworkDetectorFinds 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](Framework::parents), except that Astro yields to the runner-up.JasprJaspr, 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.JavaJava.LynxLynx.NextJsNext.js.NodeNode.js: the only runtime whose install command follows the packager.Npmnpm: `package.json` or `package-lock.json`.NuxtNuxt.PackagerDetectorFinds 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.PhpPHP.Pnpmpnpm: `pnpm-lock.yaml`.PythonPython.ReactReact.ReactNativeReact Native.RemixRemix: always server-side.RenderingDetectorTells 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.RubyRuby.RuntimeDetectorFinds the runtime of a project: the first option, in the order they were added, that matches an input the way the `Strategy` says.ScoreOne option as a framework detector scores it.SsrServer-side rendering: the build has a server entry for the framework.StaticStatic output: plain files, with an optional fallback page.SvelteSvelte.SvelteKitSvelteKit: static when the configuration (or `package.json`) uses `@sveltejs/adapter-static`, server-side otherwise.SwiftSwift.TanStackStartTanStack Start: server-side with a Nitro plugin or without prerendering, static when it prerenders.VueVue.YarnYarn: `yarn.lock`.
use utopia_detector::Analog;
Rust
pub struct Analog;

Analog, the Angular meta-framework.

PHP: Utopia\Detector\Detection\Framework\Analog.

use utopia_detector::Angular;
Rust
pub struct Angular;

Angular.

PHP: Utopia\Detector\Detection\Framework\Angular.

use utopia_detector::Astro;
Rust
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;
Rust
pub struct Bun;

Bun.

PHP: Utopia\Detector\Detection\Runtime\Bun.

use utopia_detector::Cpp;
Rust
pub struct Cpp;

C++.

PHP: Utopia\Detector\Detection\Runtime\CPP.

use utopia_detector::Dart;
Rust
pub struct Dart;

Dart.

PHP: Utopia\Detector\Detection\Runtime\Dart.

use utopia_detector::Deno;
Rust
pub struct Deno;

Deno.

PHP: Utopia\Detector\Detection\Runtime\Deno.

use utopia_detector::Detected;
Rust
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().

Also implements Deref, Clone, Debug.
use utopia_detector::Dotnet;
Rust
pub struct Dotnet;

.NET.

PHP: Utopia\Detector\Detection\Runtime\Dotnet.

use utopia_detector::Flutter;
Rust
pub struct Flutter;

Flutter (web).

PHP: Utopia\Detector\Detection\Framework\Flutter.

use utopia_detector::FrameworkDetector;
Rust
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.

Rust
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");
PHP
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"; // ./.next
Also implements Debug.
use utopia_detector::Jaspr;
Rust
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;
Rust
pub struct Java;

Java.

PHP: Utopia\Detector\Detection\Runtime\Java.

use utopia_detector::Lynx;
Rust
pub struct Lynx;

Lynx.

PHP: Utopia\Detector\Detection\Framework\Lynx.

use utopia_detector::NextJs;
Rust
pub struct NextJs;

Next.js.

PHP: Utopia\Detector\Detection\Framework\NextJs.

use utopia_detector::Node;
Rust
pub struct Node;

Node.js: the only runtime whose install command follows the packager.

PHP: Utopia\Detector\Detection\Runtime\Node.

use utopia_detector::Npm;
Rust
pub struct Npm;

npm: package.json or package-lock.json.

PHP: Utopia\Detector\Detection\Packager\NPM.

use utopia_detector::Nuxt;
Rust
pub struct Nuxt;

Nuxt.

PHP: Utopia\Detector\Detection\Framework\Nuxt.

use utopia_detector::PackagerDetector;
Rust
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.

Rust
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"));
PHP
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"; // yarn
Also implements Debug.
use utopia_detector::Php;
Rust
pub struct Php;

PHP.

PHP: Utopia\Detector\Detection\Runtime\PHP.

use utopia_detector::Pnpm;
Rust
pub struct Pnpm;

pnpm: pnpm-lock.yaml.

PHP: Utopia\Detector\Detection\Packager\PNPM.

use utopia_detector::Python;
Rust
pub struct Python;

Python.

PHP: Utopia\Detector\Detection\Runtime\Python.

use utopia_detector::React;
Rust
pub struct React;

React.

PHP: Utopia\Detector\Detection\Framework\React.

use utopia_detector::ReactNative;
Rust
pub struct ReactNative;

React Native.

PHP: Utopia\Detector\Detection\Framework\ReactNative.

use utopia_detector::Remix;
Rust
pub struct Remix;

Remix: always server-side.

PHP: Utopia\Detector\Detection\Framework\Remix.

use utopia_detector::RenderingDetector;
Rust
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.

Rust
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"));
PHP
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.html
Also implements Debug.
use utopia_detector::Ruby;
Rust
pub struct Ruby;

Ruby.

PHP: Utopia\Detector\Detection\Runtime\Ruby.

use utopia_detector::RuntimeDetector;
Rust
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.

Rust
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");
PHP
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 install
Also implements Debug.
use utopia_detector::Score;
Rust
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;
Rust
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;
Rust
pub struct Static {
    // private fields
}

Static output: plain files, with an optional fallback page.

PHP: Utopia\Detector\Detection\Rendering\XStatic.

use utopia_detector::Svelte;
Rust
pub struct Svelte;

Svelte.

PHP: Utopia\Detector\Detection\Framework\Svelte.

use utopia_detector::SvelteKit;
Rust
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;
Rust
pub struct Swift;

Swift.

PHP: Utopia\Detector\Detection\Runtime\Swift.

use utopia_detector::TanStackStart;
Rust
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;
Rust
pub struct Vue;

Vue.

PHP: Utopia\Detector\Detection\Framework\Vue.

use utopia_detector::Yarn;
Rust
pub struct Yarn;

Yarn: yarn.lock.

PHP: Utopia\Detector\Detection\Packager\Yarn.

use utopia_detector::Adapter;
Rust
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;
Rust
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;
Rust
pub enum Input {
    File,
    Packages,
}

What a framework detector input is.

PHP: the $type of Framework::addInput().

use utopia_detector::Rendered;
Rust
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;
Rust
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;
Rust
pub trait Framework: Send + Sync

A web framework, recognised by its configuration files and the packages a project depends on.

PHP: Utopia\Detector\Detection\Framework.

use utopia_detector::Packager;
Rust
pub trait Packager: Send + Sync

A package manager, recognised by the files it leaves in a project.

PHP: Utopia\Detector\Detection\Packager.

Implemented byNpmPnpmYarn
use utopia_detector::Rendering;
Rust
pub trait Rendering: Send + Sync

How a framework's build output is served, recognised by the files the build leaves for a given framework.

PHP: Utopia\Detector\Detection\Rendering.

Implemented bySsrStatic
use utopia_detector::Runtime;
Rust
pub trait Runtime: Send + Sync

A language runtime, recognised by its languages, file extensions or files.

PHP: Utopia\Detector\Detection\Runtime.

use utopia_detector::best;
Rust
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;
Rust
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;
Rust
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;
Rust
pub fn matches<'a>(
    files: impl IntoIterator<Item = &'a [u8]>,
    packages: impl IntoIterator<Item = &'a [u8]>,
    inputs: &[&[u8]],
    manifests: &[Vec<Vec<u8>>],
) -> usize

How 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().