Struct deno_graph::ModuleGraph
source · [−]pub struct ModuleGraph {
pub roots: Vec<(ModuleSpecifier, ModuleKind)>,
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, ModuleKind)>
imports: Vec<GraphImport>
redirects: BTreeMap<ModuleSpecifier, ModuleSpecifier>
Implementations
sourceimpl 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) -> Vec<ModuleGraphError>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn errors(&self) -> Vec<ModuleGraphError>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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 lock(&self) -> Result<(), ModuleGraphError>
pub fn lock(&self) -> Result<(), ModuleGraphError>
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.
sourcepub fn modules(&self) -> Vec<&Module>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn modules(&self) -> Vec<&Module>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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 resolution_map(
&self
) -> HashMap<ModuleSpecifier, HashMap<String, Resolved>>
pub fn resolution_map(
&self
) -> HashMap<ModuleSpecifier, HashMap<String, Resolved>>
Returns a map of the fully resolved dependency graph of the module graph.
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
) -> 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.
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.
Trait Implementations
sourceimpl Debug for ModuleGraph
impl Debug for ModuleGraph
sourceimpl Display for ModuleGraph
impl Display for ModuleGraph
sourceimpl Serialize for ModuleGraph
impl Serialize for ModuleGraph
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more