1pub mod detect;
9pub mod bootstrap;
10pub mod compile;
11
12pub use detect::WorkerDetector;
13pub use bootstrap::WorkerBootstrap;
14pub use compile::WorkerCompiler;
15
16#[derive(Debug, Clone, Default)]
18pub struct WorkerConfig {
19 pub enabled:bool,
21 pub output_dir:String,
23 pub inline_dependencies:bool,
25 pub worker_type:WorkerType,
27 pub bootstrap_scripts:Vec<String>,
29 pub source_maps:bool,
31}
32
33impl WorkerConfig {
34 pub fn new() -> Self {
35 Self {
36 enabled:true,
37 output_dir:"out/workers".to_string(),
38 inline_dependencies:true,
39 worker_type:WorkerType::Module,
40 bootstrap_scripts:Vec::new(),
41 source_maps:true,
42 }
43 }
44}
45
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
48pub enum WorkerType {
49 Classic,
51 #[default]
53 Module,
54}
55
56impl WorkerType {
57 pub fn as_str(&self) -> &'static str {
58 match self {
59 WorkerType::Classic => "classic",
60 WorkerType::Module => "module",
61 }
62 }
63}
64
65#[derive(Debug, Clone)]
67pub struct WorkerInfo {
68 pub source_path:String,
70 pub output_path:String,
72 pub name:String,
74 pub worker_type:WorkerType,
76 pub dependencies:Vec<String>,
78 pub is_shared:bool,
80}
81
82impl WorkerInfo {
83 pub fn new(source_path:impl Into<String>, worker_type:WorkerType) -> Self {
84 let source_path = source_path.into();
85 let name = std::path::Path::new(&source_path)
86 .file_stem()
87 .and_then(|s| s.to_str())
88 .unwrap_or("worker")
89 .to_string();
90
91 Self {
92 source_path:source_path.clone(),
93 output_path:source_path,
94 name,
95 worker_type,
96 dependencies:Vec::new(),
97 is_shared:false,
98 }
99 }
100}