// Copyright 2018-2025 the Deno authors. MIT license. use std::borrow::Cow; use std::collections::BTreeMap; use deno_config::workspace::PackageJsonDepResolution; use deno_runtime::deno_permissions::PermissionsOptions; use deno_runtime::deno_telemetry::OtelConfig; use deno_semver::Version; use indexmap::IndexMap; use serde::Deserialize; use serde::Serialize; use url::Url; use super::virtual_fs::FileSystemCaseSensitivity; use crate::args::UnstableConfig; pub const MAGIC_BYTES: &[u8; 8] = b"d3n0l4nd"; #[derive(Deserialize, Serialize)] pub enum NodeModules { Managed { /// Relative path for the node_modules directory in the vfs. node_modules_dir: Option, }, Byonm { root_node_modules_dir: Option, }, } #[derive(Deserialize, Serialize)] pub struct SerializedWorkspaceResolverImportMap { pub specifier: String, pub json: String, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct SerializedResolverWorkspaceJsrPackage { pub relative_base: String, pub name: String, pub version: Option, pub exports: IndexMap, } #[derive(Deserialize, Serialize)] pub struct SerializedWorkspaceResolver { pub import_map: Option, pub jsr_pkgs: Vec, pub package_jsons: BTreeMap, pub pkg_json_resolution: PackageJsonDepResolution, } // Note: Don't use hashmaps/hashsets. Ensure the serialization // is deterministic. #[derive(Deserialize, Serialize)] pub struct Metadata { pub argv: Vec, pub seed: Option, pub code_cache_key: Option, pub permissions: PermissionsOptions, pub location: Option, pub v8_flags: Vec, pub log_level: Option, pub ca_stores: Option>, pub ca_data: Option>, pub unsafely_ignore_certificate_errors: Option>, pub env_vars_from_env_file: IndexMap, pub workspace_resolver: SerializedWorkspaceResolver, pub entrypoint_key: String, pub node_modules: Option, pub unstable_config: UnstableConfig, pub otel_config: OtelConfig, pub vfs_case_sensitivity: FileSystemCaseSensitivity, } pub struct SourceMapStore { data: IndexMap, Cow<'static, [u8]>>, } impl SourceMapStore { pub fn with_capacity(capacity: usize) -> Self { Self { data: IndexMap::with_capacity(capacity), } } pub fn iter(&self) -> impl Iterator { self.data.iter().map(|(k, v)| (k.as_ref(), v.as_ref())) } #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { self.data.len() } pub fn add( &mut self, specifier: Cow<'static, str>, source_map: Cow<'static, [u8]>, ) { self.data.insert(specifier, source_map); } pub fn get(&self, specifier: &str) -> Option<&[u8]> { self.data.get(specifier).map(|v| v.as_ref()) } }