Skip to main content

ModuleLoader

Trait ModuleLoader 

Source
pub trait ModuleLoader {
    // Required method
    fn load(&self, from: &Path, specifier: &str) -> Option<(PathBuf, String)>;

    // Provided methods
    fn is_installed(&self, _from: &Path, _specifier: &str) -> bool { ... }
    fn holds_no_code(&self, _from: &Path, _specifier: &str) -> bool { ... }
}
Expand description

Finds the modules a config file imports, so their values can be evaluated statically too.

The evaluator asks for every module a config imports a value from (import base from './base', import { vitestConfig } from '@scope/vitest-config/frontend', require('./base')). An implementation returns the source of the modules worth following, typically files of the project itself and of its workspace packages, and None for anything else (an installed package, a builtin), whose values then stay ConfigValue::Unknown.

Required Methods§

Source

fn load(&self, from: &Path, specifier: &str) -> Option<(PathBuf, String)>

The path and source of the module specifier names when imported from the file from.

Provided Methods§

Source

fn is_installed(&self, _from: &Path, _specifier: &str) -> bool

Whether specifier, a bare specifier imported from the file from that Self::load does not load, names an installed package rather than code of the project: not a workspace package the loader cannot map to a source file, nor an alias of a project directory (a tsconfig path such as @app/tools). Only for an installed package does the evaluator take a define… helper (defineConfig) to be the value it is given, a copying merge (mergeConfig) the merge of what it is given, and the methods of a binding the config only calls methods on to keep nothing they are given; code of the project may do anything. false unless the loader says otherwise, so that nothing it does not vouch for is trusted. Without a loader, every bare specifier counts as one.

Source

fn holds_no_code(&self, _from: &Path, _specifier: &str) -> bool

Whether specifier, a relative import from the file from that Self::load does not load, names a file of the project that holds no code: a declaration file (./types beside types.d.ts), JSON, a stylesheet or an asset. A re-export of one changes nothing; one of any other module the loader does not load may run code of the project. false unless the loader says otherwise.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§