From eaa293c6b951cbc65640c2680c4551a7e9c1490a Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Thu, 1 Feb 2024 17:29:45 +0800 Subject: [PATCH] revert: feat: support custom source root (#5522) (#5561) Revert "feat: support custom source root (#5522)" This reverts commit fe785afa38bea33d796d55896a78b9d64927dae5. --- Cargo.lock | 6 ++++-- Cargo.toml | 2 +- crates/rspack_plugin_devtool/src/lib.rs | 17 ++++++--------- .../index.js | 8 ------- .../webpack.config.js | 21 ------------------- 5 files changed, 11 insertions(+), 43 deletions(-) delete mode 100644 packages/rspack/tests/configCases/plugins/source-map-dev-tool-plugin-source-root/index.js delete mode 100644 packages/rspack/tests/configCases/plugins/source-map-dev-tool-plugin-source-root/webpack.config.js diff --git a/Cargo.lock b/Cargo.lock index 9c849d38a6e..3272c566bc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3150,13 +3150,15 @@ dependencies = [ [[package]] name = "rspack_sources" -version = "0.2.9" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f09931bc4ed54e5a04b59e5a9cb9a13a4a42c479431aeff7abe7cb35b6b3169" +checksum = "25a741e3d5c1b73996bad4beeefb8aa0bbffad40ba4f0c4b09080265c11bd7bd" dependencies = [ "dashmap", "dyn-clone", "memchr", + "once_cell", + "parking_lot", "rustc-hash", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 3bf08612ddd..b68053d19a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ quote = { version = "1.0.35" } rayon = { version = "1.8.1" } regex = { version = "1.10.3" } rkyv = { version = "0.7.43" } -rspack_sources = { version = "=0.2.9" } +rspack_sources = { version = "=0.2.7" } rustc-hash = { version = "1.1.0" } schemars = { version = "0.8.16" } serde = { version = "1.0.196" } diff --git a/crates/rspack_plugin_devtool/src/lib.rs b/crates/rspack_plugin_devtool/src/lib.rs index 2ff2cab58dd..4c33341a894 100644 --- a/crates/rspack_plugin_devtool/src/lib.rs +++ b/crates/rspack_plugin_devtool/src/lib.rs @@ -136,7 +136,6 @@ pub struct SourceMapDevToolPlugin { no_sources: bool, public_path: Option, module: bool, - source_root: Option, #[derivative(Debug = "ignore")] test: Option, } @@ -179,7 +178,6 @@ impl SourceMapDevToolPlugin { no_sources: options.no_sources, public_path: options.public_path, module: options.module, - source_root: options.source_root, test: options.test, } } @@ -303,7 +301,7 @@ impl Plugin for SourceMapDevToolPlugin { let mut has_name = used_names_set.contains(&source_name); if !has_name { used_names_set.insert(source_name.clone()); - *source = Cow::from(source_name); + *source = source_name; continue; } @@ -325,7 +323,7 @@ impl Plugin for SourceMapDevToolPlugin { has_name = used_names_set.contains(&source_name); if !has_name { used_names_set.insert(source_name.clone()); - *source = Cow::from(source_name); + *source = source_name; continue; } @@ -335,16 +333,13 @@ impl Plugin for SourceMapDevToolPlugin { has_name = used_names_set.contains(&source_name); } used_names_set.insert(source_name.clone()); - *source = Cow::from(source_name); + *source = source_name; } if self.no_sources { for content in source_map.sources_content_mut() { - *content = Cow::from(String::default()); + *content = String::default(); } } - if let Some(source_root) = &self.source_root { - source_map.set_source_root(Some(source_root.clone())); - } let mut source_map_buffer = Vec::new(); source_map .to_writer(&mut source_map_buffer) @@ -796,11 +791,11 @@ impl EvalSourceMapDevToolPlugin { for source in map.sources_mut() { let resource_path = normalize_custom_filename(source); let resource_path = contextify(&compilation.options.context, resource_path); - *source = Cow::from(resource_path); + *source = resource_path; } if self.no_sources { for content in map.sources_content_mut() { - *content = Cow::from(String::default()); + *content = String::default(); } } let mut map_buffer = Vec::new(); diff --git a/packages/rspack/tests/configCases/plugins/source-map-dev-tool-plugin-source-root/index.js b/packages/rspack/tests/configCases/plugins/source-map-dev-tool-plugin-source-root/index.js deleted file mode 100644 index 04cf8f18918..00000000000 --- a/packages/rspack/tests/configCases/plugins/source-map-dev-tool-plugin-source-root/index.js +++ /dev/null @@ -1,8 +0,0 @@ -it("should generate the correct sourceRoot in SourceMap", function () { - const fs = require("fs"); - const path = require("path"); - const source = JSON.parse(fs.readFileSync(__filename + ".map", "utf-8")); - expect(source.sourceRoot).toContain( - path.resolve(__dirname, "../folder") + "/" - ); -}); diff --git a/packages/rspack/tests/configCases/plugins/source-map-dev-tool-plugin-source-root/webpack.config.js b/packages/rspack/tests/configCases/plugins/source-map-dev-tool-plugin-source-root/webpack.config.js deleted file mode 100644 index cbb08b698c6..00000000000 --- a/packages/rspack/tests/configCases/plugins/source-map-dev-tool-plugin-source-root/webpack.config.js +++ /dev/null @@ -1,21 +0,0 @@ -const path = require("path"); -const rspack = require("@rspack/core"); - -/** - * @type {import("@rspack/core").Configuration} - */ -module.exports = { - node: { - __dirname: false, - __filename: false - }, - output: { - filename: "[name].js" - }, - plugins: [ - new rspack.SourceMapDevToolPlugin({ - filename: "[file].map", - sourceRoot: path.join(__dirname, "folder") + "/" - }) - ] -};