diff --git a/.cargo/config.toml b/.cargo/config.toml index 571b7f26aa3..d9b3e7e317f 100755 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -30,7 +30,6 @@ rustflags = [ "-Wclippy::same_name_method", "-Aclippy::default_constructed_unit_structs", - "-C", "symbol-mangling-version=v0", "--cfg", "tokio_unstable" ] diff --git a/Cargo.lock b/Cargo.lock index 0565289c1e6..b8c66c14526 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1412,9 +1412,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -1436,9 +1436,9 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" @@ -1453,9 +1453,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" @@ -1474,9 +1474,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -1485,21 +1485,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -2995,6 +2995,12 @@ dependencies = [ "syn 2.0.79", ] +[[package]] +name = "pollster" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3" + [[package]] name = "portable-atomic" version = "1.3.3" @@ -3507,6 +3513,7 @@ dependencies = [ "glob", "napi-derive", "napi-h", + "pollster", "rspack_binding_values", "rspack_collections", "rspack_core", @@ -3864,10 +3871,10 @@ dependencies = [ "serde", "serde_json", "stacker", + "swc", "swc_config", "swc_core", "swc_plugin_import", - "tokio", "url", ] @@ -5220,9 +5227,9 @@ dependencies = [ [[package]] name = "swc" -version = "3.0.1" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2183536db1e18e9b1d8b6c98716b2f030f459f3e46a0f1806125c0d03a081fff" +checksum = "75ed459d2becd7649143665548028e7c9254b8794bc5e15d262694a4bb54caa4" dependencies = [ "anyhow", "base64 0.21.7", @@ -5314,9 +5321,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "2.0.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c96bb59e6721eb665764d6dc42a8537d61129ade06f8dd87894d51e018c81d" +checksum = "992b89cdcff8e61c1308a984af5450a60a382b106f3e79fd6aabf9e2e193d076" dependencies = [ "ahash 0.8.11", "anyhow", @@ -5346,9 +5353,9 @@ dependencies = [ [[package]] name = "swc_compiler_base" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee24249ab88d3951169364c6c9042d7200d3f8d9657f4ead33f0f8b212cf8c16" +checksum = "990ad90a98e1e72af29ce25ed72e12e61d4a06c64725e6fa63c9d7291a9f1e27" dependencies = [ "anyhow", "base64 0.21.7", @@ -5399,9 +5406,9 @@ dependencies = [ [[package]] name = "swc_core" -version = "3.0.1" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c73dfbb25de4c4059b40ecd352be76a6a1a9424890f4579a815f25432468c6" +checksum = "ec7c3843afe82ed84128192118412c185e883010a1c2fe730c373cd739c8cc56" dependencies = [ "swc", "swc_allocator", @@ -5427,9 +5434,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4257865f3b7f30a6c6f46035a39f27c08b59a1af093a9400f90bd5e2d510993" +checksum = "99e7c0cd9dfe2a49c8f0b4ce699c13c9e270b8487a0176e1d89e5a9a586d0b3b" dependencies = [ "bitflags 2.5.0", "bytecheck 0.6.11", @@ -5448,9 +5455,9 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca92989669711b99814770f32ccd55ae526627f0576e2a2b7c99df78007fed02" +checksum = "09236707a86e5d9f24c58e46c7f0efcc728daf1dd48167b2071f7afc11b7ea67" dependencies = [ "memchr", "num-bigint", @@ -5480,9 +5487,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_bugfixes" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "744bf969587ec9f0f3a1fa648bdaa8db5895b5c3ba24cab22e2f55fbf3145f80" +checksum = "b75e7322ae25d39db5fc3e1022c9044415578646ad2b0e776d3651ea72c6c5ef" dependencies = [ "swc_atoms", "swc_common", @@ -5497,9 +5504,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_common" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "105c4288abcade8e27cf094f3a8357d8525f05116fb90555ae916de004ce37ef" +checksum = "41265d5e64e9e72e7916be2bc491529be6386f276878a5f938abd3de3e804ae2" dependencies = [ "swc_common", "swc_ecma_ast", @@ -5510,9 +5517,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2015" -version = "3.0.1" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2d82ed9ea4af9cffd600d3e67e6799bf6aa44058baec555db1e76156fb0bf6" +checksum = "2091f28686c27c001d661397078438ef7af3d5e63986fd3ebad406757221997a" dependencies = [ "arrayvec", "indexmap 2.2.6", @@ -5537,9 +5544,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2016" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "000baf706f58d331bce625df7c3d7753ee9b082257348f01a6322de324c32657" +checksum = "7e7a93d54a35e32b14d676ce212af86ad12a3ed6a9e1a777592ca03ad530d380" dependencies = [ "swc_atoms", "swc_common", @@ -5554,9 +5561,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2017" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32d35656f67ed3bb4b47e2db1c38a672f162b4a8da2209c5e6d1630e9fb9a5e5" +checksum = "85b0f6ba7783a1fb34839b9c28c630b724b440fda93cccb7c62f0c689fb91155" dependencies = [ "serde", "swc_atoms", @@ -5572,9 +5579,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2018" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ca1a1a415b68621c35cf9e6abeca238a10ebe7755aa41c1f62ca7963507def9" +checksum = "76dc53785f2354b3f2adc828e6e1210f6358dac9d6bbdcb7aabd6953b1ea7d3d" dependencies = [ "serde", "swc_atoms", @@ -5591,9 +5598,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2019" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7139341fc2fcefd6b95c513556b3e40a582e8cfddf60e7ea1de3a925feaa3b" +checksum = "2dcd6f4d5adf45ee2f9a32b0ef8ae57064cc6ad9994b6b83ab8779a3cf4e2c88" dependencies = [ "swc_atoms", "swc_common", @@ -5607,9 +5614,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2020" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7a17758f8aabed8c7d7b283a091636e66a19bf08232aa346299361fa7536ae" +checksum = "1103f8814cf15a841dfe3be7f236ba4ed7eeba99dd70ba95a6c50d3f06f98470" dependencies = [ "serde", "swc_atoms", @@ -5625,9 +5632,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2021" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "108fa9dbaea53ac3fc94bb4245a3a88c5655575b455913c5103bde3e669e0a97" +checksum = "f8bfc3e80b008c849c9fccfeacbf0c96b7a7bcc8cc36b80f5a36a2589e43112b" dependencies = [ "swc_atoms", "swc_common", @@ -5641,9 +5648,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2022" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190af774d89b59ea9477c740304c4e90401ab18ae38aa60865ad4a9ec3184eec" +checksum = "c2c99e6bb989a1eeb0372a244eaecff7afe97ac9d5c90ff910fd9624fbb91b55" dependencies = [ "swc_atoms", "swc_common", @@ -5660,9 +5667,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es3" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fef5471201257b228aac059359ab2c9b63d75c046c0f1898a118b88ad29a72" +checksum = "2d713149adf01aea336eab6dfd71efc69b47bd4c23bf00d94676b29a7a4399c2" dependencies = [ "swc_common", "swc_ecma_ast", @@ -5675,9 +5682,9 @@ dependencies = [ [[package]] name = "swc_ecma_ext_transforms" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99bb59c22fb1fa791b62e8c85708613e5ce735d6e10b876008e78cd29c74944e" +checksum = "e8372183140810c1b68167694ffc8b83ab184d57f936b655a141a21fc6be843e" dependencies = [ "phf 0.11.2", "swc_atoms", @@ -5689,9 +5696,9 @@ dependencies = [ [[package]] name = "swc_ecma_lints" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8e245e1c8a40e1bbb1d1e07944c7c3f609cec90aeb58a3146eef811b21aa713" +checksum = "281bc034243e0594dda84f1c0c705dbd25475fa384815cce454ffd75e2582cfe" dependencies = [ "auto_impl", "dashmap 5.5.3", @@ -5709,9 +5716,9 @@ dependencies = [ [[package]] name = "swc_ecma_loader" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1e95137d89bd71b770d2bd26a0de8205387fb12d727a9ca5a1fc4c3a7994611" +checksum = "3990b0a3db49dc0d6310b24487f502152c1cc92adea4fbe4335907fce4b13e42" dependencies = [ "anyhow", "dashmap 5.5.3", @@ -5731,9 +5738,9 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95e35da2034a38396a1547b2746d32fe37bcd4ff52a4b7ab793ebc034aa2d47d" +checksum = "1ef4de55c8a57d10a2683157b4d17301482518a07fd15c3d71000fe0d1b99328" dependencies = [ "arrayvec", "indexmap 2.2.6", @@ -5767,9 +5774,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af71660a9c76b542d1e42a9d5bec7ae061c6969fc742f024a53c474a5a57bd3" +checksum = "a49f6ab5fa19498d0feb45a4943e1ad962736ee251e8f0f885330f7aeca39c39" dependencies = [ "either", "new_debug_unreachable", @@ -5789,9 +5796,9 @@ dependencies = [ [[package]] name = "swc_ecma_preset_env" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbaaa45a4900566137daaa092ab6d486ca07aa1019fe2336ca6839f665034c48" +checksum = "cfe5e2978c94c480735ac2153e082cf3cdd25b27eb5b6e8053b11275a64ee7a5" dependencies = [ "anyhow", "dashmap 5.5.3", @@ -5814,9 +5821,9 @@ dependencies = [ [[package]] name = "swc_ecma_quote_macros" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "400f606bcc8576c1fd0e8f278ae5f8e405f8f575917eef9e7acff3ab483b53cb" +checksum = "f48adb2e1ae349888f8a0bcbd0a8f2045551073b8426a86fc6576389ee8ec524" dependencies = [ "anyhow", "proc-macro2", @@ -5831,9 +5838,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0646ade61000feaff7a4b1a1ff326b86e156f1bb9fd462a8f246ce171037723" +checksum = "8a3e411329a10c03a9d7a006be3e0b556bf6ab7f557466e681f8fdedb6551122" dependencies = [ "swc_atoms", "swc_common", @@ -5851,9 +5858,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c09e305178eb251f9115ee765842f3e27589c079bee265c85658582de46cb8d6" +checksum = "46acfbf848da60fadd98b707efef90c5f8ed8542509078c083d65e4f9dc214da" dependencies = [ "better_scoped_tls", "bitflags 2.5.0", @@ -5875,9 +5882,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08b7446902482d5b132bccafee83172c98fd7b07b7ab1df863d9cfb2c0d3ff3e" +checksum = "8edd0cf96f8f06071e164343829eb393e5824e0fd9fecfe02188448a29751b80" dependencies = [ "swc_atoms", "swc_common", @@ -5889,9 +5896,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_compat" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be6ada1ae8e7495852a1645bbac4d1e87fe7fc4d061ce6256d2466c25295065" +checksum = "66fe50b2f009c63d4e77a4fa9001af7c04be58824bc9748f576b614c65e80e9b" dependencies = [ "arrayvec", "indexmap 2.2.6", @@ -5937,9 +5944,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_module" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4235ddd644e14a7b7a7f068640f353136858bf7987694122cc00fdc964d61fea" +checksum = "25f8b1f049d172e4b83167751293728ce0c4692e364c1ffbce7af35bb7dad855" dependencies = [ "Inflector", "anyhow", @@ -5964,9 +5971,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05703e5671b838797b8bae42baf29be7a4541e8ab7c03ee3587689ad37ff71bd" +checksum = "30019eed0d2bf516f08216c87c89e372c91750c1bae8a3254335c5f6ad044852" dependencies = [ "dashmap 5.5.3", "indexmap 2.2.6", @@ -5989,9 +5996,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07e74fddfd7dc82368257a678ff9683566ae3d99cacee2831959d60ba76ddc2" +checksum = "c3090cde1901f95b5430171709acc319cd36acda5c2a4a77706656ede5fbdd4f" dependencies = [ "either", "rustc-hash 1.1.0", @@ -6009,9 +6016,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b6432ee6b1f232c7d5eb21eefa363802aba8683f11f215eb3c58d4e43d924f" +checksum = "dff97567117214938c3a5f397cd9c4ecb5945778982d918471b9623da351f1f0" dependencies = [ "base64 0.21.7", "dashmap 5.5.3", @@ -6034,9 +6041,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e2d6d68482f78da5e68105b706aa0023b78fa16b6a82b1f72d1b7de8d349960" +checksum = "0c4056d06593b73a3149530fdbd4f44e7692cb801c03750ec874c1753b68c6c6" dependencies = [ "ryu-js", "serde", @@ -6051,9 +6058,9 @@ dependencies = [ [[package]] name = "swc_ecma_usage_analyzer" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "215b4b4953eba739e825d7e7d70270fa884d8ae4c24d463e9f9c477c857cdabe" +checksum = "c85c31dad1d402a52394eb184742a7095ba02277c55df327b89fb8bd65e59a7c" dependencies = [ "indexmap 2.2.6", "rustc-hash 1.1.0", @@ -6068,9 +6075,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "860ebda7452f4c6d3ef37f4e781a7d130cd5698e20044d07484ad85ab14d5324" +checksum = "9371e7e39fca55508ae91abf28fd3d8dae8eff3782e918081f6932523c68789c" dependencies = [ "indexmap 2.2.6", "num_cpus", @@ -6088,9 +6095,9 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b666a2d56c29f7535c158d8f70b7750436cad62cc356953d3ed550e4607ed" +checksum = "a380252c317c67f321b8e0d66dbc2427842bd184505e12016f0d3f811776af86" dependencies = [ "new_debug_unreachable", "num-bigint", @@ -6114,9 +6121,9 @@ dependencies = [ [[package]] name = "swc_error_reporters" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9f077f41ae28feb53f73c84f59f6e992c6e74b1e7ea65c6eb7dd0f2b5c17b5f" +checksum = "44f6ddeea4e330922832e5f1544f8097b46b786c86d200eb3a6ef761ba83ce12" dependencies = [ "anyhow", "miette 7.2.0", @@ -6127,9 +6134,9 @@ dependencies = [ [[package]] name = "swc_fast_graph" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "780bf429bd56049d2ca2678e6ac3304a1f178327550eec52b04a7932c300b497" +checksum = "b1b3add3571bc073f49b4f4fb4326f54c24fe7799296e0ad5341af895150e79c" dependencies = [ "indexmap 2.2.6", "petgraph", @@ -6139,9 +6146,9 @@ dependencies = [ [[package]] name = "swc_html" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fdadc2bcf53c7853d6464338abf595d438034339ad9fe8cf9ef6fce2a357d77" +checksum = "6c673bf52372599ab75bb087f90eb2f1c205e6ce0303398aa64e8e68c3cbcc6f" dependencies = [ "swc_html_ast", "swc_html_codegen", @@ -6151,9 +6158,9 @@ dependencies = [ [[package]] name = "swc_html_ast" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f775c4a26fe724f0bb847cea66830678d20f217bf2e6a98c7e322025ce94eba" +checksum = "2a551d9898a7528b652b19fb4b1003450aee5b5f6e7182b89aadb832d9fe3ca5" dependencies = [ "is-macro", "string_enum", @@ -6163,9 +6170,9 @@ dependencies = [ [[package]] name = "swc_html_codegen" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b34a3e0a30dbd22182f8ada3e97dd95ef2aa7e6f2ea755c1915a05a5f13fa0f4" +checksum = "12419d070a0d184f599e804394d357d5c05f9a4264543ab62a057429ba86a95d" dependencies = [ "auto_impl", "bitflags 2.5.0", @@ -6191,9 +6198,9 @@ dependencies = [ [[package]] name = "swc_html_minifier" -version = "3.0.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2079e1e09525f3da212ba0c440bc65da0dfee1a3578ea1d25048805a4ac8bc8a" +checksum = "72cd273c60195f88ab0651492c8a223923dc91d42602dec07555900aff648d44" dependencies = [ "once_cell", "serde", @@ -6216,9 +6223,9 @@ dependencies = [ [[package]] name = "swc_html_parser" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "742129ab25e26dd70c9a78ea2dd520896f49373e4e781797684a5520810bcf23" +checksum = "fb4f2850e8108394c5cdd4f3a3b4715eb99acd4fed30e6da35f090414f13af61" dependencies = [ "swc_atoms", "swc_common", @@ -6228,9 +6235,9 @@ dependencies = [ [[package]] name = "swc_html_utils" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e17d1db98068a7f00261019c29637fa7552a251d3bb38a3b993329fd8a4257b7" +checksum = "c17d92636f5e4c64bb9417eb69c97ae5d45d1915f6e97d22c36e1621d53867be" dependencies = [ "once_cell", "serde", @@ -6241,9 +6248,9 @@ dependencies = [ [[package]] name = "swc_html_visit" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f3c962a7d5a5e79029af143ad64a182b2c18277e7f47d8e7791a7004be510d" +checksum = "191ea427c86b7f7c0fe07db1047de818c5a4f7076ddf97aa779d636a6941f794" dependencies = [ "serde", "swc_atoms", @@ -6265,9 +6272,9 @@ dependencies = [ [[package]] name = "swc_node_comments" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "782b6885d35056d93d8370426e0dffa7aba514250e5bd54dea312b35c7704f6a" +checksum = "3e4b8a903dde91bb4fc335508145d62b3c16eefb825e8457edaab57f6a8b6d91" dependencies = [ "dashmap 5.5.3", "swc_atoms", @@ -6288,9 +6295,9 @@ dependencies = [ [[package]] name = "swc_plugin_proxy" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43330668909c0db594e6779754c4e53c249b4f3c9c7ea1af6668ff028f7072e6" +checksum = "676d058cb956ea0ec542b47930b22b045c388cac6d43c2afac83687b2e560957" dependencies = [ "better_scoped_tls", "rkyv 0.7.45", @@ -6302,9 +6309,9 @@ dependencies = [ [[package]] name = "swc_plugin_runner" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c88b8d131b40a85482143089082dc32e3557e4cb05fc1ac1676fa48bc917e58" +checksum = "f0f16f595767d7ab0b962a9b59f3ec5ea0c8a205e0e0940ef5ee3a1b39d3dc0c" dependencies = [ "anyhow", "enumset", @@ -6361,9 +6368,9 @@ dependencies = [ [[package]] name = "swc_typescript" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddce3a99df78efd73b3401ee9893165f571d1fa867d8c46bca69a8a23e0844c5" +checksum = "b70dfbda2233c81ecd0da521c6b2e1b318a7f57dc0e8186b7157ed5576db1e02" dependencies = [ "swc_atoms", "swc_common", diff --git a/Cargo.toml b/Cargo.toml index 2b840a97e7b..16db5eb9b58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ parcel_sourcemap = { version = "2.1.1" } paste = { version = "1.0" } path-clean = { version = "1.0.1" } pathdiff = { version = "0.2.1" } +pollster = { version = "*" } proc-macro2 = { version = "1.0.79" } quote = { version = "1.0.35" } rayon = { version = "1.10.0" } @@ -79,12 +80,12 @@ rkyv = { version = "=0.8.8" } # Must be pinned with the same swc versions swc_config = { version = "=1.0.0" } -swc_core = { version = "=3.0.1", default-features = false } -swc_ecma_minifier = { version = "=3.0.0", default-features = false } -swc_error_reporters = { version = "=3.0.0" } -swc_html = { version = "=3.0.0" } -swc_html_minifier = { version = "=3.0.0", default-features = false } -swc_node_comments = { version = "=2.0.0" } +swc_core = { version = "=4.0.0", default-features = false } +swc_ecma_minifier = { version = "=4.0.0", default-features = false } +swc_error_reporters = { version = "=4.0.0" } +swc_html = { version = "=4.0.0" } +swc_html_minifier = { version = "=4.0.0", default-features = false } +swc_node_comments = { version = "=3.0.0" } rspack_dojang = { version = "0.1.9" } [workspace.metadata.release] diff --git a/crates/rspack_binding_options/Cargo.toml b/crates/rspack_binding_options/Cargo.toml index d8c0661f871..04842b10b08 100644 --- a/crates/rspack_binding_options/Cargo.toml +++ b/crates/rspack_binding_options/Cargo.toml @@ -19,6 +19,7 @@ derivative = { workspace = true } glob = { workspace = true } napi = { workspace = true, features = ["async", "tokio_rt", "serde-json", "anyhow"] } napi-derive = { workspace = true } +pollster = { workspace = true } rspack_binding_values = { version = "0.1.0", path = "../rspack_binding_values" } rspack_collections = { version = "0.1.0", path = "../rspack_collections" } rspack_core = { version = "0.1.0", path = "../rspack_core" } diff --git a/crates/rspack_binding_options/src/options/raw_module/mod.rs b/crates/rspack_binding_options/src/options/raw_module/mod.rs index ad97e51a9e5..975d979789d 100644 --- a/crates/rspack_binding_options/src/options/raw_module/mod.rs +++ b/crates/rspack_binding_options/src/options/raw_module/mod.rs @@ -22,7 +22,6 @@ use rspack_error::error; use rspack_napi::regexp::{JsRegExp, JsRegExpExt}; use rspack_napi::threadsafe_function::ThreadsafeFunction; use rspack_regex::RspackRegex; -use tokio::runtime::Handle; use crate::RawResolveOptions; @@ -586,10 +585,10 @@ impl From for RawAssetGeneratorDataUrlFnArgs { impl From for AssetGeneratorDataUrl { fn from(value: RawAssetGeneratorDataUrlWrapper) -> Self { - let handle = Handle::current(); + use pollster::block_on; match value.0 { Either::A(a) => Self::Options(a.into()), - Either::B(b) => Self::Func(Arc::new(move |ctx| handle.block_on(b.call(ctx.into())))), + Either::B(b) => Self::Func(Arc::new(move |ctx| block_on(b.call(ctx.into())))), } } } diff --git a/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_cache_group_test.rs b/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_cache_group_test.rs index 0ffeb3d7154..192145b2337 100644 --- a/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_cache_group_test.rs +++ b/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_cache_group_test.rs @@ -6,7 +6,6 @@ use rspack_binding_values::JsModuleWrapper; use rspack_napi::regexp::{JsRegExp, JsRegExpExt}; use rspack_napi::threadsafe_function::ThreadsafeFunction; use rspack_plugin_split_chunks::{CacheGroupTest, CacheGroupTestFnCtx}; -use tokio::runtime::Handle; pub(super) type RawCacheGroupTest = Either3>>; @@ -35,11 +34,11 @@ impl<'a> From> for JsCacheGroupTestCtx { } pub(super) fn normalize_raw_cache_group_test(raw: RawCacheGroupTest) -> CacheGroupTest { - let handle = Handle::current(); + use pollster::block_on; match raw { Either3::A(str) => CacheGroupTest::String(str), Either3::B(regexp) => CacheGroupTest::RegExp(regexp.to_rspack_regex()), - Either3::C(v) => CacheGroupTest::Fn(Arc::new(move |ctx| handle.block_on(v.call(ctx.into())))), + Either3::C(v) => CacheGroupTest::Fn(Arc::new(move |ctx| block_on(v.call(ctx.into())))), } } diff --git a/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_chunks.rs b/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_chunks.rs index c6eef7fa497..39197cd0c0f 100644 --- a/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_chunks.rs +++ b/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_chunks.rs @@ -5,12 +5,11 @@ use rspack_binding_values::JsChunk; use rspack_napi::regexp::{JsRegExp, JsRegExpExt}; use rspack_napi::string::JsStringExt; use rspack_napi::threadsafe_function::ThreadsafeFunction; -use tokio::runtime::Handle; pub type Chunks = Either3>; pub fn create_chunks_filter(raw: Chunks) -> rspack_plugin_split_chunks::ChunkFilter { - let handle = Handle::current(); + use pollster::block_on; match raw { Either3::A(reg) => { rspack_plugin_split_chunks::create_regex_chunk_filter_from_str(reg.to_rspack_regex()) @@ -19,6 +18,6 @@ pub fn create_chunks_filter(raw: Chunks) -> rspack_plugin_split_chunks::ChunkFil let js_str = js_str.into_string(); rspack_plugin_split_chunks::create_chunk_filter_from_str(&js_str) } - Either3::C(f) => Arc::new(move |chunk, _| handle.block_on(f.call(JsChunk::from(chunk)))), + Either3::C(f) => Arc::new(move |chunk, _| block_on(f.call(JsChunk::from(chunk)))), } } diff --git a/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_name.rs b/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_name.rs index c6f1659c388..76ed8b101f8 100644 --- a/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_name.rs +++ b/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_name.rs @@ -6,7 +6,6 @@ use rspack_binding_values::{JsChunk, JsModuleWrapper}; use rspack_core::Chunk; use rspack_napi::threadsafe_function::ThreadsafeFunction; use rspack_plugin_split_chunks::{ChunkNameGetter, ChunkNameGetterFnCtx}; -use tokio::runtime::Handle; pub(super) type RawChunkOptionName = Either3>>; @@ -48,10 +47,10 @@ impl<'a> From> for RawChunkOptionNameCtx { } pub(super) fn normalize_raw_chunk_name(raw: RawChunkOptionName) -> ChunkNameGetter { - let handle = Handle::current(); + use pollster::block_on; match raw { Either3::A(str) => ChunkNameGetter::String(str), Either3::B(_) => ChunkNameGetter::Disabled, // FIXME: when set bool is true? - Either3::C(v) => ChunkNameGetter::Fn(Arc::new(move |ctx| handle.block_on(v.call(ctx.into())))), + Either3::C(v) => ChunkNameGetter::Fn(Arc::new(move |ctx| block_on(v.call(ctx.into())))), } } diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index 53c0edb9d75..458e55e09fc 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -745,7 +745,7 @@ impl Compilation { } let artifact = std::mem::take(&mut self.make_artifact); - self.make_artifact = make_module_graph(self, artifact)?; + self.make_artifact = make_module_graph(self, artifact).await?; Ok(()) } @@ -759,7 +759,8 @@ impl Compilation { self, artifact, vec![MakeParam::ForceBuildModules(module_identifiers.clone())], - )?; + ) + .await?; let module_graph = self.get_module_graph(); Ok(f(module_identifiers @@ -1066,7 +1067,8 @@ impl Compilation { .copied() .collect(), )], - )?; + ) + .await?; // sync assets to compilation from module_executor if let Some(module_executor) = &mut self.module_executor { diff --git a/crates/rspack_core/src/compiler/make/mod.rs b/crates/rspack_core/src/compiler/make/mod.rs index 8c1b4d844a1..c3d22ac5c8f 100644 --- a/crates/rspack_core/src/compiler/make/mod.rs +++ b/crates/rspack_core/src/compiler/make/mod.rs @@ -103,7 +103,7 @@ pub enum MakeParam { ForceBuildModules(IdentifierSet), } -pub fn make_module_graph( +pub async fn make_module_graph( compilation: &Compilation, mut artifact: MakeArtifact, ) -> Result { @@ -142,18 +142,18 @@ pub fn make_module_graph( artifact.diagnostics = Default::default(); artifact.has_module_graph_change = false; - artifact = update_module_graph(compilation, artifact, params)?; + artifact = update_module_graph(compilation, artifact, params).await?; Ok(artifact) } -pub fn update_module_graph( +pub async fn update_module_graph( compilation: &Compilation, mut artifact: MakeArtifact, params: Vec, ) -> Result { let mut cutout = Cutout::default(); let build_dependencies = cutout.cutout_artifact(&mut artifact, params); - artifact = repair(compilation, artifact, build_dependencies)?; + artifact = repair(compilation, artifact, build_dependencies).await?; cutout.fix_artifact(&mut artifact); Ok(artifact) } diff --git a/crates/rspack_core/src/compiler/make/repair/add.rs b/crates/rspack_core/src/compiler/make/repair/add.rs index 530ffd83a76..1c3df6051bd 100644 --- a/crates/rspack_core/src/compiler/make/repair/add.rs +++ b/crates/rspack_core/src/compiler/make/repair/add.rs @@ -15,12 +15,12 @@ pub struct AddTask { pub dependencies: Vec, pub current_profile: Option>, } - +#[async_trait::async_trait] impl Task for AddTask { fn get_task_type(&self) -> TaskType { TaskType::Sync } - fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + async fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { let module_identifier = self.module.identifier(); let artifact = &mut context.artifact; let module_graph = diff --git a/crates/rspack_core/src/compiler/make/repair/build.rs b/crates/rspack_core/src/compiler/make/repair/build.rs index 9992d8bd364..be4bfe52ee8 100644 --- a/crates/rspack_core/src/compiler/make/repair/build.rs +++ b/crates/rspack_core/src/compiler/make/repair/build.rs @@ -94,12 +94,12 @@ struct BuildResultTask { pub diagnostics: Vec, pub current_profile: Option>, } - +#[async_trait::async_trait] impl Task for BuildResultTask { fn get_task_type(&self) -> TaskType { TaskType::Sync } - fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + async fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { let BuildResultTask { mut module, build_result, diff --git a/crates/rspack_core/src/compiler/make/repair/factorize.rs b/crates/rspack_core/src/compiler/make/repair/factorize.rs index a86e7ef11aa..47c3f27e1bd 100644 --- a/crates/rspack_core/src/compiler/make/repair/factorize.rs +++ b/crates/rspack_core/src/compiler/make/repair/factorize.rs @@ -197,11 +197,12 @@ impl FactorizeResultTask { } } +#[async_trait::async_trait] impl Task for FactorizeResultTask { fn get_task_type(&self) -> TaskType { TaskType::Sync } - fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + async fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { let FactorizeResultTask { original_module_identifier, factory_result, diff --git a/crates/rspack_core/src/compiler/make/repair/mod.rs b/crates/rspack_core/src/compiler/make/repair/mod.rs index 361a3625cf5..ee2d10411ad 100644 --- a/crates/rspack_core/src/compiler/make/repair/mod.rs +++ b/crates/rspack_core/src/compiler/make/repair/mod.rs @@ -82,7 +82,7 @@ impl MakeTaskContext { } } -pub fn repair( +pub async fn repair( compilation: &Compilation, mut artifact: MakeArtifact, build_dependencies: HashSet, @@ -140,6 +140,6 @@ pub fn repair( .collect::>(); let mut ctx = MakeTaskContext::new(compilation, artifact); - run_task_loop(&mut ctx, init_tasks)?; + run_task_loop(&mut ctx, init_tasks).await?; Ok(ctx.transform_to_make_artifact()) } diff --git a/crates/rspack_core/src/compiler/make/repair/process_dependencies.rs b/crates/rspack_core/src/compiler/make/repair/process_dependencies.rs index 818633f3632..def63b7a81d 100644 --- a/crates/rspack_core/src/compiler/make/repair/process_dependencies.rs +++ b/crates/rspack_core/src/compiler/make/repair/process_dependencies.rs @@ -13,13 +13,13 @@ pub struct ProcessDependenciesTask { pub original_module_identifier: ModuleIdentifier, pub dependencies: Vec, } - +#[async_trait::async_trait] impl Task for ProcessDependenciesTask { fn get_task_type(&self) -> TaskType { TaskType::Sync } - fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + async fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { let Self { original_module_identifier, dependencies, diff --git a/crates/rspack_core/src/compiler/module_executor/ctrl.rs b/crates/rspack_core/src/compiler/module_executor/ctrl.rs index c230597f93b..e4e85a23382 100644 --- a/crates/rspack_core/src/compiler/module_executor/ctrl.rs +++ b/crates/rspack_core/src/compiler/module_executor/ctrl.rs @@ -196,13 +196,13 @@ struct FinishModuleTask { ctrl_task: Box, module_identifier: ModuleIdentifier, } - +#[async_trait::async_trait] impl Task for FinishModuleTask { fn get_task_type(&self) -> TaskType { TaskType::Sync } - fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + async fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { let Self { mut ctrl_task, module_identifier, diff --git a/crates/rspack_core/src/compiler/module_executor/entry.rs b/crates/rspack_core/src/compiler/module_executor/entry.rs index 8e97910d938..95d61b5ad9c 100644 --- a/crates/rspack_core/src/compiler/module_executor/entry.rs +++ b/crates/rspack_core/src/compiler/module_executor/entry.rs @@ -9,13 +9,13 @@ pub struct EntryTask { pub dep: Box, pub layer: Option, } - +#[async_trait::async_trait] impl Task for EntryTask { fn get_task_type(&self) -> TaskType { TaskType::Sync } - fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + async fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { let Self { dep, layer } = *self; let mut module_graph = MakeTaskContext::get_module_graph_mut(&mut context.artifact.module_graph_partial); diff --git a/crates/rspack_core/src/compiler/module_executor/execute.rs b/crates/rspack_core/src/compiler/module_executor/execute.rs index 7f8ec7dad12..bd935e45641 100644 --- a/crates/rspack_core/src/compiler/module_executor/execute.rs +++ b/crates/rspack_core/src/compiler/module_executor/execute.rs @@ -6,7 +6,7 @@ use rspack_collections::{Identifier, IdentifierSet}; use rspack_error::Result; use rustc_hash::FxHashMap as HashMap; use rustc_hash::FxHashSet as HashSet; -use tokio::{runtime::Handle, sync::oneshot::Sender}; +use tokio::sync::oneshot::Sender; use crate::{ compiler::make::repair::MakeTaskContext, @@ -54,13 +54,13 @@ pub struct ExecuteTask { Vec, )>, } - +#[async_trait::async_trait] impl Task for ExecuteTask { fn get_task_type(&self) -> TaskType { TaskType::Sync } - fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + async fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { let Self { entry_dep_id, layer, @@ -162,18 +162,14 @@ impl Task for ExecuteTask { compilation.create_module_hashes(modules.clone())?; compilation.code_generation_modules(&mut None, modules.clone())?; - - Handle::current().block_on(async { - compilation - .process_runtime_requirements( - modules.clone(), - once(chunk_ukey), - once(chunk_ukey), - compilation.plugin_driver.clone(), - ) - .await - })?; - + compilation + .process_runtime_requirements( + modules.clone(), + once(chunk_ukey), + once(chunk_ukey), + compilation.plugin_driver.clone(), + ) + .await?; let runtime_modules = compilation .chunk_graph .get_chunk_runtime_modules_iterable(&chunk_ukey) diff --git a/crates/rspack_core/src/compiler/module_executor/mod.rs b/crates/rspack_core/src/compiler/module_executor/mod.rs index 6def179e6ae..8bcfc83c31b 100644 --- a/crates/rspack_core/src/compiler/module_executor/mod.rs +++ b/crates/rspack_core/src/compiler/module_executor/mod.rs @@ -64,7 +64,9 @@ impl ModuleExecutor { make_artifact.diagnostics = Default::default(); make_artifact.has_module_graph_change = false; - make_artifact = update_module_graph(compilation, make_artifact, params).unwrap_or_default(); + make_artifact = update_module_graph(compilation, make_artifact, params) + .await + .unwrap_or_default(); let mut ctx = MakeTaskContext::new(compilation, make_artifact); let (event_sender, event_receiver) = unbounded_channel(); @@ -82,7 +84,8 @@ impl ModuleExecutor { event_sender: event_sender.clone(), }) }, - ); + ) + .await; stop_sender .send(ctx.transform_to_make_artifact()) diff --git a/crates/rspack_core/src/compiler/module_executor/overwrite.rs b/crates/rspack_core/src/compiler/module_executor/overwrite.rs index b73d75aee2c..5931540ed46 100644 --- a/crates/rspack_core/src/compiler/module_executor/overwrite.rs +++ b/crates/rspack_core/src/compiler/module_executor/overwrite.rs @@ -21,7 +21,7 @@ impl Task for OverwriteTask { self.origin_task.get_task_type() } - fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + async fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { let Self { origin_task, event_sender, @@ -32,7 +32,7 @@ impl Task for OverwriteTask { .downcast_ref::() { let original_module_identifier = process_dependencies_task.original_module_identifier; - let res = origin_task.sync_run(context)?; + let res = origin_task.sync_run(context).await?; event_sender .send(Event::FinishModule(original_module_identifier, res.len())) .expect("should success"); @@ -44,7 +44,7 @@ impl Task for OverwriteTask { { let dep_id = *factorize_result_task.dependencies[0].id(); let original_module_identifier = factorize_result_task.original_module_identifier; - let res = origin_task.sync_run(context)?; + let res = origin_task.sync_run(context).await?; if res.is_empty() { event_sender .send(Event::FinishDeps(original_module_identifier, dep_id, None)) @@ -58,7 +58,7 @@ impl Task for OverwriteTask { let original_module_identifier = add_task.original_module_identifier; let target_module_identifier = add_task.module.identifier(); - let res = origin_task.sync_run(context)?; + let res = origin_task.sync_run(context).await?; if res.is_empty() { event_sender .send(Event::FinishDeps( @@ -76,7 +76,7 @@ impl Task for OverwriteTask { } // other task - origin_task.sync_run(context) + origin_task.sync_run(context).await } async fn async_run(self: Box) -> TaskResult { diff --git a/crates/rspack_core/src/utils/mod.rs b/crates/rspack_core/src/utils/mod.rs index 27e4454b3a1..c75fc94b084 100644 --- a/crates/rspack_core/src/utils/mod.rs +++ b/crates/rspack_core/src/utils/mod.rs @@ -9,7 +9,6 @@ use rustc_hash::FxHashMap as HashMap; use crate::{ BoxModule, ChunkGraph, ChunkGroupByUkey, ChunkGroupUkey, ChunkUkey, Compilation, ModuleGraph, }; - mod comment; mod compile_boolean_matcher; mod concatenated_module_visitor; diff --git a/crates/rspack_core/src/utils/task_loop.rs b/crates/rspack_core/src/utils/task_loop.rs index 170480ea5b0..5fc1ecfd091 100644 --- a/crates/rspack_core/src/utils/task_loop.rs +++ b/crates/rspack_core/src/utils/task_loop.rs @@ -10,10 +10,7 @@ use std::{ use rspack_error::Result; use rspack_util::ext::AsAny; -use tokio::{ - runtime::Handle, - sync::mpsc::{self, error::TryRecvError}, -}; +use tokio::sync::mpsc::{self, error::TryRecvError}; /// Result returned by task /// @@ -42,7 +39,7 @@ pub trait Task: Debug + Send + Any + AsAny { /// Sync task process /// /// The context is shared with all tasks - fn sync_run(self: Box, _context: &mut Ctx) -> TaskResult { + async fn sync_run(self: Box, _context: &mut Ctx) -> TaskResult { unreachable!(); } @@ -53,15 +50,15 @@ pub trait Task: Debug + Send + Any + AsAny { } /// Run task loop -pub fn run_task_loop( +pub async fn run_task_loop( ctx: &mut Ctx, init_tasks: Vec>>, ) -> Result<()> { - run_task_loop_with_event(ctx, init_tasks, |_, task| task) + run_task_loop_with_event(ctx, init_tasks, |_, task| task).await } /// Run task loop with event -pub fn run_task_loop_with_event( +pub async fn run_task_loop_with_event( ctx: &mut Ctx, init_tasks: Vec>>, before_task_run: impl Fn(&mut Ctx, Box>) -> Box>, @@ -73,7 +70,7 @@ pub fn run_task_loop_with_event( let is_expected_shutdown: Arc = Arc::new(AtomicBool::new(false)); let mut queue: VecDeque>> = VecDeque::from(init_tasks); let mut active_task_count = 0; - tokio::task::block_in_place(|| loop { + loop { let task = queue.pop_front(); if task.is_none() && active_task_count == 0 { return Ok(()); @@ -95,7 +92,7 @@ pub fn run_task_loop_with_event( } TaskType::Sync => { // merge sync task result directly - match task.sync_run(ctx) { + match task.sync_run(ctx).await { Ok(r) => queue.extend(r), Err(e) => { is_expected_shutdown.store(true, Ordering::Relaxed); @@ -107,10 +104,8 @@ pub fn run_task_loop_with_event( } let data = if queue.is_empty() && active_task_count != 0 { - Handle::current().block_on(async { - let res = rx.recv().await.expect("should recv success"); - Ok(res) - }) + let res = rx.recv().await.expect("should recv success"); + Ok(res) } else { rx.try_recv() }; @@ -132,7 +127,7 @@ pub fn run_task_loop_with_event( panic!("unexpected recv error") } } - }) + } } #[cfg(test)] @@ -151,11 +146,12 @@ mod test { #[derive(Debug)] struct SyncTask; + #[async_trait::async_trait] impl Task for SyncTask { fn get_task_type(&self) -> TaskType { TaskType::Sync } - fn sync_run(self: Box, context: &mut Context) -> TaskResult { + async fn sync_run(self: Box, context: &mut Context) -> TaskResult { if context.sync_return_error { return Err(miette!("throw sync error")); } @@ -204,7 +200,8 @@ mod test { vec![Box::new(AsyncTask { async_return_error: false, })], - ); + ) + .await; assert!(res.is_ok(), "task loop should be run success"); assert_eq!(context.call_sync_task_count, 7); @@ -219,7 +216,8 @@ mod test { vec![Box::new(AsyncTask { async_return_error: false, })], - ); + ) + .await; assert!( format!("{:?}", res).contains("throw sync error"), "should return sync error" @@ -237,7 +235,8 @@ mod test { vec![Box::new(AsyncTask { async_return_error: false, })], - ); + ) + .await; assert!( format!("{:?}", res).contains("throw async error"), "should return async error" diff --git a/crates/rspack_loader_swc/Cargo.toml b/crates/rspack_loader_swc/Cargo.toml index 1d1891a62a7..c955b766297 100644 --- a/crates/rspack_loader_swc/Cargo.toml +++ b/crates/rspack_loader_swc/Cargo.toml @@ -6,7 +6,8 @@ name = "rspack_loader_swc" repository = "https://github.com/web-infra-dev/rspack" version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - +[package.metadata.cargo-shear] +ignored = ["swc"] [features] default = [] plugin = [ @@ -31,8 +32,8 @@ rspack_util = { version = "0.1.0", path = "../rspack_util" } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } stacker = { workspace = true } +swc = { version = "4.0.0", features = ["manual-tokio-runtmie"] } swc_config = { workspace = true } swc_core = { workspace = true, features = ["base", "ecma_ast", "common"] } swc_plugin_import = { version = "0.1.5", path = "../swc_plugin_import" } -tokio = { workspace = true } url = "2.5.0" diff --git a/crates/rspack_loader_swc/src/lib.rs b/crates/rspack_loader_swc/src/lib.rs index d796ee989a1..8b920b9644c 100644 --- a/crates/rspack_loader_swc/src/lib.rs +++ b/crates/rspack_loader_swc/src/lib.rs @@ -122,7 +122,7 @@ impl SwcLoader { keep_comments: Some(true), }; - let program = tokio::task::block_in_place(|| c.transform(built).map_err(AnyhowError::from))?; + let program = c.transform(built).map_err(AnyhowError::from)?; if source_map_kind.enabled() { let mut v = IdentCollector { names: Default::default(), diff --git a/crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs b/crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs index 0629a8f49a4..3f6b86de34a 100644 --- a/crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs +++ b/crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs @@ -350,165 +350,168 @@ impl SourceMapDevToolPlugin { } } - mapped_sources - .into_par_iter() + let futures = mapped_sources + .into_iter() .map(|(filename, source, source_map)| { - let source_map_json = match source_map { - Some(map) => Some(map.to_json().into_diagnostic()?), - None => None, - }; - - let mut asset = compilation - .assets() - .get(&filename) - .unwrap_or_else(|| { - panic!( - "expected to find filename '{}' in compilation.assets, but it was not present", - &filename - ) - }) - .clone(); - let Some(source_map_json) = source_map_json else { - return Ok(MappedAsset { - asset: (filename, asset), - source_map: None, - }); - }; - let css_extension_detected = CSS_EXTENSION_DETECT_REGEXP.is_match(&filename); - let current_source_mapping_url_comment = match &self.source_mapping_url_comment { - Some(SourceMappingUrlComment::String(s)) => { - let s = if css_extension_detected { - URL_FORMATTING_REGEXP.replace_all(s, "\n/*$1*/") - } else { - Cow::from(s) - }; - Some(SourceMappingUrlCommentRef::String(s)) - } - Some(SourceMappingUrlComment::Fn(f)) => Some(SourceMappingUrlCommentRef::Fn(f)), - None => None, - }; - - if let Some(source_map_filename_config) = &self.source_map_filename { - let chunk = file_to_chunk.get(&filename); - let source_type = if css_extension_detected { - &SourceType::Css - } else { - &SourceType::JavaScript + async { + let source_map_json = match source_map { + Some(map) => Some(map.to_json().into_diagnostic()?), + None => None, }; - let filename = match &self.file_context { - Some(file_context) => Cow::Owned( - relative(Path::new(file_context), Path::new(&filename)) - .to_string_lossy() - .to_string(), - ), - None => Cow::Borrowed(&filename), + + let mut asset = compilation + .assets() + .get(&filename) + .unwrap_or_else(|| { + panic!( + "expected to find filename '{}' in compilation.assets, but it was not present", + &filename + ) + }) + .clone(); + let Some(source_map_json) = source_map_json else { + return Ok(MappedAsset { + asset: (filename, asset), + source_map: None, + }); }; - let data = PathData::default().filename(&filename); - let data = match chunk { - Some(chunk) => data - .chunk(chunk) - .content_hash_optional(chunk.content_hash.get(source_type).map(|i| i.encoded())), - None => data, + let css_extension_detected = CSS_EXTENSION_DETECT_REGEXP.is_match(&filename); + let current_source_mapping_url_comment = match &self.source_mapping_url_comment { + Some(SourceMappingUrlComment::String(s)) => { + let s = if css_extension_detected { + URL_FORMATTING_REGEXP.replace_all(s, "\n/*$1*/") + } else { + Cow::from(s) + }; + Some(SourceMappingUrlCommentRef::String(s)) + } + Some(SourceMappingUrlComment::Fn(f)) => Some(SourceMappingUrlCommentRef::Fn(f)), + None => None, }; - let source_map_filename = compilation - .get_asset_path(source_map_filename_config, data) - .always_ok(); - if let Some(current_source_mapping_url_comment) = current_source_mapping_url_comment { - let source_map_url = if let Some(public_path) = &self.public_path { - format!("{public_path}{source_map_filename}") + if let Some(source_map_filename_config) = &self.source_map_filename { + let chunk = file_to_chunk.get(&filename); + let source_type = if css_extension_detected { + &SourceType::Css } else { - let mut file_path = PathBuf::new(); - file_path.push(Component::RootDir); - file_path.extend(Path::new(filename.as_ref()).components()); - - let mut source_map_path = PathBuf::new(); - source_map_path.push(Component::RootDir); - source_map_path.extend(Path::new(&source_map_filename).components()); - - relative( - #[allow(clippy::unwrap_used)] - file_path.parent().unwrap(), - &source_map_path, - ) - .to_string_lossy() - .to_string() + &SourceType::JavaScript + }; + let filename = match &self.file_context { + Some(file_context) => Cow::Owned( + relative(Path::new(file_context), Path::new(&filename)) + .to_string_lossy() + .to_string(), + ), + None => Cow::Borrowed(&filename), + }; + let data = PathData::default().filename(&filename); + let data = match chunk { + Some(chunk) => data + .chunk(chunk) + .content_hash_optional(chunk.content_hash.get(source_type).map(|i| i.encoded())), + None => data, }; - let data = data.url(&source_map_url); + let source_map_filename = compilation + .get_asset_path(source_map_filename_config, data) + .always_ok(); + + if let Some(current_source_mapping_url_comment) = current_source_mapping_url_comment { + let source_map_url = if let Some(public_path) = &self.public_path { + format!("{public_path}{source_map_filename}") + } else { + let mut file_path = PathBuf::new(); + file_path.push(Component::RootDir); + file_path.extend(Path::new(filename.as_ref()).components()); + + let mut source_map_path = PathBuf::new(); + source_map_path.push(Component::RootDir); + source_map_path.extend(Path::new(&source_map_filename).components()); + + relative( + #[allow(clippy::unwrap_used)] + file_path.parent().unwrap(), + &source_map_path, + ) + .to_string_lossy() + .to_string() + }; + let data = data.url(&source_map_url); + let current_source_mapping_url_comment = match ¤t_source_mapping_url_comment { + SourceMappingUrlCommentRef::String(s) => compilation + .get_asset_path(&FilenameTemplate::from(s.to_string()), data) + .always_ok(), + SourceMappingUrlCommentRef::Fn(f) => { + let comment = f(data).await?; + FilenameTemplate::from(comment) + .render(data, None, output_options.hash_digest_length) + .always_ok() + } + }; + asset.source = Some( + ConcatSource::new([ + source.clone(), + RawSource::from( + current_source_mapping_url_comment + .cow_replace("[url]", &source_map_url) + .into_owned(), + ) + .boxed(), + ]) + .boxed(), + ); + asset.info.related.source_map = Some(source_map_filename.clone()); + } else { + asset.source = Some(source.clone()); + } + let mut source_map_asset_info = AssetInfo::default().with_development(Some(true)); + if let Some(asset) = compilation.assets().get(filename.as_ref()) { + // set source map asset version to be the same as the target asset + source_map_asset_info.version = asset.info.version.clone(); + } + let source_map_asset = CompilationAsset::new( + Some(RawSource::from(source_map_json).boxed()), + source_map_asset_info, + ); + Ok(MappedAsset { + asset: (filename.to_string(), asset), + source_map: Some((source_map_filename, source_map_asset)), + }) + } else { + let current_source_mapping_url_comment = current_source_mapping_url_comment.expect( + "SourceMapDevToolPlugin: append can't be false when no filename is provided.", + ); let current_source_mapping_url_comment = match ¤t_source_mapping_url_comment { - SourceMappingUrlCommentRef::String(s) => compilation - .get_asset_path(&FilenameTemplate::from(s.to_string()), data) - .always_ok(), - SourceMappingUrlCommentRef::Fn(f) => { - let comment = futures::executor::block_on(f(data))?; - FilenameTemplate::from(comment) - .render(data, None, output_options.hash_digest_length) - .always_ok() + SourceMappingUrlCommentRef::String(s) => s, + SourceMappingUrlCommentRef::Fn(_) => { + return Err(error!( + "SourceMapDevToolPlugin: append can't be a function when no filename is provided" + )) } }; + let base64 = rspack_base64::encode_to_string(source_map_json.as_bytes()); asset.source = Some( ConcatSource::new([ source.clone(), RawSource::from( current_source_mapping_url_comment - .cow_replace("[url]", &source_map_url) + .cow_replace( + "[url]", + &format!("data:application/json;charset=utf-8;base64,{base64}"), + ) .into_owned(), ) .boxed(), ]) .boxed(), ); - asset.info.related.source_map = Some(source_map_filename.clone()); - } else { - asset.source = Some(source.clone()); + Ok(MappedAsset { + asset: (filename, asset), + source_map: None, + }) } - let mut source_map_asset_info = AssetInfo::default().with_development(Some(true)); - if let Some(asset) = compilation.assets().get(filename.as_ref()) { - // set source map asset version to be the same as the target asset - source_map_asset_info.version = asset.info.version.clone(); - } - let source_map_asset = CompilationAsset::new( - Some(RawSource::from(source_map_json).boxed()), - source_map_asset_info, - ); - Ok(MappedAsset { - asset: (filename.to_string(), asset), - source_map: Some((source_map_filename, source_map_asset)), - }) - } else { - let current_source_mapping_url_comment = current_source_mapping_url_comment - .expect("SourceMapDevToolPlugin: append can't be false when no filename is provided."); - let current_source_mapping_url_comment = match ¤t_source_mapping_url_comment { - SourceMappingUrlCommentRef::String(s) => s, - SourceMappingUrlCommentRef::Fn(_) => { - return Err(error!( - "SourceMapDevToolPlugin: append can't be a function when no filename is provided" - )) - } - }; - let base64 = rspack_base64::encode_to_string(source_map_json.as_bytes()); - asset.source = Some( - ConcatSource::new([ - source.clone(), - RawSource::from( - current_source_mapping_url_comment - .cow_replace( - "[url]", - &format!("data:application/json;charset=utf-8;base64,{base64}"), - ) - .into_owned(), - ) - .boxed(), - ]) - .boxed(), - ); - Ok(MappedAsset { - asset: (filename, asset), - source_map: None, - }) } - }) - .collect::>>() + }); + join_all(futures).await.into_iter().collect() } }