From ac35fea859e4b649b0caaa025d15af0a3683d97c Mon Sep 17 00:00:00 2001 From: hardfist Date: Fri, 6 Sep 2024 10:14:46 +0800 Subject: [PATCH 1/4] feat(chore): use dyn output_filesystem --- crates/node_binding/src/compiler.rs | 4 +--- crates/node_binding/src/lib.rs | 6 ++++-- crates/rspack_core/src/compiler/hmr.rs | 6 +----- crates/rspack_core/src/compiler/mod.rs | 15 ++++----------- crates/rspack_fs/src/async.rs | 4 +++- crates/rspack_fs/src/native.rs | 2 ++ crates/rspack_fs_node/src/async.rs | 1 + crates/rspack_fs_node/src/node.rs | 1 + 8 files changed, 17 insertions(+), 22 deletions(-) diff --git a/crates/node_binding/src/compiler.rs b/crates/node_binding/src/compiler.rs index 2f7a8f71f14..d49f54c95b0 100644 --- a/crates/node_binding/src/compiler.rs +++ b/crates/node_binding/src/compiler.rs @@ -7,9 +7,7 @@ use std::{ }, }; -use rspack_fs_node::AsyncNodeWritableFileSystem; - -type CompilerInner = rspack_core::Compiler; +type CompilerInner = rspack_core::Compiler; /// `Compiler` struct that is `!Unpin`. pub(crate) struct Compiler(CompilerInner, PhantomPinned); diff --git a/crates/node_binding/src/lib.rs b/crates/node_binding/src/lib.rs index 7f17cbcd1f2..4afbc5021a0 100644 --- a/crates/node_binding/src/lib.rs +++ b/crates/node_binding/src/lib.rs @@ -67,8 +67,10 @@ impl Rspack { let rspack = rspack_core::Compiler::new( compiler_options, plugins, - AsyncNodeWritableFileSystem::new(output_filesystem) - .map_err(|e| Error::from_reason(format!("Failed to create writable filesystem: {e}",)))?, + Box::new( + AsyncNodeWritableFileSystem::new(output_filesystem) + .map_err(|e| Error::from_reason(format!("Failed to create writable filesystem: {e}",)))?, + ), Some(resolver_factory), Some(loader_resolver_factory), ); diff --git a/crates/rspack_core/src/compiler/hmr.rs b/crates/rspack_core/src/compiler/hmr.rs index 2a662dc6d26..e6c709d1ffc 100644 --- a/crates/rspack_core/src/compiler/hmr.rs +++ b/crates/rspack_core/src/compiler/hmr.rs @@ -3,7 +3,6 @@ use std::path::PathBuf; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use rspack_collections::{Identifier, IdentifierMap}; use rspack_error::Result; -use rspack_fs::AsyncWritableFileSystem; use rspack_hash::RspackHashDigest; use rspack_sources::Source; use rustc_hash::FxHashSet as HashSet; @@ -12,10 +11,7 @@ use crate::{ fast_set, get_chunk_from_ukey, ChunkKind, Compilation, Compiler, ModuleExecutor, RuntimeSpec, }; -impl Compiler -where - T: AsyncWritableFileSystem + Send + Sync, -{ +impl Compiler { pub async fn rebuild( &mut self, changed_files: std::collections::HashSet, diff --git a/crates/rspack_core/src/compiler/mod.rs b/crates/rspack_core/src/compiler/mod.rs index 2c4e0d94854..76c8bc64ca7 100644 --- a/crates/rspack_core/src/compiler/mod.rs +++ b/crates/rspack_core/src/compiler/mod.rs @@ -2,7 +2,6 @@ mod compilation; mod hmr; mod make; mod module_executor; - use std::sync::Arc; use rspack_error::Result; @@ -50,12 +49,9 @@ pub struct CompilerHooks { } #[derive(Debug)] -pub struct Compiler -where - T: AsyncWritableFileSystem + Send + Sync, -{ +pub struct Compiler { pub options: Arc, - pub output_filesystem: T, + pub output_filesystem: Box, pub compilation: Compilation, pub plugin_driver: SharedPluginDriver, pub resolver_factory: Arc, @@ -67,15 +63,12 @@ where unaffected_modules_cache: Arc, } -impl Compiler -where - T: AsyncWritableFileSystem + Send + Sync, -{ +impl Compiler { #[instrument(skip_all)] pub fn new( options: CompilerOptions, plugins: Vec, - output_filesystem: T, + output_filesystem: Box, // no need to pass resolve_factory in rust api resolver_factory: Option>, loader_resolver_factory: Option>, diff --git a/crates/rspack_fs/src/async.rs b/crates/rspack_fs/src/async.rs index 21fa2e3802a..6c8fec3e04c 100644 --- a/crates/rspack_fs/src/async.rs +++ b/crates/rspack_fs/src/async.rs @@ -1,9 +1,11 @@ +use std::fmt::Debug; + use futures::future::BoxFuture; use rspack_paths::Utf8Path; use crate::Result; -pub trait AsyncWritableFileSystem { +pub trait AsyncWritableFileSystem: Debug { /// Creates a new, empty directory at the provided path. /// /// NOTE: If a parent of the given path doesn’t exist, this function is supposed to return an error. diff --git a/crates/rspack_fs/src/native.rs b/crates/rspack_fs/src/native.rs index ff30b559df9..c5d27b4092c 100644 --- a/crates/rspack_fs/src/native.rs +++ b/crates/rspack_fs/src/native.rs @@ -8,6 +8,7 @@ use super::{ Error, Result, }; +#[derive(Debug)] pub struct NativeFileSystem; impl WritableFileSystem for NativeFileSystem { @@ -34,6 +35,7 @@ cfg_async! { use futures::future::BoxFuture; use crate::{AsyncReadableFileSystem, AsyncWritableFileSystem}; + #[derive(Debug)] pub struct AsyncNativeFileSystem; impl AsyncWritableFileSystem for AsyncNativeFileSystem { diff --git a/crates/rspack_fs_node/src/async.rs b/crates/rspack_fs_node/src/async.rs index c49310e29be..d25e203429e 100644 --- a/crates/rspack_fs_node/src/async.rs +++ b/crates/rspack_fs_node/src/async.rs @@ -4,6 +4,7 @@ use rspack_paths::Utf8Path; use crate::node::ThreadsafeNodeFS; +#[derive(Debug)] pub struct AsyncNodeWritableFileSystem(ThreadsafeNodeFS); impl AsyncNodeWritableFileSystem { diff --git a/crates/rspack_fs_node/src/node.rs b/crates/rspack_fs_node/src/node.rs index 823aa022488..cc9e85a03b5 100644 --- a/crates/rspack_fs_node/src/node.rs +++ b/crates/rspack_fs_node/src/node.rs @@ -60,6 +60,7 @@ cfg_async! { use rspack_napi::threadsafe_function::ThreadsafeFunction; #[napi(object, object_to_js = false, js_name = "ThreadsafeNodeFS")] + #[derive(Debug)] pub struct ThreadsafeNodeFS { #[napi(ts_type = "(name: string, content: Buffer) => Promise | void")] pub write_file: ThreadsafeFunction<(String, Buffer), ()>, From 73d627c3118c09d96664e97044f23fc0d6ff0bf3 Mon Sep 17 00:00:00 2001 From: hardfist Date: Fri, 6 Sep 2024 11:08:33 +0800 Subject: [PATCH 2/4] fix: remove debug constraint --- crates/rspack_core/src/compiler/mod.rs | 5 ++++- crates/rspack_fs/src/async.rs | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/rspack_core/src/compiler/mod.rs b/crates/rspack_core/src/compiler/mod.rs index 76c8bc64ca7..6f38dc889b5 100644 --- a/crates/rspack_core/src/compiler/mod.rs +++ b/crates/rspack_core/src/compiler/mod.rs @@ -4,6 +4,7 @@ mod make; mod module_executor; use std::sync::Arc; +use derivative::Derivative; use rspack_error::Result; use rspack_fs::AsyncWritableFileSystem; use rspack_futures::FuturesResults; @@ -48,9 +49,11 @@ pub struct CompilerHooks { pub asset_emitted: CompilerAssetEmittedHook, } -#[derive(Debug)] +#[derive(Derivative)] +#[derivative(Debug)] pub struct Compiler { pub options: Arc, + #[derivative(Debug = "ignore")] pub output_filesystem: Box, pub compilation: Compilation, pub plugin_driver: SharedPluginDriver, diff --git a/crates/rspack_fs/src/async.rs b/crates/rspack_fs/src/async.rs index 6c8fec3e04c..21fa2e3802a 100644 --- a/crates/rspack_fs/src/async.rs +++ b/crates/rspack_fs/src/async.rs @@ -1,11 +1,9 @@ -use std::fmt::Debug; - use futures::future::BoxFuture; use rspack_paths::Utf8Path; use crate::Result; -pub trait AsyncWritableFileSystem: Debug { +pub trait AsyncWritableFileSystem { /// Creates a new, empty directory at the provided path. /// /// NOTE: If a parent of the given path doesn’t exist, this function is supposed to return an error. From b3d04fab52f8648c6a52bde68639a0520270de8b Mon Sep 17 00:00:00 2001 From: hardfist Date: Fri, 6 Sep 2024 11:11:53 +0800 Subject: [PATCH 3/4] fix: remove debug --- crates/rspack_fs/src/native.rs | 2 -- crates/rspack_fs_node/src/async.rs | 1 - crates/rspack_fs_node/src/node.rs | 1 - 3 files changed, 4 deletions(-) diff --git a/crates/rspack_fs/src/native.rs b/crates/rspack_fs/src/native.rs index c5d27b4092c..ff30b559df9 100644 --- a/crates/rspack_fs/src/native.rs +++ b/crates/rspack_fs/src/native.rs @@ -8,7 +8,6 @@ use super::{ Error, Result, }; -#[derive(Debug)] pub struct NativeFileSystem; impl WritableFileSystem for NativeFileSystem { @@ -35,7 +34,6 @@ cfg_async! { use futures::future::BoxFuture; use crate::{AsyncReadableFileSystem, AsyncWritableFileSystem}; - #[derive(Debug)] pub struct AsyncNativeFileSystem; impl AsyncWritableFileSystem for AsyncNativeFileSystem { diff --git a/crates/rspack_fs_node/src/async.rs b/crates/rspack_fs_node/src/async.rs index d25e203429e..c49310e29be 100644 --- a/crates/rspack_fs_node/src/async.rs +++ b/crates/rspack_fs_node/src/async.rs @@ -4,7 +4,6 @@ use rspack_paths::Utf8Path; use crate::node::ThreadsafeNodeFS; -#[derive(Debug)] pub struct AsyncNodeWritableFileSystem(ThreadsafeNodeFS); impl AsyncNodeWritableFileSystem { diff --git a/crates/rspack_fs_node/src/node.rs b/crates/rspack_fs_node/src/node.rs index cc9e85a03b5..823aa022488 100644 --- a/crates/rspack_fs_node/src/node.rs +++ b/crates/rspack_fs_node/src/node.rs @@ -60,7 +60,6 @@ cfg_async! { use rspack_napi::threadsafe_function::ThreadsafeFunction; #[napi(object, object_to_js = false, js_name = "ThreadsafeNodeFS")] - #[derive(Debug)] pub struct ThreadsafeNodeFS { #[napi(ts_type = "(name: string, content: Buffer) => Promise | void")] pub write_file: ThreadsafeFunction<(String, Buffer), ()>, From dd96b3f224510776b07ea249178254ad11b5748f Mon Sep 17 00:00:00 2001 From: hardfist Date: Mon, 9 Sep 2024 16:47:38 +0800 Subject: [PATCH 4/4] chore: disable rspack-cli jest cache --- packages/rspack-cli/jest.config.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/rspack-cli/jest.config.js b/packages/rspack-cli/jest.config.js index 0b2118a394f..40ee463f5f0 100644 --- a/packages/rspack-cli/jest.config.js +++ b/packages/rspack-cli/jest.config.js @@ -1,17 +1,14 @@ /** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const config = { - preset: "ts-jest", - testEnvironment: "../../scripts/test/patch-node-env.cjs", - testTimeout: process.env.CI ? 200000 : 30000, - testMatch: ["/tests/**/*.test.ts", "/tests/**/*.test.js"], - watchPathIgnorePatterns: ["/tests/.*/dist"], - extensionsToTreatAsEsm: [".mts"], - globals: { - "ts-jest": { - tsconfig: "/tests/tsconfig.json" - } - }, - prettierPath: require.resolve("prettier-2") + preset: 'ts-jest', + testEnvironment: '../../scripts/test/patch-node-env.cjs', + testTimeout: process.env.CI ? 200000 : 30000, + testMatch: ['/tests/**/*.test.ts', '/tests/**/*.test.js'], + watchPathIgnorePatterns: ['/tests/.*/dist'], + extensionsToTreatAsEsm: ['.mts'], + globals: {'ts-jest': {tsconfig: '/tests/tsconfig.json'}}, + cache: false, + prettierPath: require.resolve('prettier-2') }; module.exports = config;