Skip to content

Commit

Permalink
feat(chore): use dyn output_filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist committed Sep 9, 2024
1 parent cec9cff commit ac35fea
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 22 deletions.
4 changes: 1 addition & 3 deletions crates/node_binding/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use std::{
},
};

use rspack_fs_node::AsyncNodeWritableFileSystem;

type CompilerInner = rspack_core::Compiler<AsyncNodeWritableFileSystem>;
type CompilerInner = rspack_core::Compiler;

/// `Compiler` struct that is `!Unpin`.
pub(crate) struct Compiler(CompilerInner, PhantomPinned);
Expand Down
6 changes: 4 additions & 2 deletions crates/node_binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down
6 changes: 1 addition & 5 deletions crates/rspack_core/src/compiler/hmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,10 +11,7 @@ use crate::{
fast_set, get_chunk_from_ukey, ChunkKind, Compilation, Compiler, ModuleExecutor, RuntimeSpec,
};

impl<T> Compiler<T>
where
T: AsyncWritableFileSystem + Send + Sync,
{
impl Compiler {
pub async fn rebuild(
&mut self,
changed_files: std::collections::HashSet<String>,
Expand Down
15 changes: 4 additions & 11 deletions crates/rspack_core/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod compilation;
mod hmr;
mod make;
mod module_executor;

use std::sync::Arc;

use rspack_error::Result;
Expand Down Expand Up @@ -50,12 +49,9 @@ pub struct CompilerHooks {
}

#[derive(Debug)]
pub struct Compiler<T>
where
T: AsyncWritableFileSystem + Send + Sync,
{
pub struct Compiler {
pub options: Arc<CompilerOptions>,
pub output_filesystem: T,
pub output_filesystem: Box<dyn AsyncWritableFileSystem + Send + Sync>,
pub compilation: Compilation,
pub plugin_driver: SharedPluginDriver,
pub resolver_factory: Arc<ResolverFactory>,
Expand All @@ -67,15 +63,12 @@ where
unaffected_modules_cache: Arc<UnaffectedModulesCache>,
}

impl<T> Compiler<T>
where
T: AsyncWritableFileSystem + Send + Sync,
{
impl Compiler {
#[instrument(skip_all)]
pub fn new(
options: CompilerOptions,
plugins: Vec<BoxPlugin>,
output_filesystem: T,
output_filesystem: Box<dyn AsyncWritableFileSystem + Send + Sync>,
// no need to pass resolve_factory in rust api
resolver_factory: Option<Arc<ResolverFactory>>,
loader_resolver_factory: Option<Arc<ResolverFactory>>,
Expand Down
4 changes: 3 additions & 1 deletion crates/rspack_fs/src/async.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_fs/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::{
Error, Result,
};

#[derive(Debug)]
pub struct NativeFileSystem;

impl WritableFileSystem for NativeFileSystem {
Expand All @@ -34,6 +35,7 @@ cfg_async! {
use futures::future::BoxFuture;

use crate::{AsyncReadableFileSystem, AsyncWritableFileSystem};
#[derive(Debug)]
pub struct AsyncNativeFileSystem;

impl AsyncWritableFileSystem for AsyncNativeFileSystem {
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_fs_node/src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rspack_paths::Utf8Path;

use crate::node::ThreadsafeNodeFS;

#[derive(Debug)]
pub struct AsyncNodeWritableFileSystem(ThreadsafeNodeFS);

impl AsyncNodeWritableFileSystem {
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_fs_node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> | void")]
pub write_file: ThreadsafeFunction<(String, Buffer), ()>,
Expand Down

0 comments on commit ac35fea

Please sign in to comment.