refactor: remove snapshot_module_load_cb (#20043)

This commit is contained in:
Nayeem Rahman 2023-08-06 00:00:38 +01:00 committed by GitHub
parent 85a2b281f5
commit b96f283064
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 36 deletions

12
Cargo.lock generated
View file

@ -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",

View file

@ -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" }

View file

@ -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,
})
}

View file

@ -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 {