deno/libs/resolver/loader/mod.rs
David Sherret 489d9bbdcf
Some checks are pending
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
refactor(loader): extract out more module loading code from cli crate (#30084)
2025-07-14 11:27:51 -04:00

61 lines
1.3 KiB
Rust

// Copyright 2018-2025 the Deno authors. MIT license.
mod npm;
#[cfg(all(feature = "graph", feature = "deno_ast"))]
mod module_loader;
use std::borrow::Cow;
use deno_media_type::MediaType;
#[cfg(all(feature = "graph", feature = "deno_ast"))]
pub use module_loader::*;
pub use npm::*;
use url::Url;
pub enum RequestedModuleType<'a> {
None,
Json,
Text,
Bytes,
Other(&'a str),
}
#[allow(clippy::disallowed_types)]
type ArcStr = std::sync::Arc<str>;
#[allow(clippy::disallowed_types)]
type ArcBytes = std::sync::Arc<[u8]>;
pub enum LoadedModuleOrAsset<'a> {
Module(LoadedModule<'a>),
/// An external asset that the caller must fetch.
ExternalAsset {
specifier: Cow<'a, Url>,
/// Whether this was a module the graph knows about.
statically_analyzable: bool,
},
}
pub struct LoadedModule<'a> {
pub specifier: Cow<'a, Url>,
pub media_type: MediaType,
pub source: LoadedModuleSource,
}
pub enum LoadedModuleSource {
ArcStr(ArcStr),
ArcBytes(ArcBytes),
String(Cow<'static, str>),
Bytes(Cow<'static, [u8]>),
}
impl LoadedModuleSource {
pub fn as_bytes(&self) -> &[u8] {
match self {
LoadedModuleSource::ArcStr(text) => text.as_bytes(),
LoadedModuleSource::ArcBytes(bytes) => bytes,
LoadedModuleSource::String(text) => text.as_bytes(),
LoadedModuleSource::Bytes(bytes) => bytes,
}
}
}