diff --git a/Cargo.lock b/Cargo.lock index c529e02134d..5966a5abf52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3685,6 +3685,21 @@ dependencies = [ "str_indices", ] +[[package]] +name = "rspack" +version = "0.2.0" +dependencies = [ + "bitflags 2.6.0", + "indexmap 2.7.0", + "regex", + "rspack_core", + "rspack_hash", + "rspack_paths", + "rspack_regex", + "rustc-hash 2.1.0", + "serde_json", +] + [[package]] name = "rspack_allocator" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 55da6222f03..9527dd12a1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ ignored = [ "rspack_plugin_mini_css_extract", "rspack_binding", "rspack_plugin_merge", + "rspack", ] [workspace.dependencies] anyhow = { version = "1.0.95", features = ["backtrace"] } @@ -106,6 +107,7 @@ rspack_dojang = { version = "0.1.9" } # all rspack workspace dependencies +rspack = { version = "0.2.0", path = "crates/rspack" } rspack_allocator = { version = "0.2.0", path = "crates/rspack_allocator" } rspack_ast = { version = "0.2.0", path = "crates/rspack_ast" } rspack_base64 = { version = "0.2.0", path = "crates/rspack_base64" } diff --git a/crates/rspack/Cargo.toml b/crates/rspack/Cargo.toml new file mode 100644 index 00000000000..2559da8ee4b --- /dev/null +++ b/crates/rspack/Cargo.toml @@ -0,0 +1,21 @@ +[package] +description = "rspack" +edition = "2021" +license = "MIT" +name = "rspack" +repository = "https://github.com/web-infra-dev/rspack" +version = "0.2.0" + +[dependencies] +bitflags = { workspace = true } +indexmap = { workspace = true, features = ["rayon"] } +regex = { workspace = true } +rspack_core = { workspace = true } +rspack_hash = { workspace = true } +rspack_paths = { workspace = true } +rspack_regex = { workspace = true } +rustc-hash = { workspace = true } +serde_json = { workspace = true } + +[lints] +workspace = true diff --git a/crates/rspack/LICENSE b/crates/rspack/LICENSE new file mode 100644 index 00000000000..46310101ad8 --- /dev/null +++ b/crates/rspack/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2022-present Bytedance, Inc. and its affiliates. + + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crates/rspack/src/lib.rs b/crates/rspack/src/lib.rs new file mode 100644 index 00000000000..66dd7795f50 --- /dev/null +++ b/crates/rspack/src/lib.rs @@ -0,0 +1 @@ +pub mod options; diff --git a/crates/rspack_core/src/options/compiler_options_builder.rs b/crates/rspack/src/options/builder.rs similarity index 96% rename from crates/rspack_core/src/options/compiler_options_builder.rs rename to crates/rspack/src/options/builder.rs index 8bf5361463d..cb577ef8b04 100644 --- a/crates/rspack_core/src/options/compiler_options_builder.rs +++ b/crates/rspack/src/options/builder.rs @@ -1,23 +1,24 @@ use indexmap::IndexMap; +use rspack_core::{incremental::IncrementalPasses, ModuleType}; +use rspack_core::{ + AssetParserDataUrl, AssetParserDataUrlOptions, AssetParserOptions, ByDependency, CacheOptions, + ChunkLoading, ChunkLoadingType, CleanOptions, CompilerOptions, Context, CrossOriginLoading, + CssAutoGeneratorOptions, CssAutoParserOptions, CssExportsConvention, CssGeneratorOptions, + CssModuleGeneratorOptions, CssModuleParserOptions, CssParserOptions, DynamicImportMode, + EntryDescription, Environment, ExperimentCacheOptions, Experiments, Filename, FilenameTemplate, + GeneratorOptions, GeneratorOptionsMap, JavascriptParserOptions, JavascriptParserOrder, + JavascriptParserUrl, LibraryName, LibraryNonUmdObject, LibraryOptions, Mode, ModuleNoParseRules, + ModuleOptions, ModuleRule, ModuleRuleEffect, OutputOptions, ParserOptions, ParserOptionsMap, + PathInfo, PublicPath, Resolve, RspackFuture, RuleSetCondition, RuleSetLogicalConditions, + TrustedTypes, WasmLoading, WasmLoadingType, +}; use rspack_hash::{HashDigest, HashFunction, HashSalt}; use rspack_paths::{AssertUtf8, Utf8PathBuf}; use rspack_regex::RspackRegex; use rustc_hash::FxHashMap as HashMap; -use super::{ - get_targets_properties, AssetParserDataUrl, AssetParserDataUrlOptions, AssetParserOptions, - ByDependency, CacheOptions, ChunkLoading, ChunkLoadingType, CleanOptions, CompilerOptions, - Context, CrossOriginLoading, CssAutoGeneratorOptions, CssAutoParserOptions, CssExportsConvention, - CssGeneratorOptions, CssModuleGeneratorOptions, CssModuleParserOptions, CssParserOptions, - Devtool, DynamicImportMode, EntryDescription, Environment, ExperimentCacheOptions, Experiments, - Filename, FilenameTemplate, GeneratorOptions, GeneratorOptionsMap, JavascriptParserOptions, - JavascriptParserOrder, JavascriptParserUrl, LibraryName, LibraryNonUmdObject, LibraryOptions, - Mode, ModuleNoParseRules, ModuleOptions, ModuleRule, ModuleRuleEffect, OutputOptions, - ParserOptions, ParserOptionsMap, PathInfo, PublicPath, Resolve, RspackFuture, RuleSetCondition, - RuleSetLogicalConditions, Target, TargetProperties, TrustedTypes, WasmLoading, WasmLoadingType, -}; -use crate::{incremental::IncrementalPasses, ModuleType}; - +use super::target::{get_targets_properties, TargetProperties}; +use super::{Devtool, Target}; macro_rules! d { ($o:expr, $v:expr) => {{ $o.unwrap_or($v) @@ -36,6 +37,39 @@ macro_rules! f { }}; } +pub trait Builder { + type Item; + fn builder() -> Self::Item; +} + +impl Builder for CompilerOptions { + type Item = CompilerOptionsBuilder; + fn builder() -> Self::Item { + CompilerOptionsBuilder::default() + } +} + +impl Builder for OutputOptions { + type Item = OutputOptionsBuilder; + fn builder() -> Self::Item { + OutputOptionsBuilder::default() + } +} + +impl Builder for ModuleOptions { + type Item = ModuleOptionsBuilder; + fn builder() -> Self::Item { + ModuleOptionsBuilder::default() + } +} + +impl Builder for Experiments { + type Item = ExperimentsBuilder; + fn builder() -> Self::Item { + ExperimentsBuilder::default() + } +} + #[derive(Debug, Default)] pub struct CompilerOptionsBuilder { name: Option, @@ -52,12 +86,6 @@ pub struct CompilerOptionsBuilder { output: Option, } -impl CompilerOptions { - pub fn builder() -> CompilerOptionsBuilder { - CompilerOptionsBuilder::default() - } -} - impl CompilerOptionsBuilder { pub fn name(&mut self, name: String) -> &mut Self { self.name = Some(name); @@ -230,12 +258,6 @@ pub struct ModuleOptionsBuilder { no_parse: Option, } -impl ModuleOptions { - pub fn builder() -> ModuleOptionsBuilder { - ModuleOptionsBuilder::default() - } -} - impl ModuleOptionsBuilder { pub fn rule(&mut self, rule: ModuleRule) -> &mut Self { self.rules.push(rule); @@ -1074,13 +1096,13 @@ impl OutputOptionsBuilder { }); let chunk_loading_global = f!(self.chunk_loading_global.take(), || { - format!("webpackChunk{}", crate::utils::to_identifier(&unique_name)) + format!("webpackChunk{}", rspack_core::to_identifier(&unique_name)) }); let hot_update_global = f!(self.hot_update_global.take(), || { format!( "webpackHotUpdate{}", - crate::utils::to_identifier(&unique_name) + rspack_core::to_identifier(&unique_name) ) }); @@ -1293,12 +1315,6 @@ impl OutputOptionsBuilder { } } -impl OutputOptions { - pub fn builder() -> OutputOptionsBuilder { - OutputOptionsBuilder::default() - } -} - #[derive(Debug, Default)] pub struct ExperimentsBuilder { layers: Option, @@ -1314,11 +1330,6 @@ pub struct ExperimentsBuilder { async_web_assembly: Option, } -impl Experiments { - pub fn builder() -> ExperimentsBuilder { - ExperimentsBuilder::default() - } -} impl ExperimentsBuilder { pub fn layers(&mut self, layers: bool) -> &mut Self { self.layers = Some(layers); diff --git a/crates/rspack_core/src/options/devtool.rs b/crates/rspack/src/options/devtool.rs similarity index 100% rename from crates/rspack_core/src/options/devtool.rs rename to crates/rspack/src/options/devtool.rs diff --git a/crates/rspack/src/options/mod.rs b/crates/rspack/src/options/mod.rs new file mode 100644 index 00000000000..671c5bc34fe --- /dev/null +++ b/crates/rspack/src/options/mod.rs @@ -0,0 +1,9 @@ +mod builder; +mod devtool; +mod target; + +pub use builder::{ + Builder, CompilerOptionsBuilder, ExperimentsBuilder, ModuleOptionsBuilder, OutputOptionsBuilder, +}; +pub use devtool::Devtool; +pub use target::Target; diff --git a/crates/rspack_core/src/options/target.rs b/crates/rspack/src/options/target.rs similarity index 99% rename from crates/rspack_core/src/options/target.rs rename to crates/rspack/src/options/target.rs index e8c74ad95ca..5915de8d278 100644 --- a/crates/rspack_core/src/options/target.rs +++ b/crates/rspack/src/options/target.rs @@ -1,4 +1,4 @@ -use super::Context; +use rspack_core::Context; pub type Target = Vec; diff --git a/crates/rspack_core/src/options/mod.rs b/crates/rspack_core/src/options/mod.rs index bc7ffb23bff..4dbfeb92bf2 100644 --- a/crates/rspack_core/src/options/mod.rs +++ b/crates/rspack_core/src/options/mod.rs @@ -1,8 +1,6 @@ mod compiler_options; -mod compiler_options_builder; - pub use compiler_options::*; -pub use compiler_options_builder::*; + mod entry; pub use entry::*; mod optimizations; @@ -33,7 +31,3 @@ mod filename; pub use filename::*; mod clean_options; pub use clean_options::*; -mod target; -pub use target::*; -mod devtool; -pub use devtool::*;