Skip to content

Commit

Permalink
feat: eszip 2.3 - support Wasm modules (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Jan 15, 2025
1 parent 89bfaac commit 3ef2ce5
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 35 deletions.
38 changes: 34 additions & 4 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 @@ -13,7 +13,7 @@ members = ["lib"]
[workspace.dependencies]
deno_graph = { version = "0.86.3", default-features = false }
deno_ast = { version = "0.44.0", features = ["transpiling"] }
import_map = "0.20.0"
import_map = "0.21.0"
serde = "1"

[profile.release]
Expand Down Expand Up @@ -57,7 +57,7 @@ indexmap = "2"
serde = { workspace = true }
serde_json = "1"
sha2 = {version = "0.10.1", optional = true}
thiserror = "1.0.30"
thiserror = "2"
url = "2.2.2"
xxhash-rust = { version = "0.8", optional = true }

Expand Down
1 change: 1 addition & 0 deletions benches/source_hash_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ async fn build_eszip(mb: usize) -> EszipV2 {
graph.valid().unwrap();
EszipV2::from_graph(eszip::FromGraphOptions {
graph,
module_kind_resolver: Default::default(),
parser: analyzer.as_capturing_parser(),
transpile_options: TranspileOptions::default(),
emit_options: EmitOptions::default(),
Expand Down
1 change: 1 addition & 0 deletions lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ pub async fn build_eszip(
.map_err(|e| js_sys::Error::new(&e.to_string()))?;
let mut eszip = eszip::EszipV2::from_graph(eszip::FromGraphOptions {
graph,
module_kind_resolver: Default::default(),
parser: analyzer.as_capturing_parser(),
transpile_options: Default::default(),
emit_options: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions src/examples/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async fn main() {
let mut eszip = eszip::EszipV2::from_graph(eszip::FromGraphOptions {
graph,
parser: analyzer.as_capturing_parser(),
module_kind_resolver: Default::default(),
transpile_options: TranspileOptions::default(),
emit_options: EmitOptions::default(),
relative_file_base: None,
Expand Down
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

#![deny(clippy::print_stderr)]
#![deny(clippy::print_stdout)]
#![deny(clippy::unused_async)]

mod error;
pub mod v1;
pub mod v2;
Expand All @@ -14,6 +18,7 @@ use futures::io::AsyncReadExt;
use serde::Deserialize;
use serde::Serialize;
use v2::EszipV2Modules;
use v2::EszipVersion;

pub use crate::error::ParseError;
pub use crate::v1::EszipV1;
Expand Down Expand Up @@ -47,8 +52,8 @@ impl Eszip {
let mut reader = futures::io::BufReader::new(reader);
let mut magic = [0; 8];
reader.read_exact(&mut magic).await?;
if EszipV2::has_magic(&magic) {
let (eszip, fut) = EszipV2::parse_with_magic(&magic, reader).await?;
if let Some(version) = EszipVersion::from_magic(&magic) {
let (eszip, fut) = EszipV2::parse_with_version(version, reader).await?;
Ok((Eszip::V2(eszip), Box::pin(fut)))
} else {
let mut buffer = Vec::new();
Expand Down Expand Up @@ -212,6 +217,7 @@ pub enum ModuleKind {
Json = 1,
Jsonc = 2,
OpaqueData = 3,
Wasm = 4,
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expression: bytes
80,
50,
46,
50,
51,
0,
0,
0,
Expand Down
2 changes: 1 addition & 1 deletion src/snapshots/eszip__v2__tests__npm_empty_snapshot.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expression: bytes
80,
50,
46,
50,
51,
0,
0,
0,
Expand Down
2 changes: 1 addition & 1 deletion src/snapshots/eszip__v2__tests__npm_packages.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expression: bytes
80,
50,
46,
50,
51,
0,
0,
0,
Expand Down
2 changes: 1 addition & 1 deletion src/snapshots/eszip__v2__tests__opaque_data.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expression: bytes
80,
50,
46,
50,
51,
0,
0,
0,
Expand Down
Binary file added src/testdata/source/math.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions src/testdata/source/wasm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { add } from "./math.wasm";
console.log(add(1, 2));
Binary file added src/testdata/wasm.eszip2_3
Binary file not shown.
Loading

0 comments on commit 3ef2ce5

Please sign in to comment.