diff --git a/Cargo.lock b/Cargo.lock index 3539e3b..66cea23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -254,9 +254,9 @@ dependencies = [ [[package]] name = "deno_ast" -version = "0.33.2" +version = "0.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fdafff817ae3ad89672d54cd8daebc86dc352065ccc18691605043e6b845d00" +checksum = "7f61944e781d268799bf65857e664d3c09a37590043d4b0ed10facefc9bea473" dependencies = [ "anyhow", "base64", @@ -331,9 +331,9 @@ dependencies = [ [[package]] name = "deno_graph" -version = "0.65.0" +version = "0.66.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd7e17cc32255286c37c81a44425b71c4a7e1aadb7bdf65968a31d28415fa1d0" +checksum = "8c67c7c05d70e43560b1dfa38ee385d2d0153ccd4ea16fdc6a706881fd60f3c5" dependencies = [ "anyhow", "async-trait", @@ -351,6 +351,7 @@ dependencies = [ "regex", "serde", "serde_json", + "sha2", "thiserror", "url", ] @@ -1184,6 +1185,17 @@ dependencies = [ "digest", ] +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -1296,9 +1308,9 @@ dependencies = [ [[package]] name = "swc_bundler" -version = "0.225.3" +version = "0.225.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26491762e84ae1d0a2e179fe48066072834777a1b12e8e88a7f07c8f92cc0188" +checksum = "feb8b6f3ad184a5ae21544411491bf136635237fc097d7c93ccd915449ebb2ba" dependencies = [ "anyhow", "crc", @@ -1477,9 +1489,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.137.3" +version = "0.137.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd47dd9ccb73a1f5d8d7eff9518554b752b1733b56503af090e78859abb42dd" +checksum = "803bb435fdd532d5c931f0d487e48dbc94750d26c9336d79a6f1c04c62f08d93" dependencies = [ "better_scoped_tls", "bitflags 2.4.2", @@ -1500,9 +1512,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.126.3" +version = "0.126.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb31417e0d415d7f0ff026f1e7c909427e386b7d0af9a2a78678507e4d9d79" +checksum = "486479e75907547d4c65ca6deed8faa465a2e9475cc9605be36a0e5eb609f578" dependencies = [ "swc_atoms", "swc_common", @@ -1526,9 +1538,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.198.3" +version = "0.198.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3920268ac8972b494067d0b7c088964b21d08f5d1f58d7151bd1eb7054a137b0" +checksum = "f3c6fffe4d6e3609fdd6c768cc063dbc9f5101f9be0db1168ec76ace979cf616" dependencies = [ "dashmap", "indexmap", @@ -1550,9 +1562,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.171.3" +version = "0.171.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "448c40c2a2b224cb5101cc6cdee81837c281a34f2a2aa6dd18d6d5cd8d492e60" +checksum = "e2822bc6c28bb1a96090a3b2caa28f45efbaecb333714d30868a2390eaae943f" dependencies = [ "either", "rustc-hash", @@ -1570,9 +1582,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.183.3" +version = "0.183.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2394dc3abceada246feeb709b8c4d23392973f49a24fcc59b2ee21737cb6c8" +checksum = "8984ebb8955116c426457a0c70b0aa9a08a06656e245781ff617a9cd1e289697" dependencies = [ "base64", "dashmap", @@ -1594,9 +1606,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "0.188.3" +version = "0.188.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cff231437173e041e5a3be9b8c782fd297ffcb53ed16d805f853e4a68315c45" +checksum = "a2e898fbab993abb60fb67009521908f2317f1d33f804e5b38d769f52e58572e" dependencies = [ "ryu-js", "serde", @@ -1611,9 +1623,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.127.3" +version = "0.127.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd185161161dfc65ee0d6f3044c901b766c3abb4efcd0b35c9e76c833724896" +checksum = "8ff9e77ea18468895d26bd38656885860fede2acd24d1687f64363aaf8910441" dependencies = [ "indexmap", "num_cpus", diff --git a/js/mod.ts b/js/mod.ts index c3d1b44..4e6e25d 100644 --- a/js/mod.ts +++ b/js/mod.ts @@ -41,7 +41,7 @@ import { type CacheSetting, createCache, type FetchCacher, -} from "https://deno.land/x/deno_cache@0.6.3/mod.ts"; +} from "https://deno.land/x/deno_cache@0.7.1/mod.ts"; /** The output of the {@linkcode bundle} function. */ export interface BundleEmit { @@ -195,8 +195,17 @@ export async function bundle( const { bundle: jsBundle } = await instantiate(); const result = await jsBundle( locationToUrl(root).toString(), - (specifier: string, isDynamic: boolean, cacheSetting: CacheSetting) => { - return bundleLoad!(specifier, isDynamic, cacheSetting).then((result) => { + (specifier: string, options: { + isDynamic: boolean; + cacheSetting: CacheSetting; + checksum: string | undefined; + }) => { + return bundleLoad!( + specifier, + options.isDynamic, + options.cacheSetting, + options.checksum, + ).then((result) => { if (result?.kind === "module") { if (typeof result.content === "string") { result.content = encoder.encode(result.content); diff --git a/rs-lib/Cargo.toml b/rs-lib/Cargo.toml index fb55fec..4bf23c7 100644 --- a/rs-lib/Cargo.toml +++ b/rs-lib/Cargo.toml @@ -11,8 +11,8 @@ license = "MIT" [dependencies] anyhow = { workspace = true } base64 = { workspace = true } -deno_ast = { version = "0.33.2", features = ["bundler", "codegen", "proposal", "react", "sourcemap", "transforms", "typescript", "visit", "transpiling"] } -deno_graph = { version = "0.65.0", default-features = true } +deno_ast = { version = "0.33.3", features = ["bundler", "codegen", "proposal", "react", "sourcemap", "transforms", "typescript", "visit", "transpiling"] } +deno_graph = { version = "0.66.0", default-features = true } escape8259 = "0.5.2" futures = "0.3.17" import_map = "0.18.1" diff --git a/rs-lib/src/lib.rs b/rs-lib/src/lib.rs index 7918138..7d76031 100644 --- a/rs-lib/src/lib.rs +++ b/rs-lib/src/lib.rs @@ -28,7 +28,9 @@ pub use deno_ast::ImportsNotUsedAsValues; pub use deno_ast::ModuleSpecifier; pub use deno_graph::source::CacheSetting; pub use deno_graph::source::LoadFuture; +pub use deno_graph::source::LoadOptions; pub use deno_graph::source::Loader; +pub use deno_graph::source::LoaderChecksum; pub async fn bundle( root: ModuleSpecifier, @@ -116,7 +118,14 @@ async fn get_import_map_from_input( match input { ImportMapInput::ModuleSpecifier(url) => { let response = loader - .load(url, false, CacheSetting::Use) + .load( + url, + LoadOptions { + is_dynamic: false, + cache_setting: CacheSetting::Use, + maybe_checksum: None, + }, + ) .await? .ok_or_else(|| { anyhow::anyhow!("Could not find import map {}", url) diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 30061c0..1da159f 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -3,14 +3,15 @@ use anyhow::anyhow; use deno_emit::BundleOptions; use deno_emit::BundleType; -use deno_emit::CacheSetting; use deno_emit::EmitOptions; use deno_emit::ImportMapInput; use deno_emit::ImportsNotUsedAsValues; use deno_emit::LoadFuture; +use deno_emit::LoadOptions; use deno_emit::Loader; use deno_emit::ModuleSpecifier; use deno_emit::TranspileOptions; +use serde::Serialize; use url::Url; use wasm_bindgen::prelude::*; @@ -149,15 +150,26 @@ impl Loader for JsLoader { fn load( &mut self, specifier: &ModuleSpecifier, - is_dynamic: bool, - cache_setting: CacheSetting, + options: LoadOptions, ) -> LoadFuture { + #[derive(Serialize)] + #[serde(rename_all = "camelCase")] + struct JsLoadOptions { + pub is_dynamic: bool, + pub cache_setting: &'static str, + pub checksum: Option, + } + let specifier = specifier.clone(); let this = JsValue::null(); let arg0 = JsValue::from(specifier.to_string()); - let arg1 = JsValue::from(is_dynamic); - let arg2 = JsValue::from(cache_setting.as_js_str()); - let result = self.load.call3(&this, &arg0, &arg1, &arg2); + let arg1 = serde_wasm_bindgen::to_value(&JsLoadOptions { + is_dynamic: options.is_dynamic, + cache_setting: options.cache_setting.as_js_str(), + checksum: options.maybe_checksum.map(|c| c.into_string()), + }) + .unwrap(); + let result = self.load.call2(&this, &arg0, &arg1); let f = async move { let response = match result { Ok(result) => {