Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully thread the source-compression value #761

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/cli/src/codegen/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl CodeGenBuilder {

fn build_dynamic(self) -> Result<Box<dyn CodeGen>> {
let mut dynamic_gen = Box::new(DynamicGenerator::new());
dynamic_gen.source_compression = self.source_compression;

if let Some(v) = self.provider_version {
dynamic_gen.import_namespace = String::from("javy_quickjs_provider_v");
Expand Down
21 changes: 19 additions & 2 deletions crates/cli/src/codegen/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) struct DynamicGenerator {
/// JavaScript function exports.
function_exports: Exports,
/// Whether to embed the compressed JS source in the generated module.
source_compression: bool,
pub source_compression: bool,
/// WIT options for code generation.
pub wit_opts: WitOptions,
}
Expand All @@ -58,7 +58,7 @@ impl DynamicGenerator {
/// Creates a new [`DynamicGenerator`].
pub fn new() -> Self {
Self {
source_compression: Default::default(),
source_compression: true,
import_namespace: "".into(),
function_exports: Default::default(),
wit_opts: Default::default(),
Expand Down Expand Up @@ -304,3 +304,20 @@ fn print_wat(wasm_binary: &[u8]) -> Result<()> {
fn print_wat(_wasm_binary: &[u8]) -> Result<()> {
Ok(())
}

#[cfg(test)]
mod test {
use super::DynamicGenerator;
use super::WitOptions;
use anyhow::Result;

#[test]
fn default_values() -> Result<()> {
let gen = DynamicGenerator::new();
assert!(gen.source_compression);
assert_eq!(gen.import_namespace, "");
assert_eq!(gen.wit_opts, WitOptions::default());

Ok(())
}
}
19 changes: 18 additions & 1 deletion crates/cli/src/codegen/static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl StaticGenerator {
let engine = include_bytes!(concat!(env!("OUT_DIR"), "/engine.wasm"));
Self {
engine,
source_compression: Default::default(),
source_compression: true,
function_exports: Default::default(),
wit_opts: Default::default(),
js_runtime_config,
Expand Down Expand Up @@ -201,3 +201,20 @@ fn optimize_wasm(wasm: &[u8]) -> Result<Vec<u8>> {

Ok(fs::read(&tempfile_path)?)
}

#[cfg(test)]
mod test {
use super::StaticGenerator;
use super::WitOptions;
use anyhow::Result;
use javy_config::Config;

#[test]
fn default_values() -> Result<()> {
let gen = StaticGenerator::new(Config::default());
assert!(gen.source_compression);
assert_eq!(gen.wit_opts, WitOptions::default());

Ok(())
}
}
Loading