From bea5815c8b0f5e396c56c0f20a72a9598b3eecb1 Mon Sep 17 00:00:00 2001 From: JW Date: Thu, 6 Jun 2024 20:43:50 +0800 Subject: [PATCH] fix: css parse error recovery --- .../src/options/raw_module/mod.rs | 1 - .../src/plugins/js_loader/resolver.rs | 24 +++++++++++++++++++ .../src/loader/rsc_client_entry_loader.rs | 6 ++--- .../src/loader/rsc_proxy_loader.rs | 6 ++--- .../RSCClientReferenceManifestRspackPlugin.ts | 2 +- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/crates/rspack_binding_options/src/options/raw_module/mod.rs b/crates/rspack_binding_options/src/options/raw_module/mod.rs index a34de6fc68bb..0a39570e348a 100644 --- a/crates/rspack_binding_options/src/options/raw_module/mod.rs +++ b/crates/rspack_binding_options/src/options/raw_module/mod.rs @@ -20,7 +20,6 @@ use rspack_core::{ use rspack_error::error; use rspack_napi::regexp::{JsRegExp, JsRegExpExt}; use rspack_napi::threadsafe_function::ThreadsafeFunction; -use rspack_plugin_rsc::{RSC_CLIENT_ENTRY_LOADER_IDENTIFIER, RSC_PROXY_LOADER_IDENTIFIER}; use tokio::runtime::Handle; use crate::RawResolveOptions; diff --git a/crates/rspack_binding_options/src/plugins/js_loader/resolver.rs b/crates/rspack_binding_options/src/plugins/js_loader/resolver.rs index dc859cb6eee0..643e300a8098 100644 --- a/crates/rspack_binding_options/src/plugins/js_loader/resolver.rs +++ b/crates/rspack_binding_options/src/plugins/js_loader/resolver.rs @@ -10,6 +10,10 @@ use rspack_identifier::{Identifiable, Identifier}; use rspack_loader_preact_refresh::PREACT_REFRESH_LOADER_IDENTIFIER; use rspack_loader_react_refresh::REACT_REFRESH_LOADER_IDENTIFIER; use rspack_loader_swc::SWC_LOADER_IDENTIFIER; +use rspack_plugin_rsc::{ + RSCClientEntryLoader, RSCProxyLoader, RSC_CLIENT_ENTRY_LOADER_IDENTIFIER, + RSC_PROXY_LOADER_IDENTIFIER, +}; use super::{JsLoaderRspackPlugin, JsLoaderRspackPluginInner}; @@ -54,6 +58,26 @@ pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> BoxLoader { if builtin.starts_with(rspack_loader_testing::PITCHING_LOADER_IDENTIFIER) { return Arc::new(rspack_loader_testing::PitchingLoader); } + if builtin.starts_with(RSC_PROXY_LOADER_IDENTIFIER) { + return Arc::new( + RSCProxyLoader::new( + serde_json::from_str(options.unwrap_or("{}")).unwrap_or_else(|e| { + panic!("Could not parse builtin:rsc-proxy-loader options:{options:?},error: {e:?}") + }), + ) + .with_identifier(builtin.into()), + ); + } + if builtin.starts_with(RSC_CLIENT_ENTRY_LOADER_IDENTIFIER) { + return Arc::new( + RSCClientEntryLoader::new( + serde_json::from_str(options.unwrap_or("{}")).unwrap_or_else(|e| { + panic!("Could not parse builtin:rsc-client-entry-loader options:{options:?},error: {e:?}") + }), + ) + .with_identifier(builtin.into()), + ); + } unreachable!("Unexpected builtin loader: {builtin}") } diff --git a/crates/rspack_plugin_rsc/src/loader/rsc_client_entry_loader.rs b/crates/rspack_plugin_rsc/src/loader/rsc_client_entry_loader.rs index 103c7ccfa740..0f2d8869915c 100644 --- a/crates/rspack_plugin_rsc/src/loader/rsc_client_entry_loader.rs +++ b/crates/rspack_plugin_rsc/src/loader/rsc_client_entry_loader.rs @@ -5,7 +5,7 @@ use std::{ use indexmap::set::IndexSet; use itertools::Itertools; -use rspack_core::{LoaderRunnerContext, Mode}; +use rspack_core::{Mode, RunnerContext}; use rspack_error::Result; use rspack_loader_runner::{Identifiable, Identifier, Loader, LoaderContext}; use serde::{Deserialize, Serialize}; @@ -117,8 +117,8 @@ impl RSCClientEntryLoader { pub const RSC_CLIENT_ENTRY_LOADER_IDENTIFIER: &str = "builtin:rsc-client-entry-loader"; #[async_trait::async_trait] -impl Loader for RSCClientEntryLoader { - async fn run(&self, loader_context: &mut LoaderContext<'_, LoaderRunnerContext>) -> Result<()> { +impl Loader for RSCClientEntryLoader { + async fn run(&self, loader_context: &mut LoaderContext) -> Result<()> { let content = std::mem::take(&mut loader_context.content).expect("Content should be available"); let resource_path = loader_context.resource_path().to_str(); let mut source = content.try_into_string()?; diff --git a/crates/rspack_plugin_rsc/src/loader/rsc_proxy_loader.rs b/crates/rspack_plugin_rsc/src/loader/rsc_proxy_loader.rs index bef28082cfac..aae90052d351 100644 --- a/crates/rspack_plugin_rsc/src/loader/rsc_proxy_loader.rs +++ b/crates/rspack_plugin_rsc/src/loader/rsc_proxy_loader.rs @@ -1,4 +1,4 @@ -use rspack_core::LoaderRunnerContext; +use rspack_core::RunnerContext; use rspack_error::Result; use rspack_loader_runner::{Identifiable, Identifier, Loader, LoaderContext}; use serde::{Deserialize, Serialize}; @@ -37,8 +37,8 @@ impl RSCProxyLoader { pub const RSC_PROXY_LOADER_IDENTIFIER: &str = "builtin:rsc-proxy-loader"; #[async_trait::async_trait] -impl Loader for RSCProxyLoader { - async fn run(&self, loader_context: &mut LoaderContext<'_, LoaderRunnerContext>) -> Result<()> { +impl Loader for RSCProxyLoader { + async fn run(&self, loader_context: &mut LoaderContext) -> Result<()> { let resource_path = loader_context.resource_path().to_path_buf(); let content = std::mem::take(&mut loader_context.content).expect("content should be available"); diff --git a/packages/rspack/src/builtin-plugin/RSCClientReferenceManifestRspackPlugin.ts b/packages/rspack/src/builtin-plugin/RSCClientReferenceManifestRspackPlugin.ts index cc4c84034fce..74c26b965c45 100644 --- a/packages/rspack/src/builtin-plugin/RSCClientReferenceManifestRspackPlugin.ts +++ b/packages/rspack/src/builtin-plugin/RSCClientReferenceManifestRspackPlugin.ts @@ -1,6 +1,6 @@ +import path from "path"; import type { RawRscClientReferenceManifestRspackPluginOptions } from "@rspack/binding"; import { BuiltinPluginName } from "@rspack/binding"; -import path from "path"; import type { Compiler } from "../Compiler"; import type { RuleSetCondition } from "../config/zod";