diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-08-06 00:00:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 23:00:38 +0000 |
commit | b96f28306490a56aac91b8ef06b35ebdc7f41b63 (patch) | |
tree | 742499afe4b3f4b82f125fc7785fb46632fea22f | |
parent | 85a2b281f566d3404d23852ae29d4a75d020dd5e (diff) |
refactor: remove snapshot_module_load_cb (#20043)
-rw-r--r-- | Cargo.lock | 12 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | cli/build.rs | 2 | ||||
-rw-r--r-- | runtime/build.rs | 54 |
4 files changed, 36 insertions, 36 deletions
diff --git a/Cargo.lock b/Cargo.lock index 5e3e16487..a75c42eb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -977,9 +977,9 @@ dependencies = [ [[package]] name = "deno_core" -version = "0.199.0" +version = "0.200.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70fbd0cb620ac36fac08d708c5f01362280c5aa8149657a225db4932bd73758e" +checksum = "a8ba264b90ceb6e95b39d82e674d8ecae86ca012f900338ea50d1a077d9d75fd" dependencies = [ "anyhow", "bytes", @@ -1349,9 +1349,9 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.77.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b345c096fd8433337ed8e1727f4732397c134e188e1739c88b0c077869020f3" +checksum = "ffd1c83b1fd465ee0156f2917c9af9ca09fe2bf54052a2cae1a8dcbc7b89aefc" dependencies = [ "deno-proc-macro-rules", "lazy-regex", @@ -4452,9 +4452,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.110.0" +version = "0.111.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3bafaee0eecbef6c47ad3e7e0a764e22eb35a229ff7d06b7801fcbeaa5364b8" +checksum = "309b3060a9627882514f3a3ce3cc08ceb347a76aeeadc58f138c3f189cf88b71" dependencies = [ "bytes", "derive_more", diff --git a/Cargo.toml b/Cargo.toml index 852cfe0c2..1d9c54924 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,9 +41,7 @@ repository = "https://github.com/denoland/deno" v8 = { version = "0.74.1", default-features = false } deno_ast = { version = "0.27.0", features = ["transpiling"] } -deno_core = "0.199.0" -deno_ops = "0.77.0" -serde_v8 = "0.110.0" +deno_core = "0.200.0" deno_runtime = { version = "0.122.0", path = "./runtime" } napi_sym = { version = "0.44.0", path = "./cli/napi/sym" } diff --git a/cli/build.rs b/cli/build.rs index 9860412a1..ecf0d3cbe 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -284,7 +284,6 @@ mod ts { .expect("snapshot compression failed"), ); })), - snapshot_module_load_cb: None, with_runtime_cb: None, }); for path in output.files_loaded_during_snapshot { @@ -377,7 +376,6 @@ fn create_cli_snapshot(snapshot_path: PathBuf) -> CreateSnapshotOutput { startup_snapshot: Some(deno_runtime::js::deno_isolate_init()), extensions, compression_cb: None, - snapshot_module_load_cb: None, with_runtime_cb: None, }) } diff --git a/runtime/build.rs b/runtime/build.rs index 5b02f2202..64ef246dc 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -17,39 +17,33 @@ mod startup_snapshot { use deno_core::snapshot_util::*; use deno_core::Extension; use deno_core::ExtensionFileSource; - use deno_core::ModuleCode; + use deno_core::ExtensionFileSourceCode; use deno_http::DefaultHttpPropertyExtractor; use std::path::Path; - fn transpile_ts_for_snapshotting( - file_source: &ExtensionFileSource, - ) -> Result<ModuleCode, AnyError> { + fn maybe_transpile_source( + source: &mut ExtensionFileSource, + ) -> Result<(), AnyError> { // Always transpile `node:` built-in modules, since they might be TypeScript. - let media_type = if file_source.specifier.starts_with("node:") { + let media_type = if source.specifier.starts_with("node:") { MediaType::TypeScript } else { - MediaType::from_path(Path::new(&file_source.specifier)) + MediaType::from_path(Path::new(&source.specifier)) }; - let should_transpile = match media_type { - MediaType::JavaScript => false, - MediaType::Mjs => false, - MediaType::TypeScript => true, - _ => { - panic!( - "Unsupported media type for snapshotting {media_type:?} for file {}", - file_source.specifier - ) - } - }; - let code = file_source.load()?; - - if !should_transpile { - return Ok(code); + match media_type { + MediaType::TypeScript => {} + MediaType::JavaScript => return Ok(()), + MediaType::Mjs => return Ok(()), + _ => panic!( + "Unsupported media type for snapshotting {media_type:?} for file {}", + source.specifier + ), } + let code = source.load()?; let parsed = deno_ast::parse_module(ParseParams { - specifier: file_source.specifier.to_string(), + specifier: source.specifier.to_string(), text_info: SourceTextInfo::from_string(code.as_str().to_owned()), media_type, capture_tokens: false, @@ -62,7 +56,9 @@ mod startup_snapshot { ..Default::default() })?; - Ok(transpiled_source.text.into()) + source.code = + ExtensionFileSourceCode::Computed(transpiled_source.text.into()); + Ok(()) } #[derive(Clone)] @@ -312,7 +308,7 @@ mod startup_snapshot { // NOTE(bartlomieju): ordering is important here, keep it in sync with // `runtime/worker.rs`, `runtime/web_worker.rs` and `cli/build.rs`! let fs = std::sync::Arc::new(deno_fs::RealFs); - let extensions: Vec<Extension> = vec![ + let mut extensions: Vec<Extension> = 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(), @@ -356,13 +352,21 @@ mod startup_snapshot { runtime_main::init_ops_and_esm(), ]; + 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"), snapshot_path, startup_snapshot: None, extensions, compression_cb: None, - snapshot_module_load_cb: Some(Box::new(transpile_ts_for_snapshotting)), with_runtime_cb: None, }); for path in output.files_loaded_during_snapshot { |