Skip to content

Commit

Permalink
packager
Browse files Browse the repository at this point in the history
  • Loading branch information
alshdavid committed Feb 28, 2024
1 parent 4858510 commit f036c9d
Show file tree
Hide file tree
Showing 18 changed files with 759 additions and 145 deletions.
22 changes: 18 additions & 4 deletions crates/mach/src/bundling/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ pub fn bundle(
) -> Result<(), String> {
let mut css_bundle = Bundle::new(NO_ASSET.as_path(), "css");

let mut entries: Vec<(PathBuf, Option<String>)> = asset_graph
let mut entries: Vec<(PathBuf, bool, Option<String>)> = asset_graph
.get_dependencies(&ENTRY_ASSET)
.expect("no entry assets")
.iter()
.map(|x| (x.1.clone(), None))
.map(|x| (x.1.clone(), false, None))
.collect();

while let Some((entry_asset_id, from_bundle)) = entries.pop() {
while let Some((entry_asset_id, is_lazy, from_bundle)) = entries.pop() {
let mut bundle = Bundle::new(&entry_asset_id, "");

if let Some(from_dependency_id) = from_bundle {
bundle_graph.insert(from_dependency_id.clone(), bundle.id.clone());
} else {
bundle.is_entry = true;
}

if is_lazy {
bundle.is_lazy = true
}

let mut q = Vec::<PathBuf>::from([entry_asset_id.clone()]);
Expand All @@ -46,13 +52,21 @@ pub fn bundle(
if current_asset.kind == "js" {
bundle.assets.insert(asset_id.clone());
bundle.kind = "js".to_string();

if bundle.output == "" {
bundle.output = format!("{}.{}.js", bundle.name, bundle.id);
}
}

if current_asset.kind == "css" {
css_bundle.assets.insert(asset_id.clone());
if css_bundle.entry_asset == *NO_ASSET {
css_bundle.update_entry(&asset_id);
}

if bundle.output == "" {
bundle.output = format!("{}.{}.css", bundle.name, bundle.id);
}
}

if current_asset.kind == "html" {
Expand All @@ -76,7 +90,7 @@ pub fn bundle(
q.push(asset_id.clone());
}
public::DependencyPriority::Lazy => {
entries.push((asset_id.clone(), Some(dependency_id.clone())));
entries.push((asset_id.clone(), true, Some(dependency_id.clone())));
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/mach/src/emit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ pub fn emit(
public::PackageType::JavaScript((module, cm)) => {
let bundle = bundles.iter().find(|x| x.id == *bundle_id).unwrap();
let rendered = render_module(&module, cm.clone());
println!("{} {} {}", bundle.name, bundle.id, rendered);
fs::write(
config
.dist_dir
.join(format!("{}.{}.js", bundle.name, bundle.id)),
.join(&bundle.output),
rendered,
)
.unwrap();
Expand Down
86 changes: 0 additions & 86 deletions crates/mach/src/packaging/js_runtime.rs

This file was deleted.

Loading

0 comments on commit f036c9d

Please sign in to comment.