Skip to content

BREAKING: Remove unstable Deno.emit and Deno.formatDiagnostics APIs #14463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 0 additions & 105 deletions cli/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::errors::get_error_class_name;
use crate::file_fetcher::FileFetcher;

use deno_core::error::AnyError;
use deno_core::futures::future;
use deno_core::futures::FutureExt;
use deno_core::serde::Deserialize;
use deno_core::serde::Serialize;
Expand All @@ -16,7 +15,6 @@ use deno_graph::source::LoadFuture;
use deno_graph::source::LoadResponse;
use deno_graph::source::Loader;
use deno_runtime::permissions::Permissions;
use std::collections::HashMap;
use std::sync::Arc;

#[derive(Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -248,106 +246,3 @@ impl CacherLoader for FetchCacher {
self
}
}

/// An in memory cache that is used by the runtime `Deno.emit()` API to provide
/// the same behavior as the disk cache when sources are provided.
#[derive(Debug)]
pub struct MemoryCacher {
sources: HashMap<String, Arc<String>>,
declarations: HashMap<ModuleSpecifier, String>,
emits: HashMap<ModuleSpecifier, String>,
maps: HashMap<ModuleSpecifier, String>,
build_infos: HashMap<ModuleSpecifier, String>,
versions: HashMap<ModuleSpecifier, String>,
}

impl MemoryCacher {
pub fn new(sources: HashMap<String, Arc<String>>) -> Self {
Self {
sources,
declarations: HashMap::default(),
emits: HashMap::default(),
maps: HashMap::default(),
build_infos: HashMap::default(),
versions: HashMap::default(),
}
}
}

impl Loader for MemoryCacher {
fn load(
&mut self,
specifier: &ModuleSpecifier,
_is_dynamic: bool,
) -> LoadFuture {
let mut specifier_str = specifier.to_string();
if !self.sources.contains_key(&specifier_str) {
specifier_str = specifier_str.replace("file:///", "/");
if !self.sources.contains_key(&specifier_str) {
specifier_str = specifier_str[3..].to_string();
}
}
let response =
self
.sources
.get(&specifier_str)
.map(|c| LoadResponse::Module {
specifier: specifier.clone(),
maybe_headers: None,
content: c.to_owned(),
});
Box::pin(future::ready(Ok(response)))
}
}

impl Cacher for MemoryCacher {
fn get(
&self,
cache_type: CacheType,
specifier: &ModuleSpecifier,
) -> Option<String> {
match cache_type {
CacheType::Declaration => self.declarations.get(specifier).cloned(),
CacheType::Emit => self.emits.get(specifier).cloned(),
CacheType::SourceMap => self.maps.get(specifier).cloned(),
CacheType::TypeScriptBuildInfo => {
self.build_infos.get(specifier).cloned()
}
CacheType::Version => self.versions.get(specifier).cloned(),
}
}

fn set(
&mut self,
cache_type: CacheType,
specifier: &ModuleSpecifier,
value: String,
) -> Result<(), AnyError> {
match cache_type {
CacheType::Declaration => {
self.declarations.insert(specifier.clone(), value)
}
CacheType::Emit => self.emits.insert(specifier.clone(), value),
CacheType::SourceMap => self.maps.insert(specifier.clone(), value),
CacheType::TypeScriptBuildInfo => {
self.build_infos.insert(specifier.clone(), value)
}
CacheType::Version => self.versions.insert(specifier.clone(), value),
};
Ok(())
}
}

impl CacherLoader for MemoryCacher {
fn as_cacher(&self) -> &dyn Cacher {
self
}

fn as_mut_loader(&mut self) -> &mut dyn Loader {
self
}

fn as_mut_cacher(&mut self) -> &mut dyn Cacher {
self
}
}
19 changes: 0 additions & 19 deletions cli/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use deno_core::serde::Deserialize;
use deno_core::serde::Deserializer;
use deno_core::serde::Serialize;
use deno_core::serde::Serializer;
use deno_graph::ModuleGraphError;
use once_cell::sync::Lazy;
use regex::Regex;
use std::error::Error;
Expand All @@ -16,7 +15,6 @@ const MAX_SOURCE_LINE_LENGTH: usize = 150;

const UNSTABLE_DENO_PROPS: &[&str] = &[
"BenchDefinition",
"CompilerOptions",
"CreateHttpClientOptions",
"DatagramConn",
"Diagnostic",
Expand All @@ -43,8 +41,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"connect",
"consoleSize",
"createHttpClient",
"emit",
"formatDiagnostics",
"futime",
"futimeSync",
"hostname",
Expand Down Expand Up @@ -360,21 +356,6 @@ impl Diagnostics {
Diagnostics(diagnostics)
}

pub fn extend_graph_errors(&mut self, errors: Vec<ModuleGraphError>) {
self.0.extend(errors.into_iter().map(|err| Diagnostic {
category: DiagnosticCategory::Error,
code: 900001,
start: None,
end: None,
message_text: Some(err.to_string()),
message_chain: None,
source: None,
source_line: None,
file_name: Some(err.specifier().to_string()),
related_information: None,
}));
}

/// Return a set of diagnostics where only the values where the predicate
/// returns `true` are included.
pub fn filter<P>(&self, predicate: P) -> Self
Expand Down
Loading