Repository navigation
Expand file tree
/
Copy pathlib.rs
More file actions
83 lines (72 loc) · 2.56 KB
/
Copy pathlib.rs
File metadata and controls
83 lines (72 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use std::sync::Arc;
pub use analyze_module_graph::module_group_graph_from_entries;
pub use analyze_module_graph::module_group_graph_from_module_graph;
use farmfe_core::{
config::Config,
context::CompilationContext,
module::{ModuleId, module_graph::ModuleGraph, module_group::ModuleGroupGraph},
plugin::{Plugin, PluginHookContext},
resource::resource_pot::ResourcePot,
};
use generate_module_buckets::{generate_module_buckets_map, group_module_buckets_by_module_group};
use generate_resource_pots::generate_resource_pots;
// mod module_bucket;
mod analyze_module_graph;
mod generate_module_buckets;
mod generate_module_pots;
mod generate_resource_pots;
mod merge_module_pots;
mod module_bucket;
mod module_pot;
mod utils;
/// Partial Bundling implementation for Farm.
/// See https://github.com/farm-fe/rfcs/pull/9
pub struct FarmPluginPartialBundling {}
impl Plugin for FarmPluginPartialBundling {
fn name(&self) -> &str {
"FarmPluginPartialBundling"
}
fn priority(&self) -> i32 {
99
}
fn analyze_module_graph(
&self,
module_graph: &mut ModuleGraph,
_context: &Arc<CompilationContext>,
_hook_context: &PluginHookContext,
) -> farmfe_core::error::Result<Option<ModuleGroupGraph>> {
let module_group_graph = module_group_graph_from_module_graph(module_graph);
Ok(Some(module_group_graph))
}
/// The partial bundling algorithm's result should not be related to the order of the module group.
/// Whatever the order of the module group is, the result should be the same.
/// See https://github.com/farm-fe/rfcs/blob/main/rfcs/003-partial-bundling/rfc.md for more design details.
fn partial_bundling(
&self,
modules: &Vec<ModuleId>,
context: &Arc<CompilationContext>,
_hook_context: &PluginHookContext,
) -> farmfe_core::error::Result<Option<Vec<ResourcePot>>> {
// 1. get module group graph and module graph
let module_graph = context.module_graph.read();
let module_group_graph = context.module_group_graph.read();
// 2. generate module buckets and group by module group
let module_buckets_map = generate_module_buckets_map(modules, &module_graph);
let module_group_buckets =
group_module_buckets_by_module_group(&module_buckets_map, &module_group_graph, &module_graph);
// 3. generate resource pots
let resource_pots = generate_resource_pots(
module_group_buckets,
module_buckets_map,
&module_graph,
&module_group_graph,
&context.config,
);
Ok(Some(resource_pots))
}
}
impl FarmPluginPartialBundling {
pub fn new(_: &Config) -> Self {
Self {}
}
}