Skip to content

Commit

Permalink
Add brotli and zstd support
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Dec 1, 2023
1 parent 7f45d84 commit 063ee29
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 29 deletions.
50 changes: 25 additions & 25 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,43 @@ rust-version = { workspace = true }
[[bin]]
path = "src/main.rs"
name = "glory"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.0", features = ["derive"] }
serde = { workspace = true, features = ["derive"] }
ansi_term = "0.12"
anyhow = { workspace = true }
log = "0.4"
async-trait = "0.1.72"
brotli = { version = "3.4", features = ["default"] }
bytes = "1.4"
camino = "1.1"
cargo_metadata = { version = "0.18", features = ["builder"] }
clap = { version = "4.0", features = ["derive"] }
derive_more = "0.99"
dirs = "5.0"
dotenvy = "0.15"
dunce = "1.0"
flate2 = "1.0"
flexi_logger = "0.27"
# glory-hot-reload = { git = "https://github.com/glory-rs/glory", version = "0.4.8" }
glory-hot-reload = { workspace = true }
itertools = "0.11"
lightningcss = { version = "1.0.0-alpha.51", features = ["browserslist"] }
salvo = { workspace = true, features = ["websocket"] }
tokio = { version = "1.4", default-features = false, features = ["full"] }
log = "0.4"
# not using notify 5.0 because it uses Crossbeam which has an issue with tokio
notify = "4"
once_cell ={ workspace = true }
which = "5.0"
cargo_metadata = { version = "0.18", features = ["builder"] }
reqwest = { version = "0.11", features = ["blocking", "__tls", "default-tls", "native-tls-crate", "json"], default-features = false }
salvo = { workspace = true, features = ["websocket"] }
seahash = "4.1"
semver = "1.0.18"
serde = { workspace = true, features = ["derive"] }
serde_json = "1.0"
tar = "0.4"
tokio = { version = "1.4", default-features = false, features = ["full"] }
wasm-bindgen-cli-support = "0.2"
ansi_term = "0.12"

seahash = "4.1"
reqwest = { version = "0.11", features = ["blocking", "__tls", "default-tls", "native-tls-crate", "json"], default-features = false }
dirs = "5.0"
camino = "1.1"
dotenvy = "0.15"
itertools = "0.11"
derive_more = "0.99"
flate2 = "1.0"
which = "5.0"
zip = { version = "0.6", default-features = false, features = ["deflate"] }
tar = "0.4"
dunce = "1.0"
bytes = "1.4"
# glory-hot-reload = { git = "https://github.com/glory-rs/glory", version = "0.4.8" }
glory-hot-reload = { workspace = true }
semver = "1.0.18"
async-trait = "0.1.72"
zstd = { version = "0.13", features = ["default"] }

[dev-dependencies]
insta = { version = "1.31.0", features = ["yaml"] }
Expand Down
26 changes: 22 additions & 4 deletions crates/cli/src/compile/front.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use std::sync::Arc;

use brotli::CompressorWriter;
use camino::{Utf8Path, Utf8PathBuf};
use tokio::process::Child;
use tokio::{process::Command, sync::broadcast, task::JoinHandle};
use wasm_bindgen_cli_support::Bindgen;

use super::ChangeSet;
use crate::config::Project;
use crate::ext::fs;
Expand All @@ -14,10 +22,6 @@ use crate::{
},
logger::GRAY,
};
use camino::{Utf8Path, Utf8PathBuf};
use tokio::process::Child;
use tokio::{process::Command, sync::broadcast, task::JoinHandle};
use wasm_bindgen_cli_support::Bindgen;

pub async fn front(proj: &Arc<Project>, changes: &ChangeSet) -> JoinHandle<Result<Outcome<Product>>> {
let proj = proj.clone();
Expand Down Expand Up @@ -100,6 +104,20 @@ async fn bindgen(proj: &Project) -> Result<Outcome<Product>> {
CommandResult::Failure(_) => return Ok(Outcome::Failed),
_ => {}
}
let data = fs::read(&wasm_file.dest).await?;

let br_file = File::create(format!("{}.br", wasm_file.dest.as_str()))?;
let mut br_writer = CompressorWriter::new(
br_file,
32 * 1024, // 32 KiB buffer
11, // BROTLI_PARAM_QUALITY
22, // BROTLI_PARAM_LGWIN
);
br_writer.write_all(&data)?;

let zstd_data = zstd::encode_all(&*data, 21)?;
let mut zstd_file = File::create(format!("{}.br", wasm_file.dest.as_str()))?;
zstd_file.write_all(&zstd_data)?;
}

let mut js_changed = false;
Expand Down

0 comments on commit 063ee29

Please sign in to comment.