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

V3: Removed indirection from asset graph #298

Merged
merged 1 commit into from
Jan 9, 2025
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
33 changes: 19 additions & 14 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,14 @@ 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 {
alshdavid marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -185,25 +189,26 @@ mod tests {
rpc(),
)?;

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

atlaspack.commit_assets(
&assets
.iter()
.enumerate()
.map(|(idx, asset)| AssetNode {
let assets_names = ["foo", "bar", "baz"];
let assets = assets_names
.iter()
.enumerate()
.map(|(idx, asset)| {
AssetGraphNode::Asset(AssetNode {
asset: Asset {
id: idx.to_string(),
code: Code::from(asset.to_string()),
..Asset::default()
},
requested_symbols: HashSet::new(),
})
.collect::<Vec<AssetNode>>(),
)?;
})
.collect::<Vec<AssetGraphNode>>();

atlaspack.commit_assets(assets.iter().collect())?;

let txn = db.environment().read_txn()?;
for (idx, asset) in assets.iter().enumerate() {
for (idx, asset) in assets_names.iter().enumerate() {
let entry = db.get(&txn, &idx.to_string())?;
assert_eq!(entry, Some(asset.to_string().into()));
}
Expand Down
Loading
Loading