Struct deno_graph::ModuleGraph
source · [−]pub struct ModuleGraph {
pub roots: Vec<(ModuleSpecifier, ModuleKind)>,
pub redirects: BTreeMap<ModuleSpecifier, ModuleSpecifier>,
/* private fields */
}
Expand description
The structure which represents a module graph, which can be serialized as well as “printed”. The roots of the graph represent the “starting” point which can be located in the module “slots” in the graph. The graph also contains any redirects where the requested module specifier was redirected to another module specifier when being loaded.
Fields
roots: Vec<(ModuleSpecifier, ModuleKind)>
redirects: BTreeMap<ModuleSpecifier, ModuleSpecifier>
Implementations
Returns true
if the specifier resolves to a module within a graph,
otherwise returns false
.
Returns any errors that are in the module graph.
Get a module from the module graph, returning None
if the module is not
part of the graph, or if when loading the module it errored. If any module
resolution error is needed, then use the try_get()
method which will
return any resolution error as the error in the result.
Determine if the graph sources are valid by calling the passed locker. If the integrity of all the sources passes or if there is no locker supplied the method results in an ok, otherwise returns an error which indicates the first specifier that failed the integrity check.
Return a vector of references to ES module objects in the graph. Only ES
modules that were fully resolved are present, as “errors” are omitted. If
you need to know what errors are in the graph, use the .errors()
method,
or if you just need to check if everything is “ok” with the graph, use the
.valid()
method.
pub fn synthetic_modules(&self) -> Vec<&Module>ⓘ
Returns a map of the fully resolved dependency graph of the module graph.
Resolve a specifier from the module graph following any possible redirects returning the “final” module.
pub fn resolve_dependency(
&self,
specifier: &str,
referrer: &ModuleSpecifier,
prefer_types: bool
) -> Option<&ModuleSpecifier>
pub fn resolve_dependency(
&self,
specifier: &str,
referrer: &ModuleSpecifier,
prefer_types: bool
) -> Option<&ModuleSpecifier>
Resolve a dependency of a referring module providing the string specifier of the dependency and returning an optional fully qualified module specifier.
The prefer_types
flags indicates if a type dependency is preferred over
a code dependency. If true
, a type dependency will be returned in favor
of a code dependency. If false
a code dependency will be returned in
favor of a type dependency. The value should be set to true
when
resolving specifiers for type checking, or otherwise false
.
pub fn specifiers(
&self
) -> HashMap<ModuleSpecifier, Result<(ModuleSpecifier, ModuleKind, MediaType), ModuleGraphError>>
pub fn specifiers(
&self
) -> HashMap<ModuleSpecifier, Result<(ModuleSpecifier, ModuleKind, MediaType), ModuleGraphError>>
Return a map representation of the specifiers in the graph, where each key is a module specifier and each value is a result that contains a tuple of the module specifier, module kind, and media type, or the module graph error.
pub fn try_get(
&self,
specifier: &ModuleSpecifier
) -> Result<Option<&Module>, ModuleGraphError>
pub fn try_get(
&self,
specifier: &ModuleSpecifier
) -> Result<Option<&Module>, ModuleGraphError>
Retrieve a module from the module graph. If the module identified as a
dependency of the graph, but resolving or loading that module resulted in
an error, the error will be returned as the Err
of the result. If the
module is not part of the graph, or the module is missing from the graph,
the result will be Ok
with the option of the module.
Walk the graph from the root, checking to see if there are any module graph errors on non-type only, non-dynamic imports. The first error is returned as as error result, otherwise ok if there are no errors.
Walk the graph from the root, checking to see if there are any module graph errors on non-dynamic imports that are type only related. The first error is returned as an error result, otherwise ok if there are no errors.
This is designed to be used in cases where the graph needs to be validated from a type checking perspective, prior to type checking the graph.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for ModuleGraph
impl !Send for ModuleGraph
impl !Sync for ModuleGraph
impl Unpin for ModuleGraph
impl !UnwindSafe for ModuleGraph
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more