Struct deno_graph::ModuleGraph
source · pub struct ModuleGraph {
pub roots: Vec<ModuleSpecifier>,
pub imports: Vec<GraphImport>,
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>
§imports: Vec<GraphImport>
§redirects: BTreeMap<ModuleSpecifier, ModuleSpecifier>
Implementations§
source§impl ModuleGraph
impl ModuleGraph
sourcepub fn contains(&self, specifier: &ModuleSpecifier) -> bool
pub fn contains(&self, specifier: &ModuleSpecifier) -> bool
Returns true
if the specifier resolves to a module within a graph,
otherwise returns false
.
sourcepub fn errors(&self) -> impl Iterator<Item = &ModuleGraphError>
pub fn errors(&self) -> impl Iterator<Item = &ModuleGraphError>
Returns any errors that are in the module graph.
sourcepub fn get(&self, specifier: &ModuleSpecifier) -> Option<&Module>
pub fn get(&self, specifier: &ModuleSpecifier) -> Option<&Module>
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.
sourcepub fn modules(&self) -> impl Iterator<Item = &Module>
pub fn modules(&self) -> impl Iterator<Item = &Module>
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.
sourcepub fn resolve(&self, specifier: &ModuleSpecifier) -> ModuleSpecifier
pub fn resolve(&self, specifier: &ModuleSpecifier) -> ModuleSpecifier
Resolve a specifier from the module graph following any possible redirects returning the “final” module.
sourcepub 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
.
sourcepub fn specifiers(
&self
) -> impl Iterator<Item = (&ModuleSpecifier, Result<(&ModuleSpecifier, ModuleKind, MediaType), &ModuleGraphError>)>
pub fn specifiers(
&self
) -> impl Iterator<Item = (&ModuleSpecifier, Result<(&ModuleSpecifier, ModuleKind, MediaType), &ModuleGraphError>)>
Return the entries of the specifiers in the graph, where the first value is a module specifier and the second value is a result that contains a tuple of the module specifier, module kind, and media type, or the module graph error.
sourcepub 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.
sourcepub fn valid(&self) -> Result<(), ModuleGraphError>
pub fn valid(&self) -> Result<(), ModuleGraphError>
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.
sourcepub fn valid_types_only(&self) -> Result<(), ModuleGraphError>
pub fn valid_types_only(&self) -> Result<(), ModuleGraphError>
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.