Skip to content

Commit

Permalink
feat: upgrade to deno_ast 0.29 (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Aug 31, 2023
1 parent 706d72a commit 8d69b33
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 75 deletions.
77 changes: 39 additions & 38 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
53 changes: 29 additions & 24 deletions lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,30 +268,33 @@ pub async fn build_eszip(
let import_map_url: Option<Url> =
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);
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 11 additions & 5 deletions src/examples/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, ..
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/testdata/emit/json.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default as data } from "./data.json" assert {
type: "json"
export { default as data } from "./data.json" with {
type: "json"
};
2 changes: 1 addition & 1 deletion src/testdata/source/json.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default as data } from "./data.json" assert {
type: "json"
type: "json"
};
Loading

0 comments on commit 8d69b33

Please sign in to comment.