Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): use dyn output_filesystem #7817

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 8 additions & 12 deletions crates/rspack_core/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ mod compilation;
mod hmr;
mod make;
mod module_executor;

use std::sync::Arc;

use derivative::Derivative;
use rspack_error::Result;
use rspack_fs::AsyncWritableFileSystem;
use rspack_futures::FuturesResults;
Expand Down Expand Up @@ -49,13 +49,12 @@ pub struct CompilerHooks {
pub asset_emitted: CompilerAssetEmittedHook,
}

#[derive(Debug)]
pub struct Compiler<T>
where
T: AsyncWritableFileSystem + Send + Sync,
{
#[derive(Derivative)]
#[derivative(Debug)]
pub struct Compiler {
pub options: Arc<CompilerOptions>,
pub output_filesystem: T,
#[derivative(Debug = "ignore")]
pub output_filesystem: Box<dyn AsyncWritableFileSystem + Send + Sync>,
pub compilation: Compilation,
pub plugin_driver: SharedPluginDriver,
pub resolver_factory: Arc<ResolverFactory>,
Expand All @@ -67,15 +66,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
21 changes: 9 additions & 12 deletions packages/rspack-cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -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: ["<rootDir>/tests/**/*.test.ts", "<rootDir>/tests/**/*.test.js"],
watchPathIgnorePatterns: ["<rootDir>/tests/.*/dist"],
extensionsToTreatAsEsm: [".mts"],
globals: {
"ts-jest": {
tsconfig: "<rootDir>/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: ['<rootDir>/tests/**/*.test.ts', '<rootDir>/tests/**/*.test.js'],
watchPathIgnorePatterns: ['<rootDir>/tests/.*/dist'],
extensionsToTreatAsEsm: ['.mts'],
globals: {'ts-jest': {tsconfig: '<rootDir>/tests/tsconfig.json'}},
cache: false,
prettierPath: require.resolve('prettier-2')
};

module.exports = config;
Loading