Skip to content

Commit

Permalink
feat: initialize compiler options builder (#8857)
Browse files Browse the repository at this point in the history
feat: options init
  • Loading branch information
h-a-n-a authored Dec 27, 2024
1 parent 3f2a390 commit a3a14f9
Show file tree
Hide file tree
Showing 8 changed files with 1,906 additions and 7 deletions.
1,383 changes: 1,383 additions & 0 deletions crates/rspack_core/src/options/compiler_options_builder.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/rspack_core/src/options/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct EntryDescription {
pub public_path: Option<PublicPath>,
pub base_uri: Option<String>,
pub filename: Option<Filename>,
pub depend_on: Option<Vec<String>>,
}

#[derive(Debug, Default, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/options/experiments/cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cache::persistent::PersistentCacheOptions;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum CacheOptions {
Disabled,
Memory,
Expand Down
6 changes: 6 additions & 0 deletions crates/rspack_core/src/options/filename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ impl<F> FromStr for Filename<F> {
}
}

impl<F> From<&str> for Filename<F> {
fn from(value: &str) -> Self {
Filename::from_str(value).expect("infallible")
}
}

#[inline]
fn hash_len(hash: &str, len: Option<usize>) -> usize {
let hash_len = hash.len();
Expand Down
4 changes: 4 additions & 0 deletions crates/rspack_core/src/options/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod compiler_options;
mod compiler_options_builder;

pub use compiler_options::*;
pub use compiler_options_builder::*;
mod entry;
pub use entry::*;
mod optimizations;
Expand Down Expand Up @@ -31,3 +33,5 @@ mod filename;
pub use filename::*;
mod clean_options;
pub use clean_options::*;
mod target;
pub use target::*;
54 changes: 49 additions & 5 deletions crates/rspack_core/src/options/module.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{
fmt::{self, Debug},
ops::{Deref, DerefMut},
str::FromStr,
sync::Arc,
};

Expand All @@ -16,9 +18,23 @@ use tokio::sync::OnceCell;

use crate::{Compilation, Filename, Module, ModuleType, PublicPath, Resolve};

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ParserOptionsMap(HashMap<String, ParserOptions>);

impl Deref for ParserOptionsMap {
type Target = HashMap<String, ParserOptions>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for ParserOptionsMap {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl FromIterator<(String, ParserOptions)> for ParserOptionsMap {
fn from_iter<I: IntoIterator<Item = (String, ParserOptions)>>(i: I) -> Self {
Self(HashMap::from_iter(i))
Expand Down Expand Up @@ -230,7 +246,7 @@ impl From<&str> for OverrideStrict {
}

#[cacheable]
#[derive(Debug, Clone, MergeFrom)]
#[derive(Debug, Clone, MergeFrom, Default)]
pub struct JavascriptParserOptions {
pub dynamic_import_mode: Option<DynamicImportMode>,
pub dynamic_import_preload: Option<JavascriptParserOrder>,
Expand Down Expand Up @@ -296,9 +312,23 @@ pub struct JsonParserOptions {
pub exports_depth: Option<u32>,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct GeneratorOptionsMap(HashMap<String, GeneratorOptions>);

impl Deref for GeneratorOptionsMap {
type Target = HashMap<String, GeneratorOptions>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for GeneratorOptionsMap {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl FromIterator<(String, GeneratorOptions)> for GeneratorOptionsMap {
fn from_iter<I: IntoIterator<Item = (String, GeneratorOptions)>>(i: I) -> Self {
Self(HashMap::from_iter(i))
Expand Down Expand Up @@ -515,6 +545,14 @@ impl From<String> for LocalIdentName {
}
}

impl From<&str> for LocalIdentName {
fn from(value: &str) -> Self {
Self {
template: crate::FilenameTemplate::from_str(value).expect("should be infalliable"),
}
}
}

#[cacheable]
#[derive(Debug, Clone, Copy)]
struct ExportsConventionFlags(u8);
Expand Down Expand Up @@ -688,6 +726,12 @@ impl RuleSetConditionWithEmpty {
}
}

impl From<RuleSetCondition> for RuleSetConditionWithEmpty {
fn from(condition: RuleSetCondition) -> Self {
Self::new(condition)
}
}

#[derive(Debug, Default)]
pub struct RuleSetLogicalConditions {
pub and: Option<Vec<RuleSetCondition>>,
Expand Down Expand Up @@ -755,7 +799,7 @@ pub struct ModuleRuleUseLoader {
pub type FnUse =
Box<dyn Fn(FuncUseCtx) -> BoxFuture<'static, Result<Vec<ModuleRuleUseLoader>>> + Sync + Send>;

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ModuleRule {
/// A conditional match matching an absolute path + query + fragment.
/// Note:
Expand Down Expand Up @@ -783,7 +827,7 @@ pub struct ModuleRule {
pub effect: ModuleRuleEffect,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ModuleRuleEffect {
pub side_effects: Option<bool>,
/// The `ModuleType` to use for the matched resource.
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/options/optimizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl From<&str> for MangleExportsOption {
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Optimization {
pub remove_available_modules: bool,
pub side_effects: SideEffectOption,
Expand Down
Loading

0 comments on commit a3a14f9

Please sign in to comment.