diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-08-19 21:36:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-19 22:36:35 +0200 |
| commit | b5051e25c219c188f17d499ee4e101a64eb62e37 (patch) | |
| tree | 88c6ab12aefd491d52e638c6e5043728412bca9b /cli | |
| parent | bf510544ef26b89d4c2ae935893eaf62995ed903 (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')
| -rw-r--r-- | cli/cache/code_cache.rs | 13 | ||||
| -rw-r--r-- | cli/main.rs | 5 | ||||
| -rw-r--r-- | cli/module_loader.rs | 28 | ||||
| -rw-r--r-- | cli/standalone/mod.rs | 1 |
4 files changed, 47 insertions, 0 deletions
diff --git a/cli/cache/code_cache.rs b/cli/cache/code_cache.rs index abcd0d46a..d9e951af6 100644 --- a/cli/cache/code_cache.rs +++ b/cli/cache/code_cache.rs @@ -80,6 +80,10 @@ impl CodeCache { data, )); } + + pub fn remove_code_cache(&self, specifier: &str) { + Self::ensure_ok(self.inner.remove_code_cache(specifier)) + } } impl code_cache::CodeCache for CodeCache { @@ -158,6 +162,15 @@ impl CodeCacheInner { self.conn.execute(sql, params)?; Ok(()) } + + pub fn remove_code_cache(&self, specifier: &str) -> Result<(), AnyError> { + let sql = " + DELETE FROM codecache + WHERE specifier=$1;"; + let params = params![specifier]; + self.conn.execute(sql, params)?; + Ok(()) + } } fn serialize_code_cache_type( diff --git a/cli/main.rs b/cli/main.rs index aafa7f009..6a7575dee 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -438,11 +438,15 @@ fn resolve_flags_and_init( DenoSubcommand::Lsp => vec!["--max-old-space-size=3072".to_string()], _ => { if *DENO_FUTURE { + // TODO(bartlomieju): I think this can be removed as it's handled by `deno_core` + // and its settings. // deno_ast removes TypeScript `assert` keywords, so this flag only affects JavaScript // TODO(petamoriken): Need to check TypeScript `assert` keywords in deno_ast vec!["--no-harmony-import-assertions".to_string()] } else { vec![ + // TODO(bartlomieju): I think this can be removed as it's handled by `deno_core` + // and its settings. // If we're still in v1.X version we want to support import assertions. // V8 12.6 unshipped the support by default, so force it by passing a // flag. @@ -455,6 +459,7 @@ fn resolve_flags_and_init( }; init_v8_flags(&default_v8_flags, &flags.v8_flags, get_v8_flags_from_env()); + // TODO(bartlomieju): remove last argument in Deno 2. deno_core::JsRuntime::init_platform(None, !*DENO_FUTURE); util::logger::init(flags.log_level); 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() { diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index 635293cc9..020561ece 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -745,6 +745,7 @@ pub async fn run( // Initialize v8 once from the main thread. v8_set_flags(construct_v8_flags(&[], &metadata.v8_flags, vec![])); + // TODO(bartlomieju): remove last argument in Deno 2. deno_core::JsRuntime::init_platform(None, true); let mut worker = worker_factory |
