Skip to content

Commit

Permalink
Merge branch 'main' into doc_check_ci_1231
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jan 1, 2025
2 parents 2195f31 + 5d68be6 commit 9247ef9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ impl JavascriptParserPlugin for CompatibilityPlugin {
decl: &swc_core::ecma::ast::VarDeclarator,
_statement: &swc_core::ecma::ast::VarDecl,
) -> Option<bool> {
if let Some(ident) = decl.name.as_ident()
&& ident.sym.as_str() == RuntimeGlobals::REQUIRE.name()
{
let ident = decl.name.as_ident()?;

if ident.sym.as_str() == RuntimeGlobals::REQUIRE.name() {
let start = ident.span().real_lo();
let end = ident.span().real_hi();
self.tag_nested_require_data(
Expand All @@ -111,7 +111,17 @@ impl JavascriptParserPlugin for CompatibilityPlugin {
end,
);
return Some(true);
} else if ident.sym == RuntimeGlobals::EXPORTS.name() {
self.tag_nested_require_data(
parser,
ident.sym.to_string(),
"__nested_webpack_exports__".to_string(),
ident.span().real_lo(),
ident.span().real_hi(),
);
return Some(true);
}

None
}

Expand Down
72 changes: 43 additions & 29 deletions crates/rspack_storage/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,39 @@ impl ValidateResult {
}

#[derive(Debug)]
enum ErrorReason {
pub enum ErrorReason {
Reason(String),
Detail(InvalidDetail),
Error(Box<dyn std::error::Error + Send + Sync>),
}

impl std::fmt::Display for ErrorReason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ErrorReason::Detail(detail) => {
write!(f, "{}", detail.reason)?;
for line in detail.packs.iter().take(5) {
write!(f, "\n{}", line)?;
}
if detail.packs.len() > 5 {
write!(f, "\n...")?;
}
}
ErrorReason::Error(e) => {
if let Some(e) = e.downcast_ref::<Error>() {
write!(f, "{}", e.inner)?;
} else {
write!(f, "{}", e)?;
}
}
ErrorReason::Reason(e) => {
write!(f, "{}", e)?;
}
};
Ok(())
}
}

#[derive(Debug)]
pub enum ErrorType {
Validate,
Expand Down Expand Up @@ -124,40 +151,27 @@ impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(t) = &self.r#type {
write!(f, "{} ", t)?;
}
if let Some(scope) = self.scope {
write!(f, "scope `{}` ", scope)?;
}
write!(f, "failed due to")?;

match &self.inner {
ErrorReason::Detail(detail) => {
write!(f, " {}", detail.reason)?;
let mut pack_info_lines = detail
.packs
.iter()
.map(|p| format!("- {}", p))
.collect::<Vec<_>>();
if pack_info_lines.len() > 5 {
pack_info_lines.truncate(5);
pack_info_lines.push("...".to_string());
}
if !pack_info_lines.is_empty() {
write!(f, ":\n{}", pack_info_lines.join("\n"))?;
}
}
ErrorReason::Error(e) => {
write!(f, " {}", e)?;
}
ErrorReason::Reason(e) => {
write!(f, " {}", e)?;
if let Some(scope) = self.scope {
write!(f, "scope `{}` ", scope)?;
}
write!(f, "failed due to")?;
write!(f, " {}", self.inner)?;
} else {
write!(f, "{}", self.inner)?;
}

Ok(())
}
}

impl std::error::Error for Error {}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &self.inner {
ErrorReason::Error(error) => error.source(),
_ => None,
}
}
}

impl miette::Diagnostic for Error {
fn code<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
Expand Down
11 changes: 5 additions & 6 deletions crates/rspack_storage/src/fs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,14 @@ impl std::fmt::Display for BatchFSError {
write!(f, "{}", self.message)?;
if let Some(join_error) = &self.join_error {
write!(f, " due to `{}`", join_error)?;
}
if self.errors.len() == 1 {
write!(f, "{}", self.errors[0])?;
} else {
for error in &self.errors {
write!(f, "\n- {}", error)?;
for error in self.errors.iter().take(5) {
write!(f, "\n{}", error)?;
}
if self.errors.len() > 5 {
write!(f, "\n...")?;
}
}

Ok(())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("./lib");
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var __webpack_exports__ = {};
__webpack_exports__.e = 42;

it("rename top level (avoid override by inner graph top level symbol)", () => {
expect(__webpack_exports__.e).toBe(42);
const lib2 = require("./lib2");
expect(lib2.a).toBe(1)
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const a = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
mode: "production",
optimization: {
innerGraph: true,
}
}

0 comments on commit 9247ef9

Please sign in to comment.