diff --git a/Cargo.lock b/Cargo.lock index ba55cad908..2faf17d449 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1257,9 +1257,9 @@ dependencies = [ [[package]] name = "deno_core" -version = "0.266.0" +version = "0.267.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfbfe65d133be3abefb973f87b601f686666bb05d5521f0fab16d9dd28a5d5cf" +checksum = "b5dc9aeacf98e78c1d8fa716e35f2e8a960e349f73d6bc485d45e49457d80556" dependencies = [ "anyhow", "bincode", @@ -1714,9 +1714,9 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.142.0" +version = "0.143.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f96d7d6806eb726b4feb3092cbdaf887ae412b6e8be7c67617c61dbe8b3f1693" +checksum = "594aa46152868ee15e104ab3484976a144162694a00c4096174e71b78fdb32c7" dependencies = [ "proc-macro-rules", "proc-macro2", @@ -5600,9 +5600,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.175.0" +version = "0.176.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb0193c9e969f1d7a660a2c5ad7c94bb00146c5f5367607eabb2af78094160f" +checksum = "25b62c66605745359af254c41af8e6ea2b6124a3698628a7329a6f32698250ee" dependencies = [ "bytes", "derive_more", diff --git a/Cargo.toml b/Cargo.toml index 6dea7d48e9..b2f6f4fa3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ repository = "https://github.com/denoland/deno" [workspace.dependencies] deno_ast = { version = "0.34.1", features = ["transpiling"] } -deno_core = { version = "0.266.0", features = ["snapshot_data_bincode"] } +deno_core = { version = "0.267.0" } deno_bench_util = { version = "0.134.0", path = "./bench_util" } deno_lockfile = "0.19.0" diff --git a/bench_util/js_runtime.rs b/bench_util/js_runtime.rs index 819a6c02bd..a97d8ae501 100644 --- a/bench_util/js_runtime.rs +++ b/bench_util/js_runtime.rs @@ -116,7 +116,7 @@ pub fn bench_js_async_with( } async fn inner_async(src: &'static str, runtime: &mut JsRuntime) { - runtime.execute_script_static("inner_loop", src).unwrap(); + runtime.execute_script("inner_loop", src).unwrap(); runtime .run_event_loop(PollEventLoopOptions::default()) .await diff --git a/cli/build.rs b/cli/build.rs index 0a599b03b1..8dc3dcb759 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -276,6 +276,7 @@ mod ts { build_libs, path_dts, )], + extension_transpiler: None, with_runtime_cb: None, skip_op_registration: false, }, diff --git a/cli/js.rs b/cli/js.rs index 552f3842dc..0db132bdbf 100644 --- a/cli/js.rs +++ b/cli/js.rs @@ -29,7 +29,7 @@ mod tests { ..Default::default() }); js_runtime - .execute_script_static( + .execute_script( "", r#" if (!(bootstrap.mainRuntime && bootstrap.workerRuntime)) { diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 138640d7fb..ce848c210b 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -4186,7 +4186,7 @@ fn start_tsc(runtime: &mut JsRuntime, debug: bool) -> Result<(), AnyError> { let init_config = json!({ "debug": debug }); let init_src = format!("globalThis.serverInit({init_config});"); - runtime.execute_script(located_script_name!(), init_src.into())?; + runtime.execute_script(located_script_name!(), init_src)?; Ok(()) } @@ -4564,7 +4564,7 @@ fn request( "globalThis.serverRequest({id}, \"{}\", {});", request.method, &request.args ); - runtime.execute_script(located_script_name!(), request_src.into())?; + runtime.execute_script(located_script_name!(), request_src)?; let op_state = runtime.op_state(); let mut op_state = op_state.borrow_mut(); diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index e2e11e440e..4961d1ed94 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -848,7 +848,7 @@ pub fn exec(request: Request) -> Result { "rootNames": root_names, "localOnly": request.check_mode == TypeCheckMode::Local, }); - let exec_source = format!("globalThis.exec({request_value})").into(); + let exec_source = format!("globalThis.exec({request_value})"); let mut runtime = JsRuntime::new(RuntimeOptions { startup_snapshot: Some(compiler_snapshot()), @@ -1007,7 +1007,7 @@ mod tests { ..Default::default() }); js_runtime - .execute_script_static( + .execute_script( "", r#" if (!(globalThis.exec)) { diff --git a/cli/worker.rs b/cli/worker.rs index 302303f286..47658e5945 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -397,10 +397,7 @@ impl CliMainWorker { name: &'static str, source_code: &'static str, ) -> Result, AnyError> { - self - .worker - .js_runtime - .execute_script_static(name, source_code) + self.worker.js_runtime.execute_script(name, source_code) } } @@ -656,9 +653,9 @@ impl CliMainWorkerFactory { if self.shared.subcommand.needs_test() { macro_rules! test_file { ($($file:literal),*) => { - $(worker.js_runtime.lazy_load_es_module_from_code( + $(worker.js_runtime.lazy_load_es_module_with_code( concat!("ext:cli/", $file), - deno_core::FastString::StaticAscii(include_str!(concat!("js/", $file))), + deno_core::ascii_str_include!(concat!("js/", $file)), )?;)* } } diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 98b927ba83..40c9e70199 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -636,8 +636,7 @@ pub fn load_cjs_module( main = main, module = escape_for_single_quote_string(module), inspect_brk = inspect_brk, - ) - .into(); + ); js_runtime.execute_script(located_script_name!(), source_code)?; Ok(()) diff --git a/runtime/shared.rs b/runtime/shared.rs index 04fcdcfdb7..fc91be1453 100644 --- a/runtime/shared.rs +++ b/runtime/shared.rs @@ -7,8 +7,9 @@ use deno_ast::SourceTextInfo; use deno_core::error::AnyError; use deno_core::extension; use deno_core::Extension; -use deno_core::ExtensionFileSource; -use deno_core::ExtensionFileSourceCode; +use deno_core::ModuleCodeString; +use deno_core::ModuleName; +use deno_core::SourceMapData; use std::path::Path; extension!(runtime, @@ -56,36 +57,38 @@ extension!(runtime, customizer = |ext: &mut Extension| { #[cfg(not(feature = "exclude_runtime_main_js"))] { - ext.esm_files.to_mut().push(ExtensionFileSource::new("ext:runtime_main/js/99_main.js", include_str!("./js/99_main.js"))); + use deno_core::ascii_str_include; + use deno_core::ExtensionFileSource; + ext.esm_files.to_mut().push(ExtensionFileSource::new("ext:runtime_main/js/99_main.js", ascii_str_include!("./js/99_main.js"))); ext.esm_entry_point = Some("ext:runtime_main/js/99_main.js"); } } ); pub fn maybe_transpile_source( - source: &mut ExtensionFileSource, -) -> Result<(), AnyError> { + name: ModuleName, + source: ModuleCodeString, +) -> Result<(ModuleCodeString, Option), AnyError> { // Always transpile `node:` built-in modules, since they might be TypeScript. - let media_type = if source.specifier.starts_with("node:") { + let media_type = if name.starts_with("node:") { MediaType::TypeScript } else { - MediaType::from_path(Path::new(&source.specifier)) + MediaType::from_path(Path::new(&name)) }; match media_type { MediaType::TypeScript => {} - MediaType::JavaScript => return Ok(()), - MediaType::Mjs => return Ok(()), + MediaType::JavaScript => return Ok((source, None)), + MediaType::Mjs => return Ok((source, None)), _ => panic!( "Unsupported media type for snapshotting {media_type:?} for file {}", - source.specifier + name ), } - let code = source.load()?; let parsed = deno_ast::parse_module(ParseParams { - specifier: deno_core::url::Url::parse(source.specifier).unwrap(), - text_info: SourceTextInfo::from_string(code.as_str().to_owned()), + specifier: deno_core::url::Url::parse(&name).unwrap(), + text_info: SourceTextInfo::from_string(source.as_str().to_owned()), media_type, capture_tokens: false, scope_analysis: false, @@ -97,7 +100,5 @@ pub fn maybe_transpile_source( ..Default::default() })?; - source.code = - ExtensionFileSourceCode::Computed(transpiled_source.text.into()); - Ok(()) + Ok((transpiled_source.text.into(), None)) } diff --git a/runtime/snapshot.rs b/runtime/snapshot.rs index e48af43ff7..edfef39c23 100644 --- a/runtime/snapshot.rs +++ b/runtime/snapshot.rs @@ -13,6 +13,7 @@ use deno_http::DefaultHttpPropertyExtractor; use std::io::Write; use std::path::Path; use std::path::PathBuf; +use std::rc::Rc; use std::sync::Arc; #[derive(Clone)] @@ -204,7 +205,7 @@ pub fn create_runtime_snapshot( // NOTE(bartlomieju): ordering is important here, keep it in sync with // `runtime/worker.rs`, `runtime/web_worker.rs` and `runtime/snapshot.rs`! let fs = std::sync::Arc::new(deno_fs::RealFs); - let mut extensions: Vec = vec![ + let extensions: Vec = vec![ deno_webidl::deno_webidl::init_ops_and_esm(), deno_console::deno_console::init_ops_and_esm(), deno_url::deno_url::init_ops_and_esm(), @@ -257,20 +258,14 @@ pub fn create_runtime_snapshot( ops::web_worker::deno_web_worker::init_ops(), ]; - for extension in &mut extensions { - for source in extension.esm_files.to_mut() { - maybe_transpile_source(source).unwrap(); - } - for source in extension.js_files.to_mut() { - maybe_transpile_source(source).unwrap(); - } - } - let output = create_snapshot( CreateSnapshotOptions { cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"), startup_snapshot: None, extensions, + extension_transpiler: Some(Rc::new(|specifier, source| { + maybe_transpile_source(specifier, source) + })), with_runtime_cb: Some(Box::new(|rt| { let isolate = rt.v8_isolate(); let scope = &mut v8::HandleScope::new(isolate); diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 97b855c567..6571da6c26 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -2,6 +2,7 @@ use crate::inspector_server::InspectorServer; use crate::ops; use crate::permissions::PermissionsContainer; +use crate::shared::maybe_transpile_source; use crate::shared::runtime; use crate::tokio_util::create_and_run_current_thread; use crate::worker::import_meta_resolve_callback; @@ -498,16 +499,6 @@ impl WebWorker { extension.esm_files = std::borrow::Cow::Borrowed(&[]); extension.esm_entry_point = None; } - #[cfg(not(feature = "only_snapshotted_js_sources"))] - { - use crate::shared::maybe_transpile_source; - for source in extension.esm_files.to_mut() { - maybe_transpile_source(source).unwrap(); - } - for source in extension.js_files.to_mut() { - maybe_transpile_source(source).unwrap(); - } - } } extensions.extend(std::mem::take(&mut options.extensions)); @@ -535,6 +526,9 @@ impl WebWorker { shared_array_buffer_store: options.shared_array_buffer_store.clone(), compiled_wasm_module_store: options.compiled_wasm_module_store.clone(), extensions, + extension_transpiler: Some(Rc::new(|specifier, source| { + maybe_transpile_source(specifier, source) + })), inspector: options.maybe_inspector_server.is_some(), feature_checker: Some(options.feature_checker.clone()), op_metrics_factory_fn, @@ -664,10 +658,7 @@ impl WebWorker { &mut self, module_specifier: &ModuleSpecifier, ) -> Result { - self - .js_runtime - .load_main_module(module_specifier, None) - .await + self.js_runtime.load_main_es_module(module_specifier).await } /// Loads and instantiates specified JavaScript module as "side" module. @@ -675,10 +666,7 @@ impl WebWorker { &mut self, module_specifier: &ModuleSpecifier, ) -> Result { - self - .js_runtime - .load_side_module(module_specifier, None) - .await + self.js_runtime.load_side_es_module(module_specifier).await } /// Loads, instantiates and executes specified JavaScript module. diff --git a/runtime/worker.rs b/runtime/worker.rs index d19e520c9b..ab3e5fa875 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -45,6 +45,7 @@ use log::debug; use crate::inspector_server::InspectorServer; use crate::ops; use crate::permissions::PermissionsContainer; +use crate::shared::maybe_transpile_source; use crate::shared::runtime; use crate::BootstrapOptions; @@ -445,16 +446,6 @@ impl MainWorker { extension.esm_files = std::borrow::Cow::Borrowed(&[]); extension.esm_entry_point = None; } - #[cfg(not(feature = "only_snapshotted_js_sources"))] - { - use crate::shared::maybe_transpile_source; - for source in extension.esm_files.to_mut() { - maybe_transpile_source(source).unwrap(); - } - for source in extension.js_files.to_mut() { - maybe_transpile_source(source).unwrap(); - } - } } extensions.extend(std::mem::take(&mut options.extensions)); @@ -481,6 +472,9 @@ impl MainWorker { shared_array_buffer_store: options.shared_array_buffer_store.clone(), compiled_wasm_module_store: options.compiled_wasm_module_store.clone(), extensions, + extension_transpiler: Some(Rc::new(|specifier, source| { + maybe_transpile_source(specifier, source) + })), inspector: options.maybe_inspector_server.is_some(), is_main: true, feature_checker: Some(options.feature_checker.clone()), @@ -579,10 +573,7 @@ impl MainWorker { &mut self, module_specifier: &ModuleSpecifier, ) -> Result { - self - .js_runtime - .load_main_module(module_specifier, None) - .await + self.js_runtime.load_main_es_module(module_specifier).await } /// Loads and instantiates specified JavaScript module as "side" module. @@ -590,10 +581,7 @@ impl MainWorker { &mut self, module_specifier: &ModuleSpecifier, ) -> Result { - self - .js_runtime - .load_side_module(module_specifier, None) - .await + self.js_runtime.load_side_es_module(module_specifier).await } /// Executes specified JavaScript module.