Skip to content

Commit c71170a

Browse files
authored
Merge pull request #229 from supabase/eszip-extractor
Feat: Eszip extractor
2 parents ad98744 + 2fbae0c commit c71170a

File tree

21 files changed

+210
-42
lines changed

21 files changed

+210
-42
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ deno_core = { version = "0.222.0" }
2727
deno_console = { version = "0.121.0" }
2828
deno_crypto = { version = "0.135.0" }
2929
deno_fetch = { version = "0.145.0" }
30-
deno_fs = "0.31.0"
30+
deno_fs = { version = "0.31.0", features = ["sync_fs"] }
3131
deno_config = "=0.3.1"
3232
deno_io = "0.31.0"
3333
deno_graph = "=0.55.0"

crates/base/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ anyhow = { workspace = true }
1717
bytes = { version = "1.2.1" }
1818
cityhash = { version = "0.1.1" }
1919
deno_ast = { workspace = true }
20-
deno_fs = { workspace = true, features = ["sync_fs"] }
20+
deno_fs.workspace = true
2121
deno_io = { workspace = true }
2222
deno_core = { workspace = true }
2323
deno_console = { workspace = true }
@@ -69,7 +69,7 @@ sb_node = { version = "0.1.0", path = "../node" }
6969
anyhow = { workspace = true }
7070
bytes = { version = "1.2.1" }
7171
deno_ast = { workspace = true }
72-
deno_fs = { workspace = true, features = ["sync_fs"] }
72+
deno_fs.workspace = true
7373
deno_io = { workspace = true }
7474
deno_core = { workspace = true }
7575
deno_console = { workspace = true }

crates/base/src/rt_worker/implementation/default_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tokio::sync::oneshot::Receiver;
99

1010
impl WorkerHandler for Worker {
1111
fn handle_error(&self, error: Error) -> Result<WorkerEvents, Error> {
12-
println!("{}", error);
12+
log::error!("{}", error);
1313
Ok(WorkerEvents::BootFailure(BootFailureEvent {
1414
msg: error.to_string(),
1515
}))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const numbers = {
2+
"Uno": 1,
3+
"Dos": 2
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const hello = "";
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import isEven from "npm:is-even";
22
import { serve } from "https://deno.land/[email protected]/http/server.ts"
3+
import { hello } from "./hello.js";
4+
import { numbers } from "./folder1/folder2/numbers.ts"
35

46
serve(async (req: Request) => {
57
return new Response(
6-
JSON.stringify({ is_even: isEven(10) }),
8+
JSON.stringify({ is_even: isEven(10), hello, numbers }),
79
{ status: 200, headers: { "Content-Type": "application/json" } },
810
)
911
})

crates/base/tests/user_worker_tests.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@ async fn test_user_imports_npm() {
7171

7272
let body_bytes = hyper::body::to_bytes(res.into_body()).await.unwrap();
7373

74-
assert_eq!(body_bytes, r#"{"is_even":true}"#);
74+
assert_eq!(
75+
body_bytes,
76+
r#"{"is_even":true,"hello":"","numbers":{"Uno":1,"Dos":2}}"#
77+
);
7578
}

crates/cli/src/main.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use clap::builder::FalseyValueParser;
77
use clap::{arg, crate_version, value_parser, ArgAction, Command};
88
use deno_core::url::Url;
99
use sb_graph::emitter::EmitterFactory;
10-
use sb_graph::generate_binary_eszip;
1110
use sb_graph::import_map::load_import_map;
11+
use sb_graph::{extract_from_file, generate_binary_eszip};
1212
use std::fs::File;
1313
use std::io::Write;
1414
use std::path::PathBuf;
@@ -58,7 +58,12 @@ fn cli() -> Command {
5858
.arg(arg!(--"output" <DIR> "Path to output eszip file").default_value("bin.eszip"))
5959
.arg(arg!(--"entrypoint" <Path> "Path to entrypoint to bundle as an eszip").required(true))
6060
.arg(arg!(--"import-map" <Path> "Path to import map file"))
61-
)
61+
).subcommand(
62+
Command::new("unbundle")
63+
.about("Unbundles an .eszip file into the specified directory")
64+
.arg(arg!(--"output" <DIR> "Path to extract the ESZIP content").default_value("./"))
65+
.arg(arg!(--"eszip" <DIR> "Path of eszip to extract").required(true))
66+
)
6267
}
6368

6469
//async fn exit_with_code(result: Result<(), Error>) {
@@ -167,6 +172,20 @@ fn main() -> Result<(), anyhow::Error> {
167172
let mut file = File::create(output_path.as_str()).unwrap();
168173
file.write_all(&bin).unwrap();
169174
}
175+
Some(("unbundle", sub_matches)) => {
176+
let output_path = sub_matches.get_one::<String>("output").cloned().unwrap();
177+
let eszip_path = sub_matches.get_one::<String>("eszip").cloned().unwrap();
178+
179+
let output_path = PathBuf::from(output_path.as_str());
180+
let eszip_path = PathBuf::from(eszip_path.as_str());
181+
182+
extract_from_file(eszip_path, output_path.clone()).await;
183+
184+
println!(
185+
"Eszip extracted successfully inside path {}",
186+
output_path.to_str().unwrap()
187+
);
188+
}
170189
_ => {
171190
// unrecognized command
172191
}

crates/cpu_timer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl CPUTimer {
7777

7878
#[cfg(not(target_os = "linux"))]
7979
pub fn start(_: u64, _: u64, _: CPUAlarmVal) -> Result<Self, Error> {
80-
println!("CPU timer: not enabled (need Linux)");
80+
log::error!("CPU timer: not enabled (need Linux)");
8181
Ok(Self {})
8282
}
8383
}

0 commit comments

Comments
 (0)