From 8d69b33e996272da2867964e961a89d37b7b694f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 31 Aug 2023 11:32:26 -0500 Subject: [PATCH] feat: upgrade to deno_ast 0.29 (#146) --- Cargo.lock | 77 +++++++++++++++++++------------------ Cargo.toml | 4 +- lib/Cargo.toml | 2 +- lib/lib.rs | 53 +++++++++++++------------ src/examples/builder.rs | 16 +++++--- src/testdata/emit/json.ts | 4 +- src/testdata/source/json.ts | 2 +- src/v2.rs | 11 +++++- 8 files changed, 94 insertions(+), 75 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4fff358..9c03cec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,9 +267,9 @@ dependencies = [ [[package]] name = "deno_ast" -version = "0.28.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00c93119b1c487a85603406a988a0ca9a1d0e5315404cccc5c158fb484b1f5a2" +checksum = "b041461b8b531a409fc635a5a476aee79b82f2c502d1d279c5995b6768ed944a" dependencies = [ "anyhow", "base64 0.13.1", @@ -304,11 +304,12 @@ dependencies = [ [[package]] name = "deno_graph" -version = "0.52.1" +version = "0.54.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2506f6ded4ba6722d2d7d9c1ab8ea098cc0cd72ba7d8b2c4cb37b123c000a00d" +checksum = "dcb7464fab13748a26407d0250ab3fb412a88d8b95c30b8a96aa5d49c79d4ee6" dependencies = [ "anyhow", + "async-trait", "data-url", "deno_ast", "deno_semver", @@ -395,9 +396,9 @@ dependencies = [ [[package]] name = "dprint-swc-ext" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f115ea5b6f5d0d02a25a9364f41b8c4f857452c299309dcfd29a694724d0566" +checksum = "6a0a2492465344a58a37ae119de59e81fe5a2885f2711c7b5048ef0dfa14ce42" dependencies = [ "bumpalo", "num-bigint", @@ -948,9 +949,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "5486aed0026218e61b8a01d5fbd5a0a134649abb71a0e53b7bc088529dced86e" [[package]] name = "mime" @@ -1759,9 +1760,9 @@ dependencies = [ [[package]] name = "swc_atoms" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8066e17abb484602da673e2d35138ab32ce53f26368d9c92113510e1659220b" +checksum = "9f54563d7dcba626d4acfe14ed12def7ecc28e004debe3ecd2c3ee07cc47e449" dependencies = [ "once_cell", "rustc-hash", @@ -1773,9 +1774,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.31.21" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de5823ef063f116ad281cde9700f5be6dfb182e543ce3f62c42cee1c03ffbc6b" +checksum = "39cb7fcd56655c8ae7dcf2344f0be6cbff4d9c7cb401fe3ec8e56e1de8dfe582" dependencies = [ "ast_node", "better_scoped_tls", @@ -1825,9 +1826,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.107.7" +version = "0.109.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7191c8c57af059b75a2aadc927a2608c3962d19e4d09ce8f9c3f03739ddf833" +checksum = "7bc2286cedd688a68f214faa1c19bb5cceab7c9c54d0cbe3273e4c1704e38f69" dependencies = [ "bitflags 2.4.0", "is-macro", @@ -1842,9 +1843,9 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "0.142.17" +version = "0.144.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e4e3ee8a1f0bfaf630febbe0f6a03f2c28d66d373a9bbdb3f500f6bfb536b43" +checksum = "8e62ba2c0ed1f119fc1a76542d007f1b2c12854d54dea15f5491363227debe11" dependencies = [ "memchr", "num-bigint", @@ -1874,9 +1875,9 @@ dependencies = [ [[package]] name = "swc_ecma_dep_graph" -version = "0.109.15" +version = "0.111.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1295557b5960eb97ec63fc2008be0a101d1ff7d2163a1031b3d31d3c898d5bb3" +checksum = "c5526adf6a434f145c8caf7e3a2dba554a2ad09b84467b6a62210f9ef0af0f71" dependencies = [ "swc_atoms", "swc_common", @@ -1886,9 +1887,9 @@ dependencies = [ [[package]] name = "swc_ecma_loader" -version = "0.43.23" +version = "0.44.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82f47bb1ab686f603da93a8b6e559d69b42369ab47d5dee6bdda38ae5902dc2a" +checksum = "e7d7c322462657ae27ac090a2c89f7e456c94416284a2f5ecf66c43a6a3c19d1" dependencies = [ "anyhow", "pathdiff", @@ -1899,9 +1900,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.137.15" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c0d554865a63bfa58cf1c433fa91d7d4adf40030fa8e4530e8065d0578166a" +checksum = "3eab46cb863bc5cd61535464e07e5b74d5f792fa26a27b9f6fd4c8daca9903b7" dependencies = [ "either", "num-bigint", @@ -1919,9 +1920,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.130.24" +version = "0.132.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8d8ca5dd849cea79e6a9792d725f4082ad3ade7a9541fba960c42d55ae778f2" +checksum = "01ffd4a8149052bfc1ec1832fcbe04f317846ce635a49ec438df33b06db27d26" dependencies = [ "better_scoped_tls", "bitflags 2.4.0", @@ -1942,9 +1943,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.119.24" +version = "0.121.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a09d0e350963d4fb14bf9dc31c85eb28e58a88614e779c75f49296710f9cb381" +checksum = "f4b7fee0e2c6f12456d2aefb2418f2f26529b995945d493e1dce35a5a22584fc" dependencies = [ "swc_atoms", "swc_common", @@ -1956,9 +1957,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_macros" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f59c4b6ed5d78d3ad9fc7c6f8ab4f85bba99573d31d9a2c0a712077a6b45efd2" +checksum = "8188eab297da773836ef5cf2af03ee5cca7a563e1be4b146f8141452c28cc690" dependencies = [ "pmutil", "proc-macro2", @@ -1969,9 +1970,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.164.30" +version = "0.166.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62d3a04de35f6c79d8f343822138e7313934d3530cc4e4f891a079f7e2415c1a" +checksum = "122fd9a69f464694edefbf9c59106b3c15e5cc8cb8575a97836e4fb79018e98f" dependencies = [ "either", "rustc-hash", @@ -1989,9 +1990,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.176.34" +version = "0.178.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "607017e6fbfe3229b69ffce7b47383eb9b62025ea93a50cd1cc1788d2a29a4ca" +checksum = "675b5c755b0448268830e85e59429095d3423c0ce4a850b209c6f0eeab069f63" dependencies = [ "base64 0.13.1", "dashmap", @@ -2013,9 +2014,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "0.180.33" +version = "0.182.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea349e787a62af0dcf1b8b52d507045345871571c18cb78a2f892912f7d6b753" +checksum = "4eba97b1ea71739fcf278aedad4677a3cacb52288a3f3566191b70d16a889de6" dependencies = [ "serde", "swc_atoms", @@ -2029,9 +2030,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.120.19" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb60e20e1eb9e9f7c88d99ac8659fd0561d70abd27853f550fbd907a448c878" +checksum = "11006a3398ffd4693c4d3b0a1b1a5030edbdc04228159f5301120a6178144708" dependencies = [ "indexmap 1.9.3", "num_cpus", @@ -2047,9 +2048,9 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "0.93.7" +version = "0.95.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb23a48abd9f5731b6275dbf4ea89f6e03dc60b7c8e3e1e383bb4a6c39fd7e25" +checksum = "0f628ec196e76e67892441e14eef2e423a738543d32bffdabfeec20c29582117" dependencies = [ "num-bigint", "swc_atoms", diff --git a/Cargo.toml b/Cargo.toml index e8c3745..9613e2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,8 +30,8 @@ path = "src/examples/viewer.rs" [dependencies] anyhow = "1" base64 = "0.21.0" -deno_ast = { version = "0.28.0", features = ["transpiling"] } -deno_graph = "0.52.0" +deno_ast = { version = "0.29.0", features = ["transpiling"] } +deno_graph = "0.54.0" deno_npm = "0.13.0" deno_semver = "0.4.0" futures = "0.3.26" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 873ab17..95a1981 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1" console_error_panic_hook = "0.1.7" -deno_graph = "0.52.0" +deno_graph = "0.54.0" eszip = { path = "../" } import_map = "0.15.0" js-sys = { version = "0.3.64" } diff --git a/lib/lib.rs b/lib/lib.rs index b56c2cb..fa3acbb 100644 --- a/lib/lib.rs +++ b/lib/lib.rs @@ -268,30 +268,33 @@ pub async fn build_eszip( let import_map_url: Option = serde_wasm_bindgen::from_value(import_map_url) .map_err(|e| js_sys::Error::new(&e.to_string()))?; - let (maybe_import_map, maybe_import_map_data) = - if let Some(import_map_url) = import_map_url { - let resp = - deno_graph::source::Loader::load(&mut loader, &import_map_url, false) - .await - .map_err(|e| js_sys::Error::new(&e.to_string()))? - .ok_or_else(|| { - js_sys::Error::new(&format!( - "import map not found at '{import_map_url}'" - )) - })?; - match resp { - deno_graph::source::LoadResponse::Module { - specifier, content, .. - } => { - let import_map = - import_map::parse_from_json(&specifier, &content).unwrap(); - (Some(import_map.import_map), Some((specifier, content))) - } - _ => unimplemented!(), + let (maybe_import_map, maybe_import_map_data) = if let Some(import_map_url) = + import_map_url + { + let resp = deno_graph::source::Loader::load( + &mut loader, + &import_map_url, + false, + deno_graph::source::CacheSetting::Use, + ) + .await + .map_err(|e| js_sys::Error::new(&e.to_string()))? + .ok_or_else(|| { + js_sys::Error::new(&format!("import map not found at '{import_map_url}'")) + })?; + match resp { + deno_graph::source::LoadResponse::Module { + specifier, content, .. + } => { + let import_map = + import_map::parse_from_json(&specifier, &content).unwrap(); + (Some(import_map.import_map), Some((specifier, content))) } - } else { - (None, None) - }; + _ => unimplemented!(), + } + } else { + (None, None) + }; let resolver = GraphResolver(maybe_import_map); let analyzer = deno_graph::CapturingModuleAnalyzer::default(); let mut graph = ModuleGraph::new(GraphKind::CodeOnly); @@ -340,15 +343,17 @@ impl Loader for GraphLoader { &mut self, specifier: &ModuleSpecifier, is_dynamic: bool, + cache_setting: deno_graph::source::CacheSetting, ) -> LoadFuture { if specifier.scheme() == "data" { Box::pin(std::future::ready(load_data_url(specifier))) } else { let specifier = specifier.clone(); - let result = self.0.call2( + let result = self.0.call3( &JsValue::null(), &JsValue::from(specifier.to_string()), &JsValue::from(is_dynamic), + &JsValue::from(cache_setting.as_js_str()), ); Box::pin(async move { let response = match result { diff --git a/src/examples/builder.rs b/src/examples/builder.rs index 8a6fad8..0e3049f 100644 --- a/src/examples/builder.rs +++ b/src/examples/builder.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::sync::Arc; use deno_ast::EmitOptions; +use deno_graph::source::CacheSetting; use deno_graph::BuildOptions; use deno_graph::CapturingModuleAnalyzer; use deno_graph::GraphKind; @@ -21,11 +22,15 @@ async fn main() { let mut loader = Loader; let (maybe_import_map, maybe_import_map_data) = if let Some(import_map_url) = maybe_import_map { - let resp = - deno_graph::source::Loader::load(&mut loader, &import_map_url, false) - .await - .unwrap() - .unwrap(); + let resp = deno_graph::source::Loader::load( + &mut loader, + &import_map_url, + false, + CacheSetting::Use, + ) + .await + .unwrap() + .unwrap(); match resp { deno_graph::source::LoadResponse::Module { specifier, content, .. @@ -105,6 +110,7 @@ impl deno_graph::source::Loader for Loader { &mut self, specifier: &deno_graph::ModuleSpecifier, _is_dynamic: bool, + _cache_setting: CacheSetting, ) -> deno_graph::source::LoadFuture { let specifier = specifier.clone(); diff --git a/src/testdata/emit/json.ts b/src/testdata/emit/json.ts index aa8f858..411bc50 100644 --- a/src/testdata/emit/json.ts +++ b/src/testdata/emit/json.ts @@ -1,3 +1,3 @@ -export { default as data } from "./data.json" assert { - type: "json" +export { default as data } from "./data.json" with { + type: "json" }; diff --git a/src/testdata/source/json.ts b/src/testdata/source/json.ts index b4b9c37..aa8f858 100644 --- a/src/testdata/source/json.ts +++ b/src/testdata/source/json.ts @@ -1,3 +1,3 @@ export { default as data } from "./data.json" assert { - type: "json" + type: "json" }; diff --git a/src/v2.rs b/src/v2.rs index e65ac59..4edb7b1 100644 --- a/src/v2.rs +++ b/src/v2.rs @@ -1144,6 +1144,7 @@ mod tests { use std::sync::Arc; use deno_ast::EmitOptions; + use deno_graph::source::CacheSetting; use deno_graph::source::LoadResponse; use deno_graph::BuildOptions; use deno_graph::CapturingModuleAnalyzer; @@ -1180,6 +1181,7 @@ mod tests { &mut self, specifier: &ModuleSpecifier, _is_dynamic: bool, + _cache_setting: CacheSetting, ) -> deno_graph::source::LoadFuture { match specifier.scheme() { "file" => { @@ -1234,6 +1236,7 @@ mod tests { &mut self, specifier: &ModuleSpecifier, is_dynamic: bool, + _cache_setting: deno_graph::source::CacheSetting, ) -> deno_graph::source::LoadFuture { if is_dynamic { unreachable!(); @@ -1356,7 +1359,7 @@ mod tests { let module = eszip.get_module("file:///json.ts").unwrap(); assert_eq!(module.specifier, "file:///json.ts"); let source = module.source().await.unwrap(); - assert_matches_file!(source, "./testdata/source/json.ts"); + assert_matches_file!(source, "./testdata/emit/json.ts"); let _source_map = module.source_map().await.unwrap(); assert_eq!(module.kind, ModuleKind::JavaScript); let module = eszip.get_module("file:///data.json").unwrap(); @@ -1480,7 +1483,7 @@ mod tests { let module = eszip.get_module("file:///json.ts").unwrap(); assert_eq!(module.specifier, "file:///json.ts"); let source = module.source().await.unwrap(); - assert_matches_file!(source, "./testdata/emit/json.ts"); + assert_matches_file!(source, "./testdata/source/json.ts"); let _source_map = module.source_map().await.unwrap(); assert_eq!(module.kind, ModuleKind::JavaScript); let module = eszip.get_module("file:///data.json").unwrap(); @@ -1538,6 +1541,7 @@ mod tests { &mut loader, &Url::parse("file:///import_map.json").unwrap(), false, + CacheSetting::Use, ) .await .unwrap() @@ -1612,6 +1616,7 @@ mod tests { &mut loader, &Url::parse("file:///import_map.json").unwrap(), false, + CacheSetting::Use, ) .await .unwrap() @@ -1675,6 +1680,7 @@ mod tests { &mut loader, &Url::parse("file:///deno.jsonc").unwrap(), false, + CacheSetting::Use, ) .await .unwrap() @@ -1750,6 +1756,7 @@ mod tests { &mut loader, &Url::parse("file:///deno.jsonc").unwrap(), false, + CacheSetting::Use, ) .await .unwrap()