Skip to content

Commit

Permalink
removed indirection from asset graph
Browse files Browse the repository at this point in the history
  • Loading branch information
alshdavid committed Jan 2, 2025
1 parent 249e25c commit 77bac3d
Show file tree
Hide file tree
Showing 8 changed files with 1,048 additions and 978 deletions.
40 changes: 22 additions & 18 deletions crates/atlaspack/src/atlaspack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;
use std::sync::Arc;

use atlaspack_config::atlaspack_rc_config_loader::{AtlaspackRcConfigLoader, LoadConfigOptions};
use atlaspack_core::asset_graph::{AssetGraph, AssetNode};
use atlaspack_core::asset_graph::{AssetGraph, AssetGraphNode, AssetNode};
use atlaspack_core::config_loader::ConfigLoader;
use atlaspack_core::plugin::{PluginContext, PluginLogger, PluginOptions};
use atlaspack_core::types::AtlaspackOptions;
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Atlaspack {

let asset_graph = match request_result {
RequestResult::AssetGraph(result) => {
self.commit_assets(result.graph.assets.as_slice())?;
self.commit_assets(result.graph.nodes().collect())?;

result.graph
}
Expand All @@ -139,10 +139,13 @@ impl Atlaspack {
})
}

fn commit_assets(&self, assets: &[AssetNode]) -> anyhow::Result<()> {
fn commit_assets(&self, assets: Vec<&AssetGraphNode>) -> anyhow::Result<()> {
let mut txn = self.db.environment().write_txn()?;

for AssetNode { asset, .. } in assets.iter() {
for asset_node in assets.iter() {
let AssetGraphNode::Asset(AssetNode { asset, .. }) = asset_node else {
continue;
};
self.db.put(&mut txn, &asset.id, asset.code.bytes())?;
if let Some(map) = &asset.map {
// TODO: For some reason to_buffer strips data when rkyv was upgraded, so now we use json
Expand Down Expand Up @@ -187,20 +190,21 @@ mod tests {

let assets = vec!["foo", "bar", "baz"];

atlaspack.commit_assets(
&assets
.iter()
.enumerate()
.map(|(idx, asset)| AssetNode {
asset: Asset {
id: idx.to_string(),
code: Code::from(asset.to_string()),
..Asset::default()
},
requested_symbols: HashSet::new(),
})
.collect::<Vec<AssetNode>>(),
)?;
todo!();
// atlaspack.commit_assets(
// &assets
// .iter()
// .enumerate()
// .map(|(idx, asset)| AssetNode {
// asset: Asset {
// id: idx.to_string(),
// code: Code::from(asset.to_string()),
// ..Asset::default()
// },
// requested_symbols: HashSet::new(),
// })
// .collect::<Vec<AssetNode>>(),
// )?;

let txn = db.environment().read_txn()?;
for (idx, asset) in assets.iter().enumerate() {
Expand Down
Loading

0 comments on commit 77bac3d

Please sign in to comment.