diff --git a/Cargo.lock b/Cargo.lock index f8c4cdecbecf..c529e02134df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,7 +150,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -161,7 +161,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -177,13 +177,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.83" +version = "0.1.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +checksum = "1b1244b10dcd56c92219da4e14caa97e312079e185f04ba3eea25061561dc0a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -203,7 +203,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -302,7 +302,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -445,7 +445,7 @@ checksum = "523363cbe1df49b68215efdf500b103ac3b0fb4836aed6d15689a076eadb8fff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1012,7 +1012,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" dependencies = [ "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1032,7 +1032,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a2785755761f3ddc1492979ce1e48d2c00d09311c39e4466429188f3dd6501" dependencies = [ "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1080,7 +1080,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1102,7 +1102,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core 0.20.10", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1192,7 +1192,7 @@ checksum = "30542c1ad912e0e3d22a1935c290e12e8a29d704a420177a31faad4a601a0800" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1234,7 +1234,7 @@ dependencies = [ "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1254,7 +1254,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" dependencies = [ "derive_builder_core 0.20.2", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1274,7 +1274,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", "unicode-xid", ] @@ -1309,7 +1309,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1404,7 +1404,7 @@ dependencies = [ "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1525,7 +1525,7 @@ checksum = "8d7ccf961415e7aa17ef93dcb6c2441faaa8e768abe09e659b908089546f74c5" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1638,7 +1638,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1715,7 +1715,7 @@ checksum = "39b697dbd8bfcc35d0ee91698aaa379af096368ba8837d279cc097b276edda45" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -1737,9 +1737,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "globset" @@ -1776,17 +1776,18 @@ dependencies = [ [[package]] name = "handlebars" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd4ccde012831f9a071a637b0d4e31df31c0f6c525784b35ae76a9ac6bc1e315" +checksum = "3d6b224b95c1e668ac0270325ad563b2eef1469fbbb8959bc7c692c844b813d9" dependencies = [ + "derive_builder 0.20.2", "log", "num-order", "pest", "pest_derive", "serde", "serde_json", - "thiserror 1.0.69", + "thiserror 2.0.9", ] [[package]] @@ -2066,7 +2067,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -2229,7 +2230,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -2265,6 +2266,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.14" @@ -2630,7 +2640,7 @@ checksum = "23c9b935fbe1d6cbd1dac857b54a688145e2d93f48db36010514d0f612d0ad67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -2708,7 +2718,7 @@ checksum = "1bb5c1d8184f13f7d0ccbeeca0def2f9a181bce2624302793005f5ca8aa62e5e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -2743,7 +2753,7 @@ dependencies = [ "napi-derive-backend", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -2756,7 +2766,7 @@ dependencies = [ "proc-macro2", "quote", "semver 1.0.24", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -3084,7 +3094,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -3148,7 +3158,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -3177,7 +3187,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -3266,7 +3276,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -3298,7 +3308,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -3356,7 +3366,7 @@ checksum = "ca414edb151b4c8d125c12566ab0d74dc9cdba36fb80eb7b848c15f495fd32d1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -3476,7 +3486,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -3662,7 +3672,7 @@ checksum = "09cb82b74b4810f07e460852c32f522e979787691b0b7b7439fe473e49d49b2f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -3854,7 +3864,7 @@ dependencies = [ "hex", "indexmap 2.7.0", "indoc", - "itertools 0.13.0", + "itertools 0.14.0", "json", "mime_guess", "num-bigint", @@ -3981,7 +3991,7 @@ dependencies = [ name = "rspack_ids" version = "0.2.0" dependencies = [ - "itertools 0.13.0", + "itertools 0.14.0", "rayon", "regex", "rspack_collections", @@ -4099,7 +4109,7 @@ dependencies = [ "json", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -4134,7 +4144,7 @@ version = "0.2.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -4279,7 +4289,7 @@ dependencies = [ "dashmap 6.1.0", "derive_more", "futures", - "itertools 0.13.0", + "itertools 0.14.0", "rayon", "regex", "rspack_base64", @@ -4413,7 +4423,7 @@ dependencies = [ "cow-utils", "dashmap 6.1.0", "futures", - "itertools 0.13.0", + "itertools 0.14.0", "path-clean 1.0.1", "rayon", "rspack_base64", @@ -4460,7 +4470,7 @@ dependencies = [ "fast-glob", "indexmap 2.7.0", "indoc", - "itertools 0.13.0", + "itertools 0.14.0", "linked_hash_set", "num-bigint", "once_cell", @@ -4585,7 +4595,7 @@ version = "0.2.0" dependencies = [ "async-trait", "hashlink", - "itertools 0.13.0", + "itertools 0.14.0", "regex", "rspack_cacheable", "rspack_collections", @@ -4672,7 +4682,7 @@ dependencies = [ "cow-utils", "derive_more", "indexmap 2.7.0", - "itertools 0.13.0", + "itertools 0.14.0", "rspack_cacheable", "rspack_collections", "rspack_core", @@ -4883,7 +4893,7 @@ dependencies = [ "async-trait", "cow-utils", "futures", - "itertools 0.13.0", + "itertools 0.14.0", "pollster", "rayon", "rspack_error", @@ -5080,7 +5090,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -5133,9 +5143,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] @@ -5153,13 +5163,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -5170,7 +5180,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -5439,7 +5449,7 @@ checksum = "710e9696ef338691287aeb937ee6ffe60022f579d3c8d2fd9d58973a9a10a466" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -5484,7 +5494,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -5710,7 +5720,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -5792,7 +5802,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -6143,7 +6153,7 @@ dependencies = [ "swc_ecma_ast", "swc_ecma_parser", "swc_macros_common", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -6249,7 +6259,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -6426,7 +6436,7 @@ checksum = "e96e15288bf385ab85eb83cff7f9e2d834348da58d0a31b33bdb572e66ee413e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -6503,7 +6513,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -6577,7 +6587,7 @@ checksum = "a509f56fca05b39ba6c15f3e58636c3924c78347d63853632ed2ffcb6f5a0ac7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -6650,7 +6660,7 @@ checksum = "4c78717a841565df57f811376a3d19c9156091c55175e12d378f3a522de70cef" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -6705,9 +6715,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.92" +version = "2.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ae51629bf965c5c098cc9e87908a3df5301051a9e087d6f9bef5c9771ed126" +checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" dependencies = [ "proc-macro2", "quote", @@ -6722,7 +6732,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -6842,7 +6852,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -6853,7 +6863,7 @@ checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -6945,7 +6955,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -7038,7 +7048,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -7527,7 +7537,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", "wasm-bindgen-shared", ] @@ -7549,7 +7559,7 @@ checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -8290,7 +8300,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", "synstructure", ] @@ -8312,7 +8322,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -8332,7 +8342,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", "synstructure", ] @@ -8353,7 +8363,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] @@ -8375,7 +8385,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.95", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 87dc583b4626..55da6222f03d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ anyhow = { version = "1.0.95", features = ["backtrace"] } anymap = { package = "anymap3", version = "1.0.1" } async-recursion = { version = "1.1.1" } async-scoped = { version = "0.9.0" } -async-trait = { version = "0.1.83" } +async-trait = { version = "0.1.84" } bitflags = { version = "2.6.0" } camino = { version = "1.1.9" } concat-string = { version = "1.0.1" } @@ -40,13 +40,13 @@ dashmap = { version = "6.1.0" } derive_more = { version = "1.0.0" } either = { version = "1.13.0" } futures = { version = "0.3.31" } -glob = { version = "0.3.1" } +glob = { version = "0.3.2" } hashlink = { version = "0.10.0" } heck = { version = "0.5.0" } hex = { version = "0.4.3" } indexmap = { version = "2.7.0" } indoc = { version = "2.0.5" } -itertools = { version = "0.13.0" } +itertools = { version = "0.14.0" } json = { version = "0.12.4" } lightningcss = { version = "1.0.0-alpha.61" } linked_hash_set = { version = "0.1.5" } @@ -66,13 +66,13 @@ ropey = "1.6.1" rspack_resolver = { version = "0.3.6", features = ["package_json_raw_json_api"] } rspack_sources = { version = "0.4.1" } rustc-hash = { version = "2.1.0" } -serde = { version = "1.0.216" } +serde = { version = "1.0.217" } serde_json = { version = "1.0.134" } simd-json = { version = "0.14.3" } smol_str = { version = "0.3.0" } stacker = { version = "0.1.17" } sugar_path = { version = "1.2.0", features = ["cached_current_dir"] } -syn = { version = "2.0.92" } +syn = { version = "2.0.95" } tokio = { version = "1.42.0" } tracing = { version = "0.1.41" } tracing-subscriber = { version = "0.3.19" } diff --git a/crates/rspack_core/src/options/compiler_options_builder.rs b/crates/rspack_core/src/options/compiler_options_builder.rs index 57e45d18dbdf..8bf5361463d0 100644 --- a/crates/rspack_core/src/options/compiler_options_builder.rs +++ b/crates/rspack_core/src/options/compiler_options_builder.rs @@ -9,8 +9,8 @@ use super::{ 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, + 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, @@ -24,6 +24,12 @@ macro_rules! d { }}; } +macro_rules! w { + ($o:expr, $v:expr) => {{ + $o.get_or_insert($v) + }}; +} + macro_rules! f { ($o:expr, $v:expr) => {{ $o.unwrap_or_else($v) @@ -38,6 +44,8 @@ pub struct CompilerOptionsBuilder { context: Option, cache: Option, mode: Option, + devtool: Option, + profile: Option, bail: Option, experiments: Option, module: Option, @@ -79,6 +87,11 @@ impl CompilerOptionsBuilder { self } + pub fn devtool(&mut self, devtool: Devtool) -> &mut Self { + self.devtool = Some(devtool); + self + } + pub fn mode(&mut self, mode: Mode) -> &mut Self { self.mode = Some(mode); self @@ -89,6 +102,11 @@ impl CompilerOptionsBuilder { self } + pub fn profile(&mut self, profile: bool) -> &mut Self { + self.profile = Some(profile); + self + } + pub fn module(&mut self, module: V) -> &mut Self where V: Into, @@ -115,7 +133,7 @@ impl CompilerOptionsBuilder { pub fn build(&mut self) -> CompilerOptions { let name = self.name.take(); - let context = self.context.take().unwrap_or_else(|| { + let context = f!(self.context.take(), || { std::env::current_dir() .expect("`current_dir` should be available") .assert_utf8() @@ -124,13 +142,22 @@ impl CompilerOptionsBuilder { // TODO: support browserlist default target let target = f!(self.target.take(), || vec!["web".to_string()]); - let target_properties = get_targets_properties(&target, &context); + let development = matches!(self.mode, Some(Mode::Development)); let production = matches!(self.mode, Some(Mode::Production) | None); let mode = d!(self.mode.take(), Mode::Production); - let bail = self.bail.unwrap_or(false); + // TODO: support entry + let _devtool = f!(self.devtool.take(), || { + if development { + Devtool::Eval + } else { + Devtool::False + } + }); + let profile = d!(self.profile.take(), false); + let bail = d!(self.bail.take(), false); let cache = d!(self.cache.take(), { if development { CacheOptions::Memory @@ -139,31 +166,39 @@ impl CompilerOptionsBuilder { } }); - let mut experiments = self.apply_experiments(development, production); + let mut experiments_builder = f!(self.experiments.take(), Experiments::builder); + let mut experiments = experiments_builder.build(development, production); // Disable experiments cache if global cache is set to `Disabled` if matches!(cache, CacheOptions::Disabled) { experiments.cache = ExperimentCacheOptions::Disabled; } - // TODO: support css - let css = true; - // TODO: support async web assembly - let async_web_assembly = false; - // TODO: support experiment output module - let output_module = Some(false); - - let module = self.apply_module(async_web_assembly, css, Some(&target_properties)); + let async_web_assembly = experiments_builder + .async_web_assembly + .expect("should apply default value"); + let css = experiments_builder.css.expect("should apply default value"); + let future_defaults = experiments_builder + .future_defaults + .expect("should apply default value"); + let output_module = experiments_builder + .output_module + .expect("should apply default value"); + + let module = f!(self.module.take(), ModuleOptions::builder).build( + async_web_assembly, + css, + &target_properties, + ); - // TODO: options - let entry = self.entry.clone(); - let output = self.apply_output( - context.clone(), + let is_affected_by_browserslist = target.iter().any(|t| t.starts_with("browserslist")); + let output = f!(self.output.take(), OutputOptions::builder).build( + &context, output_module, Some(&target_properties), - target.iter().any(|t| t.starts_with("browserslist")), + is_affected_by_browserslist, development, - &entry, - false, + &self.entry, + future_defaults, ); CompilerOptions { @@ -179,61 +214,12 @@ impl CompilerOptionsBuilder { experiments, node: Default::default(), optimization: Default::default(), - profile: Default::default(), + profile, amd: None, bail, __references: Default::default(), } } - - fn apply_module( - &mut self, - async_web_assembly: bool, - css: bool, - target_properties: Option<&TargetProperties>, - ) -> ModuleOptions { - self - .module - .take() - .unwrap_or_else(ModuleOptions::builder) - .build(async_web_assembly, css, target_properties) - } - - #[allow(clippy::too_many_arguments)] - fn apply_output( - &mut self, - context: Context, - output_module: Option, - target_properties: Option<&TargetProperties>, - is_affected_by_browserslist: bool, - development: bool, - entry: &IndexMap, - future_defaults: bool, - ) -> OutputOptions { - self - .output - .take() - .unwrap_or_else(OutputOptions::builder) - .build( - context.clone(), - output_module, - target_properties, - is_affected_by_browserslist, - development, - entry, - future_defaults, - ) - } - - fn apply_experiments(&mut self, development: bool, production: bool) -> Experiments { - self - .experiments - .take() - .unwrap_or_else(Experiments::builder) - .build(development, production) - } - - // fn apply_output() } #[derive(Debug, Default)] @@ -286,7 +272,7 @@ impl ModuleOptionsBuilder { &mut self, async_web_assembly: bool, css: bool, - target_properties: Option<&TargetProperties>, + target_properties: &TargetProperties, ) -> ModuleOptions { let parser = self.parser.get_or_insert(ParserOptionsMap::default()); @@ -344,7 +330,7 @@ impl ModuleOptionsBuilder { parser.insert("css/module".to_string(), css_module_parser_options); // CSS generator options - let exports_only = target_properties.map_or(true, |t| !t.document()); + let exports_only = !target_properties.document(); generator.insert( "css".to_string(), @@ -926,18 +912,17 @@ impl OutputOptionsBuilder { self } - #[allow(clippy::too_many_arguments)] + #[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)] pub fn build( &mut self, - context: Context, - output_module: Option, + context: &Context, + output_module: bool, target_properties: Option<&TargetProperties>, is_affected_by_browserslist: bool, development: bool, _entry: &IndexMap, _future_defaults: bool, ) -> OutputOptions { - let output_module = output_module.unwrap_or(false); let tp = target_properties; let path = f!(self.path.take(), || { context.as_path().join("dist") }); @@ -1321,6 +1306,10 @@ pub struct ExperimentsBuilder { top_level_await: Option, rspack_future: Option, cache: Option, + + // Builder specific + output_module: Option, + future_defaults: Option, css: Option, async_web_assembly: Option, } @@ -1351,6 +1340,11 @@ impl ExperimentsBuilder { self } + pub fn future_defaults(&mut self, future_defaults: bool) -> &mut Self { + self.future_defaults = Some(future_defaults); + self + } + pub fn css(&mut self, css: bool) -> &mut Self { self.css = Some(css); self @@ -1371,7 +1365,6 @@ impl ExperimentsBuilder { } }); let top_level_await = d!(self.top_level_await, true); - let rspack_future = d!(self.rspack_future.take(), RspackFuture {}); let cache = f!(self.cache.take(), || { if development { ExperimentCacheOptions::Memory @@ -1379,6 +1372,13 @@ impl ExperimentsBuilder { ExperimentCacheOptions::Disabled } }); + let rspack_future = d!(self.rspack_future.take(), RspackFuture {}); + + // Builder specific + let future_defaults = w!(self.future_defaults, false); + w!(self.css, *future_defaults); + w!(self.async_web_assembly, *future_defaults); + w!(self.output_module, false); Experiments { layers, diff --git a/crates/rspack_core/src/options/devtool.rs b/crates/rspack_core/src/options/devtool.rs new file mode 100644 index 000000000000..0fe1f1bda79b --- /dev/null +++ b/crates/rspack_core/src/options/devtool.rs @@ -0,0 +1,268 @@ +use bitflags::bitflags; + +#[derive(Debug, PartialEq)] +pub enum Devtool { + False, + Eval, + CheapSourceMap, + CheapModuleSourceMap, + SourceMap, + InlineCheapSourceMap, + InlineCheapModuleSourceMap, + InlineSourceMap, + InlineNosourcesCheapSourceMap, + InlineNosourcesCheapModuleSourceMap, + InlineNosourcesSourceMap, + NosourcesCheapSourceMap, + NosourcesCheapModuleSourceMap, + NosourcesSourceMap, + HiddenNosourcesCheapSourceMap, + HiddenNosourcesCheapModuleSourceMap, + HiddenNosourcesSourceMap, + HiddenCheapSourceMap, + HiddenCheapModuleSourceMap, + HiddenSourceMap, + EvalCheapSourceMap, + EvalCheapModuleSourceMap, + EvalSourceMap, + EvalNosourcesCheapSourceMap, + EvalNosourcesCheapModuleSourceMap, + EvalNosourcesSourceMap, +} + +// Implement FromStr trait to parse strings into Devtool enum +impl std::str::FromStr for Devtool { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "false" => Ok(Devtool::False), + "eval" => Ok(Devtool::Eval), + "cheap-source-map" => Ok(Devtool::CheapSourceMap), + "cheap-module-source-map" => Ok(Devtool::CheapModuleSourceMap), + "source-map" => Ok(Devtool::SourceMap), + "inline-cheap-source-map" => Ok(Devtool::InlineCheapSourceMap), + "inline-cheap-module-source-map" => Ok(Devtool::InlineCheapModuleSourceMap), + "inline-source-map" => Ok(Devtool::InlineSourceMap), + "inline-nosources-cheap-source-map" => Ok(Devtool::InlineNosourcesCheapSourceMap), + "inline-nosources-cheap-module-source-map" => { + Ok(Devtool::InlineNosourcesCheapModuleSourceMap) + } + "inline-nosources-source-map" => Ok(Devtool::InlineNosourcesSourceMap), + "nosources-cheap-source-map" => Ok(Devtool::NosourcesCheapSourceMap), + "nosources-cheap-module-source-map" => Ok(Devtool::NosourcesCheapModuleSourceMap), + "nosources-source-map" => Ok(Devtool::NosourcesSourceMap), + "hidden-nosources-cheap-source-map" => Ok(Devtool::HiddenNosourcesCheapSourceMap), + "hidden-nosources-cheap-module-source-map" => { + Ok(Devtool::HiddenNosourcesCheapModuleSourceMap) + } + "hidden-nosources-source-map" => Ok(Devtool::HiddenNosourcesSourceMap), + "hidden-cheap-source-map" => Ok(Devtool::HiddenCheapSourceMap), + "hidden-cheap-module-source-map" => Ok(Devtool::HiddenCheapModuleSourceMap), + "hidden-source-map" => Ok(Devtool::HiddenSourceMap), + "eval-cheap-source-map" => Ok(Devtool::EvalCheapSourceMap), + "eval-cheap-module-source-map" => Ok(Devtool::EvalCheapModuleSourceMap), + "eval-source-map" => Ok(Devtool::EvalSourceMap), + "eval-nosources-cheap-source-map" => Ok(Devtool::EvalNosourcesCheapSourceMap), + "eval-nosources-cheap-module-source-map" => Ok(Devtool::EvalNosourcesCheapModuleSourceMap), + "eval-nosources-source-map" => Ok(Devtool::EvalNosourcesSourceMap), + _ => Err(format!("Invalid devtool value: {s}")), + } + } +} + +// Implement Display trait to convert enum variants back to strings +impl std::fmt::Display for Devtool { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + let s = match self { + Devtool::False => "false", + Devtool::Eval => "eval", + Devtool::CheapSourceMap => "cheap-source-map", + Devtool::CheapModuleSourceMap => "cheap-module-source-map", + Devtool::SourceMap => "source-map", + Devtool::InlineCheapSourceMap => "inline-cheap-source-map", + Devtool::InlineCheapModuleSourceMap => "inline-cheap-module-source-map", + Devtool::InlineSourceMap => "inline-source-map", + Devtool::InlineNosourcesCheapSourceMap => "inline-nosources-cheap-source-map", + Devtool::InlineNosourcesCheapModuleSourceMap => "inline-nosources-cheap-module-source-map", + Devtool::InlineNosourcesSourceMap => "inline-nosources-source-map", + Devtool::NosourcesCheapSourceMap => "nosources-cheap-source-map", + Devtool::NosourcesCheapModuleSourceMap => "nosources-cheap-module-source-map", + Devtool::NosourcesSourceMap => "nosources-source-map", + Devtool::HiddenNosourcesCheapSourceMap => "hidden-nosources-cheap-source-map", + Devtool::HiddenNosourcesCheapModuleSourceMap => "hidden-nosources-cheap-module-source-map", + Devtool::HiddenNosourcesSourceMap => "hidden-nosources-source-map", + Devtool::HiddenCheapSourceMap => "hidden-cheap-source-map", + Devtool::HiddenCheapModuleSourceMap => "hidden-cheap-module-source-map", + Devtool::HiddenSourceMap => "hidden-source-map", + Devtool::EvalCheapSourceMap => "eval-cheap-source-map", + Devtool::EvalCheapModuleSourceMap => "eval-cheap-module-source-map", + Devtool::EvalSourceMap => "eval-source-map", + Devtool::EvalNosourcesCheapSourceMap => "eval-nosources-cheap-source-map", + Devtool::EvalNosourcesCheapModuleSourceMap => "eval-nosources-cheap-module-source-map", + Devtool::EvalNosourcesSourceMap => "eval-nosources-source-map", + }; + write!(f, "{s}") + } +} + +bitflags! { + #[derive(Debug, Clone, Copy, PartialEq)] + pub struct DevToolFlags: u32 { + const SOURCE_MAP = 1 << 0; + const HIDDEN = 1 << 1; + const INLINE = 1 << 2; + const EVAL = 1 << 3; + const CHEAP = 1 << 4; + const MODULE = 1 << 5; + const NOSOURCES = 1 << 6; + } +} + +impl DevToolFlags { + // pub(crate) fn use_source_map_plugin(&self) -> bool { + // self.contains(DevToolFlags::SOURCE_MAP) + // } + + // pub(crate) fn use_eval_plugin(&self) -> bool { + // !self.contains(DevToolFlags::SOURCE_MAP) && self.contains(DevToolFlags::EVAL) + // } +} + +impl From for DevToolFlags { + fn from(devtool: Devtool) -> Self { + match devtool { + Devtool::False => DevToolFlags::empty(), + Devtool::Eval => DevToolFlags::EVAL, + _ => { + // Start with SOURCE_MAP since all other variants contain it + let mut flags = DevToolFlags::SOURCE_MAP; + + match devtool { + Devtool::HiddenSourceMap + | Devtool::HiddenCheapSourceMap + | Devtool::HiddenCheapModuleSourceMap + | Devtool::HiddenNosourcesSourceMap + | Devtool::HiddenNosourcesCheapSourceMap + | Devtool::HiddenNosourcesCheapModuleSourceMap => { + flags |= DevToolFlags::HIDDEN; + } + _ => {} + } + + match devtool { + Devtool::InlineSourceMap + | Devtool::InlineCheapSourceMap + | Devtool::InlineCheapModuleSourceMap + | Devtool::InlineNosourcesSourceMap + | Devtool::InlineNosourcesCheapSourceMap + | Devtool::InlineNosourcesCheapModuleSourceMap => { + flags |= DevToolFlags::INLINE; + } + _ => {} + } + + match devtool { + Devtool::EvalSourceMap + | Devtool::EvalCheapSourceMap + | Devtool::EvalCheapModuleSourceMap + | Devtool::EvalNosourcesSourceMap + | Devtool::EvalNosourcesCheapSourceMap + | Devtool::EvalNosourcesCheapModuleSourceMap => { + flags |= DevToolFlags::EVAL; + } + _ => {} + } + + match devtool { + Devtool::CheapSourceMap + | Devtool::CheapModuleSourceMap + | Devtool::InlineCheapSourceMap + | Devtool::InlineCheapModuleSourceMap + | Devtool::EvalCheapSourceMap + | Devtool::EvalCheapModuleSourceMap + | Devtool::NosourcesCheapSourceMap + | Devtool::NosourcesCheapModuleSourceMap + | Devtool::HiddenCheapSourceMap + | Devtool::HiddenCheapModuleSourceMap + | Devtool::InlineNosourcesCheapSourceMap + | Devtool::InlineNosourcesCheapModuleSourceMap + | Devtool::EvalNosourcesCheapSourceMap + | Devtool::EvalNosourcesCheapModuleSourceMap + | Devtool::HiddenNosourcesCheapSourceMap + | Devtool::HiddenNosourcesCheapModuleSourceMap => { + flags |= DevToolFlags::CHEAP; + } + _ => {} + } + + match devtool { + Devtool::CheapModuleSourceMap + | Devtool::InlineCheapModuleSourceMap + | Devtool::EvalCheapModuleSourceMap + | Devtool::NosourcesCheapModuleSourceMap + | Devtool::HiddenCheapModuleSourceMap + | Devtool::InlineNosourcesCheapModuleSourceMap + | Devtool::EvalNosourcesCheapModuleSourceMap + | Devtool::HiddenNosourcesCheapModuleSourceMap => { + flags |= DevToolFlags::MODULE; + } + _ => {} + } + + match devtool { + Devtool::NosourcesSourceMap + | Devtool::NosourcesCheapSourceMap + | Devtool::NosourcesCheapModuleSourceMap + | Devtool::InlineNosourcesSourceMap + | Devtool::InlineNosourcesCheapSourceMap + | Devtool::InlineNosourcesCheapModuleSourceMap + | Devtool::EvalNosourcesSourceMap + | Devtool::EvalNosourcesCheapSourceMap + | Devtool::EvalNosourcesCheapModuleSourceMap + | Devtool::HiddenNosourcesSourceMap + | Devtool::HiddenNosourcesCheapSourceMap + | Devtool::HiddenNosourcesCheapModuleSourceMap => { + flags |= DevToolFlags::NOSOURCES; + } + _ => {} + } + + flags + } + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_devtool_flags_conversion() { + // Test eval-cheap-module-source-map + let devtool = Devtool::EvalCheapModuleSourceMap; + let flags = DevToolFlags::from(devtool); + + assert!(flags.contains(DevToolFlags::SOURCE_MAP)); + assert!(flags.contains(DevToolFlags::EVAL)); + assert!(flags.contains(DevToolFlags::CHEAP)); + assert!(flags.contains(DevToolFlags::MODULE)); + assert!(!flags.contains(DevToolFlags::HIDDEN)); + assert!(!flags.contains(DevToolFlags::INLINE)); + assert!(!flags.contains(DevToolFlags::NOSOURCES)); + + // Test the helper methods + // assert!(flags.use_source_map_plugin()); + } + + #[test] + fn test_eval_only() { + let devtool = Devtool::Eval; + let flags = DevToolFlags::from(devtool); + + assert!(flags.contains(DevToolFlags::EVAL)); + assert!(!flags.contains(DevToolFlags::SOURCE_MAP)); + // assert!(flags.use_eval_plugin()); + } +} diff --git a/crates/rspack_core/src/options/mod.rs b/crates/rspack_core/src/options/mod.rs index 8ecae9dbeae4..bc7ffb23bffd 100644 --- a/crates/rspack_core/src/options/mod.rs +++ b/crates/rspack_core/src/options/mod.rs @@ -35,3 +35,5 @@ mod clean_options; pub use clean_options::*; mod target; pub use target::*; +mod devtool; +pub use devtool::*; diff --git a/crates/swc_plugin_import/Cargo.toml b/crates/swc_plugin_import/Cargo.toml index bff6f7c9e1e5..b58340babbf2 100644 --- a/crates/swc_plugin_import/Cargo.toml +++ b/crates/swc_plugin_import/Cargo.toml @@ -8,7 +8,7 @@ version = "0.2.0" [dependencies] cow-utils = { workspace = true } -handlebars = "6.2.0" +handlebars = "6.3.0" heck = { workspace = true } rustc-hash = { workspace = true } serde = { workspace = true } diff --git a/packages/rspack/src/builtin-plugin/lazy-compilation/plugin.ts b/packages/rspack/src/builtin-plugin/lazy-compilation/plugin.ts index e062edafdcf7..e8eb6260fd5c 100644 --- a/packages/rspack/src/builtin-plugin/lazy-compilation/plugin.ts +++ b/packages/rspack/src/builtin-plugin/lazy-compilation/plugin.ts @@ -31,12 +31,12 @@ export default class LazyCompilationPlugin { apply(compiler: Compiler) { const backend = getBackend({ - ...this.backend, client: require.resolve( `../hot/lazy-compilation-${ compiler.options.externalsPresets.node ? "node" : "web" }.js` - ) + ), + ...this.backend }); new BuiltinLazyCompilationPlugin(