summaryrefslogtreecommitdiff
path: root/cli/module_loader.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-08-19 21:36:35 +0100
committerGitHub <noreply@github.com>2024-08-19 22:36:35 +0200
commitb5051e25c219c188f17d499ee4e101a64eb62e37 (patch)
tree88c6ab12aefd491d52e638c6e5043728412bca9b /cli/module_loader.rs
parentbf510544ef26b89d4c2ae935893eaf62995ed903 (diff)
feat: Deprecate "import assertions" with a warning (#24743)
This commit deprecates "import assertions" proposal that has been replaced with "import attributes". Any time an import assertion is encountered a warning will be printed to the terminal. This warning will be printed for both local and remote files (ie. user code and dependencies). Import assertions support will be removed in Deno 2.
Diffstat (limited to 'cli/module_loader.rs')
-rw-r--r--cli/module_loader.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/cli/module_loader.rs b/cli/module_loader.rs
index afd707ad8..9f5208936 100644
--- a/cli/module_loader.rs
+++ b/cli/module_loader.rs
@@ -2,6 +2,7 @@
use std::borrow::Cow;
use std::cell::RefCell;
+use std::collections::HashSet;
use std::path::PathBuf;
use std::pin::Pin;
use std::rc::Rc;
@@ -44,6 +45,7 @@ use deno_core::error::generic_error;
use deno_core::error::AnyError;
use deno_core::futures::future::FutureExt;
use deno_core::futures::Future;
+use deno_core::parking_lot::Mutex;
use deno_core::resolve_url;
use deno_core::ModuleCodeString;
use deno_core::ModuleLoader;
@@ -291,6 +293,7 @@ impl CliModuleLoaderFactory {
emitter: self.shared.emitter.clone(),
parsed_source_cache: self.shared.parsed_source_cache.clone(),
shared: self.shared.clone(),
+ prevent_v8_code_cache: Default::default(),
})));
ModuleLoaderAndSourceMapGetter {
module_loader: loader,
@@ -342,6 +345,10 @@ struct CliModuleLoaderInner<TGraphContainer: ModuleGraphContainer> {
emitter: Arc<Emitter>,
parsed_source_cache: Arc<ParsedSourceCache>,
graph_container: TGraphContainer,
+ // NOTE(bartlomieju): this is temporary, for deprecated import assertions.
+ // Should be removed in Deno 2.
+ // Modules stored here should not be V8 code-cached.
+ prevent_v8_code_cache: Arc<Mutex<HashSet<String>>>,
}
impl<TGraphContainer: ModuleGraphContainer>
@@ -827,6 +834,14 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
code_cache: &[u8],
) -> Pin<Box<dyn Future<Output = ()>>> {
if let Some(cache) = self.0.shared.code_cache.as_ref() {
+ if self
+ .0
+ .prevent_v8_code_cache
+ .lock()
+ .contains(specifier.as_str())
+ {
+ return std::future::ready(()).boxed_local();
+ }
// This log line is also used by tests.
log::debug!(
"Updating V8 code cache for ES module: {specifier}, [{source_hash:?}]"
@@ -841,6 +856,19 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
std::future::ready(()).boxed_local()
}
+ fn purge_and_prevent_code_cache(&self, specifier: &str) {
+ if let Some(cache) = self.0.shared.code_cache.as_ref() {
+ // This log line is also used by tests.
+ log::debug!("Remove V8 code cache for ES module: {specifier}");
+ cache.remove_code_cache(specifier);
+ self
+ .0
+ .prevent_v8_code_cache
+ .lock()
+ .insert(specifier.to_string());
+ }
+ }
+
fn get_source_map(&self, file_name: &str) -> Option<Vec<u8>> {
let specifier = resolve_url(file_name).ok()?;
match specifier.scheme() {