Skip to content

Commit

Permalink
fix: css parse error recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangWeixian committed Jun 12, 2024
1 parent f16dafe commit bea5815
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions crates/rspack_binding_options/src/plugins/js_loader/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<LoaderRunnerContext> for RSCClientEntryLoader {
async fn run(&self, loader_context: &mut LoaderContext<'_, LoaderRunnerContext>) -> Result<()> {
impl Loader<RunnerContext> for RSCClientEntryLoader {
async fn run(&self, loader_context: &mut LoaderContext<RunnerContext>) -> 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()?;
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_plugin_rsc/src/loader/rsc_proxy_loader.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -37,8 +37,8 @@ impl RSCProxyLoader {
pub const RSC_PROXY_LOADER_IDENTIFIER: &str = "builtin:rsc-proxy-loader";

#[async_trait::async_trait]
impl Loader<LoaderRunnerContext> for RSCProxyLoader {
async fn run(&self, loader_context: &mut LoaderContext<'_, LoaderRunnerContext>) -> Result<()> {
impl Loader<RunnerContext> for RSCProxyLoader {
async fn run(&self, loader_context: &mut LoaderContext<RunnerContext>) -> 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");

Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit bea5815

Please sign in to comment.