Skip to content

Commit

Permalink
chore(none): options
Browse files Browse the repository at this point in the history
  • Loading branch information
CCherry07 committed Oct 29, 2024
1 parent aebd5ee commit fabf3fb
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions rust-plugins/worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod cache;
use std::{
collections::{HashMap, HashSet},
path::Path,
sync::Arc,
};

use base64::{engine::general_purpose, Engine};
Expand All @@ -16,12 +17,15 @@ use farmfe_core::{
persistent_cache::PersistentCacheConfig,
Config, ModuleFormat, OutputConfig, TargetEnv,
},
context::EmitFileParams,
context::{CompilationContext, EmitFileParams},
deserialize,
module::ModuleType,
plugin::{Plugin, PluginLoadHookResult},
resource::{Resource, ResourceType},
resource::{Resource, ResourceOrigin, ResourceType},
rkyv::Deserialize,
serde,
serde_json::{self, to_value, Map, Value},
serialize,
};
use farmfe_macro_plugin::farm_plugin;
use farmfe_toolkit::fs::transform_output_filename;
Expand Down Expand Up @@ -359,4 +363,47 @@ impl Plugin for FarmfePluginWorker {
}
return Ok(None);
}

fn plugin_cache_loaded(
&self,
cache: &Vec<u8>,
context: &Arc<CompilationContext>,
) -> farmfe_core::error::Result<Option<()>> {
let cached_static_assets = deserialize!(cache, CachedStaticAssets);

for asset in cached_static_assets.list {
if let ResourceOrigin::Module(m) = asset.origin {
context.emit_file(EmitFileParams {
resolved_path: m.to_string(),
name: asset.name,
content: asset.bytes,
resource_type: asset.resource_type,
});
}
}

Ok(Some(()))
}
fn write_plugin_cache(
&self,
context: &Arc<CompilationContext>,
) -> farmfe_core::error::Result<Option<Vec<u8>>> {
let mut list = vec![];
let resources_map = context.resources_map.lock();
for (_, resource) in resources_map.iter() {
if let ResourceOrigin::Module(m) = &resource.origin {
if context.cache_manager.module_cache.has_cache(m) {
list.push(resource.clone());
}
}
}

if !list.is_empty() {
let cached_static_assets = CachedStaticAssets { list };
Ok(Some(serialize!(&cached_static_assets)))
} else {
Ok(None)
}
}

}

0 comments on commit fabf3fb

Please sign in to comment.