Skip to content

Commit 7e9e0e6

Browse files
authored
V3: Removed indirection from asset graph (#298)
1 parent fabfbc7 commit 7e9e0e6

File tree

8 files changed

+977
-821
lines changed

8 files changed

+977
-821
lines changed

crates/atlaspack/src/atlaspack.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::path::PathBuf;
22
use std::sync::Arc;
33

44
use atlaspack_config::atlaspack_rc_config_loader::{AtlaspackRcConfigLoader, LoadConfigOptions};
5-
use atlaspack_core::asset_graph::{AssetGraph, AssetNode};
5+
use atlaspack_core::asset_graph::{AssetGraph, AssetGraphNode, AssetNode};
66
use atlaspack_core::config_loader::ConfigLoader;
77
use atlaspack_core::plugin::{PluginContext, PluginLogger, PluginOptions};
88
use atlaspack_core::types::AtlaspackOptions;
@@ -128,7 +128,7 @@ impl Atlaspack {
128128

129129
let asset_graph = match request_result {
130130
RequestResult::AssetGraph(result) => {
131-
self.commit_assets(result.graph.assets.as_slice())?;
131+
self.commit_assets(result.graph.nodes().collect())?;
132132

133133
result.graph
134134
}
@@ -139,10 +139,14 @@ impl Atlaspack {
139139
})
140140
}
141141

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

145-
for AssetNode { asset, .. } in assets.iter() {
145+
for asset_node in assets {
146+
let AssetGraphNode::Asset(AssetNode { asset, .. }) = asset_node else {
147+
continue;
148+
};
149+
146150
self.db.put(&mut txn, &asset.id, asset.code.bytes())?;
147151
if let Some(map) = &asset.map {
148152
// TODO: For some reason to_buffer strips data when rkyv was upgraded, so now we use json
@@ -185,25 +189,26 @@ mod tests {
185189
rpc(),
186190
)?;
187191

188-
let assets = ["foo", "bar", "baz"];
189-
190-
atlaspack.commit_assets(
191-
&assets
192-
.iter()
193-
.enumerate()
194-
.map(|(idx, asset)| AssetNode {
192+
let assets_names = ["foo", "bar", "baz"];
193+
let assets = assets_names
194+
.iter()
195+
.enumerate()
196+
.map(|(idx, asset)| {
197+
AssetGraphNode::Asset(AssetNode {
195198
asset: Asset {
196199
id: idx.to_string(),
197200
code: Code::from(asset.to_string()),
198201
..Asset::default()
199202
},
200203
requested_symbols: HashSet::new(),
201204
})
202-
.collect::<Vec<AssetNode>>(),
203-
)?;
205+
})
206+
.collect::<Vec<AssetGraphNode>>();
207+
208+
atlaspack.commit_assets(assets.iter().collect())?;
204209

205210
let txn = db.environment().read_txn()?;
206-
for (idx, asset) in assets.iter().enumerate() {
211+
for (idx, asset) in assets_names.iter().enumerate() {
207212
let entry = db.get(&txn, &idx.to_string())?;
208213
assert_eq!(entry, Some(asset.to_string().into()));
209214
}

0 commit comments

Comments
 (0)