diff --git a/Cargo.lock b/Cargo.lock index bd48eb2311b..b6cf5d524f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,9 +128,9 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "ast_node" -version = "0.9.9" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9184f2b369b3e8625712493c89b785881f27eedc6cde480a81883cef78868b2" +checksum = "2ab31376d309dd3bfc9cfb3c11c93ce0e0741bbe0354b20e7f8c60b044730b79" dependencies = [ "proc-macro2", "quote", @@ -420,16 +420,6 @@ version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3054fea8a20d8ff3968d5b22cc27501d2b08dc4decdb31b184323f00c5ef23bb" -[[package]] -name = "cargo_toml" -version = "0.20.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad639525b1c67b6a298f378417b060fbc04618bea559482a8484381cce27d965" -dependencies = [ - "serde", - "toml 0.8.17", -] - [[package]] name = "cc" version = "1.0.79" @@ -1186,9 +1176,9 @@ dependencies = [ [[package]] name = "from_variant" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32016f1242eb82af5474752d00fd8ebcd9004bd69b462b1c91de833972d08ed4" +checksum = "fdc9cc75639b041067353b9bce2450d6847e547276c6fbe4487d7407980e07db" dependencies = [ "proc-macro2", "swc_macros_common", @@ -3360,7 +3350,6 @@ dependencies = [ "anyhow", "async-trait", "base64 0.22.1", - "cargo_toml", "dashmap 5.5.3", "either", "jsonc-parser 0.23.0", @@ -4345,9 +4334,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.7" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] @@ -4785,9 +4774,9 @@ dependencies = [ [[package]] name = "swc_cached" -version = "0.3.20" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83406221c501860fce9c27444f44125eafe9e598b8b81be7563d7036784cd05c" +checksum = "630c761c74ac8021490b78578cc2223aa4a568241e26505c27bf0e4fd4ad8ec2" dependencies = [ "ahash 0.8.11", "anyhow", @@ -4951,9 +4940,9 @@ dependencies = [ [[package]] name = "swc_ecma_codegen_macros" -version = "0.7.7" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859fabde36db38634f3fad548dd5e3410c1aebba1b67a3c63e67018fa57a0bca" +checksum = "090e409af49c8d1a3c13b3aab1ed09dd4eda982207eb3e63c2ad342f072b49c8" dependencies = [ "proc-macro2", "quote", @@ -5585,9 +5574,9 @@ dependencies = [ [[package]] name = "swc_eq_ignore_macros" -version = "0.1.4" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63db0adcff29d220c3d151c5b25c0eabe7e32dd936212b84cdaa1392e3130497" +checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" dependencies = [ "proc-macro2", "quote", @@ -5736,9 +5725,9 @@ dependencies = [ [[package]] name = "swc_macros_common" -version = "0.3.13" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f486687bfb7b5c560868f69ed2d458b880cebc9babebcb67e49f31b55c5bf847" +checksum = "91745f3561057493d2da768437c427c0e979dff7396507ae02f16c981c4a8466" dependencies = [ "proc-macro2", "quote", @@ -6118,21 +6107,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.17" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a44eede9b727419af8095cb2d72fab15487a541f54647ad4414b34096ee4631" +checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.18", + "toml_edit 0.22.6", ] [[package]] name = "toml_datetime" -version = "0.6.8" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] @@ -6152,15 +6141,15 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.18" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1490595c74d930da779e944f5ba2ecdf538af67df1a9848cbd156af43c1b7cf0" +checksum = "2c1b5fd4128cc8d3e0cb74d4ed9a9cc7c7284becd4df68f5f940e1ad123606f6" dependencies = [ "indexmap 2.2.6", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.16", + "winnow 0.6.5", ] [[package]] @@ -6258,7 +6247,7 @@ dependencies = [ "serde_derive", "serde_json", "termcolor", - "toml 0.8.17", + "toml 0.8.10", ] [[package]] @@ -6803,7 +6792,7 @@ dependencies = [ "serde_json", "serde_yaml", "thiserror", - "toml 0.8.17", + "toml 0.8.10", "url", ] @@ -6825,7 +6814,7 @@ dependencies = [ "serde_json", "serde_yaml", "thiserror", - "toml 0.8.17", + "toml 0.8.10", "url", ] @@ -7318,9 +7307,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.16" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b480ae9340fc261e6be3e95a1ba86d54ae3f9171132a73ce8d4bbaf68339507c" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 82bd53c8693..9fd57fa4209 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,8 +85,9 @@ rspack_dojang = { version = "0.1.8" } rate-limit = { existing-packages = 70, new-packages = 70 } [profile.dev] codegen-units = 16 -debug = 2 # debug build will cause runtime panic if codegen-unints is default +debug = 2 # debug build will cause runtime panic if codegen-unints is default incremental = true +panic = "abort" [profile.release] codegen-units = 1 @@ -94,6 +95,7 @@ debug = false # Performs “thin” LTO. This is similar to “fat”, but takes substantially less time to run while still achieving performance gains similar to “fat”. lto = "thin" opt-level = 3 +panic = "abort" strip = true [profile.release-prod] diff --git a/crates/rspack_error/src/miette_helpers.rs b/crates/rspack_error/src/miette_helpers.rs index 36a1ae6f80f..e19e5f381b3 100644 --- a/crates/rspack_error/src/miette_helpers.rs +++ b/crates/rspack_error/src/miette_helpers.rs @@ -55,7 +55,7 @@ impl miette::Diagnostic for WithHelp { fn help<'a>(&'a self) -> Option> { let help = self.wrap_help.get_or_init(|| { let prev = self.err.help().map(|h| h.to_string()); - let help = self.help.as_ref(); + let help = self.help.as_ref().cloned(); if let Some(prev) = prev { if let Some(help) = &help { Some(format!("{prev}\n{help}").into()) @@ -63,7 +63,7 @@ impl miette::Diagnostic for WithHelp { Some(prev.into()) } } else if help.is_some() { - help.cloned() + help } else { None } diff --git a/crates/rspack_loader_swc/Cargo.toml b/crates/rspack_loader_swc/Cargo.toml index 46d9448f59f..ab6471b74fd 100644 --- a/crates/rspack_loader_swc/Cargo.toml +++ b/crates/rspack_loader_swc/Cargo.toml @@ -36,6 +36,3 @@ swc_core = { workspace = true, features = ["base", "ecma_ast", " swc_plugin_import = { version = "0.1.5", path = "../swc_plugin_import" } tokio = { workspace = true } url = "2.5.0" - -[build-dependencies] -cargo_toml = { version = "0.20.4" } diff --git a/crates/rspack_loader_swc/build.rs b/crates/rspack_loader_swc/build.rs deleted file mode 100644 index c38bc42090e..00000000000 --- a/crates/rspack_loader_swc/build.rs +++ /dev/null @@ -1,18 +0,0 @@ -fn main() { - const CARGO_TOML: &str = include_str!("../../Cargo.toml"); - let workspace_toml = cargo_toml::Manifest::from_str(CARGO_TOML) - .expect("Should parse cargo toml") - .workspace; - let swc_core_version = workspace_toml - .as_ref() - .and_then(|ws| { - ws.dependencies.get("swc_core").and_then(|dep| match dep { - cargo_toml::Dependency::Simple(s) => Some(&**s), - cargo_toml::Dependency::Inherited(_) => unreachable!(), - cargo_toml::Dependency::Detailed(d) => d.version.as_deref(), - }) - }) - .expect("Should have `swc_core` version") - .to_owned(); - println!("cargo::rustc-env=RSPACK_SWC_CORE_VERSION={swc_core_version}"); -} diff --git a/crates/rspack_loader_swc/src/compiler.rs b/crates/rspack_loader_swc/src/compiler.rs index e8d2b18538a..4dc19807a3d 100644 --- a/crates/rspack_loader_swc/src/compiler.rs +++ b/crates/rspack_loader_swc/src/compiler.rs @@ -16,8 +16,6 @@ use base64::prelude::*; use dashmap::DashMap; use jsonc_parser::parse_to_serde_value; use rspack_ast::javascript::{Ast as JsAst, Context as JsAstContext, Program as JsProgram}; -use rspack_error::miette::MietteDiagnostic; -use rspack_error::DiagnosticExt; use serde_json::error::Category; use swc_config::config_types::BoolOr; use swc_config::merge::Merge; @@ -389,35 +387,7 @@ impl SwcCompiler { try_with_handler(self.cm.clone(), Default::default(), |handler| { HANDLER.set(handler, || { // Fold module - match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { - program.fold_with(&mut pass) - })) { - Ok(v) => Ok(v), - Err(err) => { - macro_rules! swc_error { - ($tt:tt) => {{ - let swc_core_version = env!("RSPACK_SWC_CORE_VERSION"); - - MietteDiagnostic::new(format!("Builtin swc-loader error: {} - -Help: - The version of the SWC Wasm plugin you're using might not be compatible with `builtin:swc-loader`. - - The `swc_core` version of the current `rspack_core` is {swc_core_version}. Please check the `swc_core` version of SWC Wasm plugin to make sure these versions are within the compatible range. - Versions of `swc_core` are more likely to be located in the `Cargo.toml` file in the root directory of these plugin repositories. - - Check out this guide as a reference for selecting the versions of SWC Wasm plugins: https://swc.rs/docs/plugin/selecting-swc-core", $tt)) - .boxed() - .into() - }} - } - if let Some(err) = err.downcast_ref::() { - Err(swc_error!(err)) - } else { - Err(swc_error!("unknown error")) - } - } - } + Ok(program.fold_with(&mut pass)) }) }) }) diff --git a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/errors.js b/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/errors.js deleted file mode 100644 index 1f111c780a8..00000000000 --- a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/errors.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = [ - [ - /The version of the SWC Wasm plugin you're using might not be compatible with \`builtin:swc-loader\`/ - ], -]; diff --git a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/index.html b/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/index.html deleted file mode 100644 index 7bac4f56868..00000000000 --- a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - Document - - -
- - diff --git a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/node_modules/swc-wasm-plugin/package.json b/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/node_modules/swc-wasm-plugin/package.json deleted file mode 100644 index 8594ce08757..00000000000 --- a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/node_modules/swc-wasm-plugin/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "swc-wasm-plugin", - "main": "plugin.wasm" -} \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/node_modules/swc-wasm-plugin/plugin.wasm b/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/node_modules/swc-wasm-plugin/plugin.wasm deleted file mode 100644 index a8aaab06740..00000000000 Binary files a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/node_modules/swc-wasm-plugin/plugin.wasm and /dev/null differ diff --git a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/rspack.config.js deleted file mode 100644 index 85df0292237..00000000000 --- a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/rspack.config.js +++ /dev/null @@ -1,89 +0,0 @@ - - -const rspack = require('@rspack/core'); -const path = require('path'); -const { RawSource } = require('webpack-sources'); -/** @type {import('@rspack/cli').Configuration} */ -const config = { - entry: { - main: './src/index.jsx', - }, - resolve: { - extensions: ['...', '.jsx'], - alias: { - '@swc/helpers': path.dirname(require.resolve('@swc/helpers/package.json')), - }, - }, - module: { - rules: [ - { - test: /\.(jsx|js)$/, - use: { - loader: 'builtin:swc-loader', - options: { - // Enable source map - sourceMap: true, - target: 'es5', - jsc: { - parser: { - syntax: 'ecmascript', - jsx: true, - }, - externalHelpers: true, - preserveAllComments: false, - transform: { - react: { - runtime: 'automatic', - pragma: 'React.createElement', - pragmaFrag: 'React.Fragment', - throwIfNamespace: true, - useBuiltins: false, - }, - }, - experimental: { - cacheRoot: __dirname + "/.swc", - plugins: [ - [ - __dirname + "/node_modules/swc-wasm-plugin", - { - exclude: ["error"] - } - ] - ] - } - }, - }, - }, - type: 'javascript/auto', - }, - { - test: /\.(png|svg|jpg)$/, - type: 'asset/resource', - }, - ], - }, - optimization: { - minimize: false, // Disabling minification because it takes too long on CI - }, - plugins: [ - new rspack.HtmlRspackPlugin({ - template: './index.html', - }), - { - // Replace all assets with empty content to avoid evaluation that causes errors - apply(compiler) { - compiler.hooks.compilation.tap("_", (compilation) => { - compilation.hooks.processAssets.tap("_", (assets) => { - let names = Object.keys(assets); - names.forEach(name => { - assets[name] = new RawSource("") - }) - }) - }) - } - } - ], - experiments: { css: true } -}; -module.exports = config; - diff --git a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/src/App.jsx b/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/src/App.jsx deleted file mode 100644 index c6d71586536..00000000000 --- a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/src/App.jsx +++ /dev/null @@ -1,21 +0,0 @@ -function App() { - return ( -
-
-

- Edit src/App.js and save to reload. -

- - Learn React - -
-
- ); -} - -export default App; diff --git a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/src/index.jsx b/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/src/index.jsx deleted file mode 100644 index 2e7bf163173..00000000000 --- a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/src/index.jsx +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom/client'; -import App from './App'; -import { answer } from 'lib3'; -console.log('answer:', answer()); - -const root = ReactDOM.createRoot(document.getElementById('root')); -root.render( - - - , -); diff --git a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/test.config.js b/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/test.config.js deleted file mode 100644 index b99331a9cd3..00000000000 --- a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/swc-loader-incompatible-wasm-plugin/test.config.js +++ /dev/null @@ -1,4 +0,0 @@ -/** @type {import("../../../..").TConfigCaseConfig} */ -module.exports = { - noTests: true, -}