1#[path = "Detect.rs"]
9pub mod Detect;
10#[path = "Bootstrap.rs"]
11pub mod Bootstrap;
12#[path = "Compile.rs"]
13pub mod Compile;
14
15pub use Detect::WorkerDetector;
16pub use Bootstrap::WorkerBootstrap;
17pub use Compile::WorkerCompiler;
18
19#[derive(Debug, Clone, Default)]
21pub struct WorkerConfig {
22 pub enabled:bool,
24 pub output_dir:String,
26 pub inline_dependencies:bool,
28 pub worker_type:WorkerType,
30 pub bootstrap_scripts:Vec<String>,
32 pub source_maps:bool,
34}
35
36impl WorkerConfig {
37 pub fn new() -> Self {
38 Self {
39 enabled:true,
40 output_dir:"out/workers".to_string(),
41 inline_dependencies:true,
42 worker_type:WorkerType::Module,
43 bootstrap_scripts:Vec::new(),
44 source_maps:true,
45 }
46 }
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
51pub enum WorkerType {
52 Classic,
54 #[default]
56 Module,
57}
58
59impl WorkerType {
60 pub fn as_str(&self) -> &'static str {
61 match self {
62 WorkerType::Classic => "classic",
63 WorkerType::Module => "module",
64 }
65 }
66}
67
68#[derive(Debug, Clone)]
70pub struct WorkerInfo {
71 pub source_path:String,
73 pub output_path:String,
75 pub name:String,
77 pub worker_type:WorkerType,
79 pub dependencies:Vec<String>,
81 pub is_shared:bool,
83}
84
85impl WorkerInfo {
86 pub fn new(source_path:impl Into<String>, worker_type:WorkerType) -> Self {
87 let source_path = source_path.into();
88 let name = std::path::Path::new(&source_path)
89 .file_stem()
90 .and_then(|s| s.to_str())
91 .unwrap_or("worker")
92 .to_string();
93
94 Self {
95 source_path:source_path.clone(),
96 output_path:source_path,
97 name,
98 worker_type,
99 dependencies:Vec::new(),
100 is_shared:false,
101 }
102 }
103}