Skip to content

Commit 7187ba9

Browse files
authored
refactor: remove unnecessary filesystem trait (#8525)
1 parent aa284b9 commit 7187ba9

File tree

20 files changed

+206
-458
lines changed

20 files changed

+206
-458
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/node_binding/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use napi::bindgen_prelude::*;
1313
use rspack_binding_options::BuiltinPlugin;
1414
use rspack_core::{Compilation, PluginExt};
1515
use rspack_error::Diagnostic;
16-
use rspack_fs_node::{AsyncNodeWritableFileSystem, ThreadsafeNodeFS};
16+
use rspack_fs_node::{NodeFileSystem, ThreadsafeNodeFS};
1717

1818
mod compiler;
1919
mod diagnostic;
@@ -70,10 +70,9 @@ impl Rspack {
7070
compiler_options,
7171
plugins,
7272
rspack_binding_options::buildtime_plugins::buildtime_plugins(),
73-
Some(Box::new(
74-
AsyncNodeWritableFileSystem::new(output_filesystem)
75-
.map_err(|e| Error::from_reason(format!("Failed to create writable filesystem: {e}",)))?,
76-
)),
73+
Some(Box::new(NodeFileSystem::new(output_filesystem).map_err(
74+
|e| Error::from_reason(format!("Failed to create writable filesystem: {e}",)),
75+
)?)),
7776
None,
7877
Some(resolver_factory),
7978
Some(loader_resolver_factory),

crates/rspack_core/src/cache/persistent/snapshot/mod.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ impl Snapshot {
103103
mod tests {
104104
use std::sync::Arc;
105105

106-
use rspack_fs::{MemoryFileSystem, SyncWritableFileSystem};
106+
use rspack_fs::{MemoryFileSystem, WritableFileSystem};
107107
use rspack_paths::Utf8PathBuf;
108108

109109
use super::super::MemoryStorage;
110110
use super::{PathMatcher, Snapshot, SnapshotOptions};
111111

112-
#[test]
113-
fn should_snapshot_work() {
112+
#[tokio::test]
113+
async fn should_snapshot_work() {
114114
let fs = Arc::new(MemoryFileSystem::default());
115115
let storage = Arc::new(MemoryStorage::default());
116116
let options = SnapshotOptions::new(
@@ -119,23 +119,31 @@ mod tests {
119119
vec![PathMatcher::String("node_modules".into())],
120120
);
121121

122-
fs.create_dir_all("/node_modules/project".into()).unwrap();
123-
fs.create_dir_all("/node_modules/lib".into()).unwrap();
124-
fs.write("/file1".into(), "abc".as_bytes()).unwrap();
125-
fs.write("/constant".into(), "abc".as_bytes()).unwrap();
122+
fs.create_dir_all("/node_modules/project".into())
123+
.await
124+
.unwrap();
125+
fs.create_dir_all("/node_modules/lib".into()).await.unwrap();
126+
fs.write("/file1".into(), "abc".as_bytes()).await.unwrap();
127+
fs.write("/constant".into(), "abc".as_bytes())
128+
.await
129+
.unwrap();
126130
fs.write(
127131
"/node_modules/project/package.json".into(),
128132
r#"{"version":"1.0.0"}"#.as_bytes(),
129133
)
134+
.await
130135
.unwrap();
131136
fs.write("/node_modules/project/file1".into(), "abc".as_bytes())
137+
.await
132138
.unwrap();
133139
fs.write(
134140
"/node_modules/lib/package.json".into(),
135141
r#"{"version":"1.1.0"}"#.as_bytes(),
136142
)
143+
.await
137144
.unwrap();
138145
fs.write("/node_modules/lib/file1".into(), "abc".as_bytes())
146+
.await
139147
.unwrap();
140148

141149
let snapshot = Snapshot::new(options, fs.clone(), storage);
@@ -149,11 +157,15 @@ mod tests {
149157
.iter(),
150158
);
151159
std::thread::sleep(std::time::Duration::from_millis(100));
152-
fs.write("/file1".into(), "abcd".as_bytes()).unwrap();
153-
fs.write("/constant".into(), "abcd".as_bytes()).unwrap();
160+
fs.write("/file1".into(), "abcd".as_bytes()).await.unwrap();
161+
fs.write("/constant".into(), "abcd".as_bytes())
162+
.await
163+
.unwrap();
154164
fs.write("/node_modules/project/file1".into(), "abcd".as_bytes())
165+
.await
155166
.unwrap();
156167
fs.write("/node_modules/lib/file1".into(), "abcd".as_bytes())
168+
.await
157169
.unwrap();
158170

159171
let (modified_paths, deleted_paths) = snapshot.calc_modified_paths();
@@ -167,6 +179,7 @@ mod tests {
167179
"/node_modules/lib/package.json".into(),
168180
r#"{"version":"1.3.0"}"#.as_bytes(),
169181
)
182+
.await
170183
.unwrap();
171184
snapshot.add(["/file1".into()].iter());
172185
let (modified_paths, deleted_paths) = snapshot.calc_modified_paths();

crates/rspack_core/src/cache/persistent/snapshot/strategy.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,28 @@ impl StrategyHelper {
132132
mod tests {
133133
use std::sync::Arc;
134134

135-
use rspack_fs::{MemoryFileSystem, SyncReadableFileSystem, SyncWritableFileSystem};
135+
use rspack_fs::{MemoryFileSystem, ReadableFileSystem, WritableFileSystem};
136136

137137
use super::{Strategy, StrategyHelper, ValidateResult};
138138

139-
#[test]
140-
fn should_strategy_works() {
139+
#[tokio::test]
140+
async fn should_strategy_works() {
141141
let fs = Arc::new(MemoryFileSystem::default());
142-
fs.create_dir_all("/packages/p1".into()).unwrap();
143-
fs.create_dir_all("/packages/p2".into()).unwrap();
142+
fs.create_dir_all("/packages/p1".into()).await.unwrap();
143+
fs.create_dir_all("/packages/p2".into()).await.unwrap();
144144
fs.write(
145145
"/packages/p1/package.json".into(),
146146
r#"{"version": "1.0.0"}"#.as_bytes(),
147147
)
148+
.await
148149
.unwrap();
149150
fs.write(
150151
"/packages/p2/package.json".into(),
151152
r#"{"version": "1.1.0"}"#.as_bytes(),
152153
)
154+
.await
153155
.unwrap();
154-
fs.write("/file1".into(), "abc".as_bytes()).unwrap();
156+
fs.write("/file1".into(), "abc".as_bytes()).await.unwrap();
155157

156158
// compile_time
157159
let Strategy::CompileTime(time1) = StrategyHelper::compile_time() else {
@@ -222,7 +224,7 @@ mod tests {
222224
ValidateResult::NoChanged
223225
));
224226
std::thread::sleep(std::time::Duration::from_millis(100));
225-
fs.write("/file1".into(), "abcd".as_bytes()).unwrap();
227+
fs.write("/file1".into(), "abcd".as_bytes()).await.unwrap();
226228
assert!(matches!(
227229
helper.validate(&"/file1".into(), &now),
228230
ValidateResult::Modified

crates/rspack_core/src/compiler/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod module_executor;
55
use std::sync::Arc;
66

77
use rspack_error::Result;
8-
use rspack_fs::{AsyncWritableFileSystem, FileSystem, NativeFileSystem};
8+
use rspack_fs::{FileSystem, NativeFileSystem, WritableFileSystem};
99
use rspack_futures::FuturesResults;
1010
use rspack_hook::define_hook;
1111
use rspack_paths::{Utf8Path, Utf8PathBuf};
@@ -53,7 +53,7 @@ pub struct CompilerHooks {
5353
#[derive(Debug)]
5454
pub struct Compiler {
5555
pub options: Arc<CompilerOptions>,
56-
pub output_filesystem: Box<dyn AsyncWritableFileSystem + Send + Sync>,
56+
pub output_filesystem: Box<dyn WritableFileSystem>,
5757
pub input_filesystem: Arc<dyn FileSystem>,
5858
pub compilation: Compilation,
5959
pub plugin_driver: SharedPluginDriver,
@@ -73,7 +73,7 @@ impl Compiler {
7373
options: CompilerOptions,
7474
plugins: Vec<BoxPlugin>,
7575
buildtime_plugins: Vec<BoxPlugin>,
76-
output_filesystem: Option<Box<dyn AsyncWritableFileSystem + Send + Sync>>,
76+
output_filesystem: Option<Box<dyn WritableFileSystem + Send + Sync>>,
7777
// only supports passing input_filesystem in rust api, no support for js api
7878
input_filesystem: Option<Arc<dyn FileSystem + Send + Sync>>,
7979
// no need to pass resolve_factory in rust api

crates/rspack_fs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ repository = "https://github.com/web-infra-dev/rspack"
77
version = "0.1.0"
88

99
[dependencies]
10+
async-trait = { workspace = true }
1011
dunce = { version = "1.0.5" }
1112
futures = { workspace = true }
1213
rspack_error = { path = "../rspack_error", version = "0.1.0" }

crates/rspack_fs/src/fs.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
use crate::{
2-
AsyncFileSystem, AsyncReadableFileSystem, AsyncWritableFileSystem, SyncFileSystem,
3-
SyncReadableFileSystem, SyncWritableFileSystem,
4-
};
1+
use std::fmt::Debug;
52

6-
pub trait FileSystem: AsyncFileSystem + SyncFileSystem {}
3+
use crate::{ReadableFileSystem, WritableFileSystem};
74

8-
pub trait ReadableFileSystem: AsyncReadableFileSystem + SyncReadableFileSystem {}
9-
10-
pub trait WritableFileSystem: AsyncWritableFileSystem + SyncWritableFileSystem {}
5+
pub trait FileSystem: ReadableFileSystem + WritableFileSystem + Debug + Sync + Send {}

crates/rspack_fs/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
mod fs;
2-
pub use fs::{FileSystem, ReadableFileSystem, WritableFileSystem};
3-
mod r#async;
4-
pub use r#async::{AsyncFileSystem, AsyncReadableFileSystem, AsyncWritableFileSystem};
2+
pub use fs::FileSystem;
3+
mod read;
4+
pub use read::ReadableFileSystem;
55

6-
mod sync;
7-
pub use sync::{SyncFileSystem, SyncReadableFileSystem, SyncWritableFileSystem};
6+
mod write;
7+
pub use write::WritableFileSystem;
88

99
mod file_metadata;
1010
pub use file_metadata::FileMetadata;

0 commit comments

Comments
 (0)