1#[path = "Detect.rs"]
9pub mod Detect;
10
11#[path = "Bootstrap.rs"]
12pub mod Bootstrap;
13
14#[path = "Compile.rs"]
15pub mod Compile;
16
17pub use Detect::WorkerDetector;
18pub use Bootstrap::WorkerBootstrap;
19pub use Compile::WorkerCompiler;
20
21#[derive(Debug, Clone, Default)]
23pub struct WorkerConfig {
24 pub enabled:bool,
26
27 pub output_dir:String,
29
30 pub inline_dependencies:bool,
32
33 pub worker_type:WorkerType,
35
36 pub bootstrap_scripts:Vec<String>,
38
39 pub source_maps:bool,
41}
42
43impl WorkerConfig {
44 pub fn new() -> Self {
45 Self {
46 enabled:true,
47
48 output_dir:"out/workers".to_string(),
49
50 inline_dependencies:true,
51
52 worker_type:WorkerType::Module,
53
54 bootstrap_scripts:Vec::new(),
55
56 source_maps:true,
57 }
58 }
59}
60
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
63pub enum WorkerType {
64 Classic,
66
67 #[default]
69 Module,
70}
71
72impl WorkerType {
73 pub fn as_str(&self) -> &'static str {
74 match self {
75 WorkerType::Classic => "classic",
76
77 WorkerType::Module => "module",
78 }
79 }
80}
81
82#[derive(Debug, Clone)]
84pub struct WorkerInfo {
85 pub source_path:String,
87
88 pub output_path:String,
90
91 pub name:String,
93
94 pub worker_type:WorkerType,
96
97 pub dependencies:Vec<String>,
99
100 pub is_shared:bool,
102}
103
104impl WorkerInfo {
105 pub fn new(source_path:impl Into<String>, worker_type:WorkerType) -> Self {
106 let source_path = source_path.into();
107
108 let name = std::path::Path::new(&source_path)
109 .file_stem()
110 .and_then(|s| s.to_str())
111 .unwrap_or("worker")
112 .to_string();
113
114 Self {
115 source_path:source_path.clone(),
116
117 output_path:source_path,
118
119 name,
120
121 worker_type,
122
123 dependencies:Vec::new(),
124
125 is_shared:false,
126 }
127 }
128}