Skip to content

Commit

Permalink
refactor: upgrade to deno_graph 0.66 (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Feb 15, 2024
1 parent 80f3cae commit 0ea4a8b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 32 deletions.
52 changes: 32 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions js/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions rs-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion rs-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 18 additions & 6 deletions wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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<String>,
}

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) => {
Expand Down

0 comments on commit 0ea4a8b

Please sign in to comment.