Skip to content
Merged
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
14 changes: 14 additions & 0 deletions turbopack/crates/turbopack-core/src/resolve/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ impl Request {
return Request::Empty;
}

// Handle webpack-style tilde prefix (~) for node_modules resolution
// This is commonly used in CSS preprocessors like less-loader and sass-loader
// Only strip ~ if it's followed by a module path (not a relative path like ~/home)
// for utoopack issue: https://github.com/utooland/utoo/issues/2309

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

通常来说,最好将问题跟踪器的链接放在提交信息或 PR 描述中,而不是代码注释里。这样能保持代码整洁,并避免在问题跟踪器 URL 更改或问题关闭时注释变得过时。Git 历史是记录这类元数据的更合适的地方。

let r = if let Some(remainder) = r
.strip_prefix('~')
.filter(|s| !s.is_empty() && !s.starts_with('/') && !s.starts_with('\\'))
.filter(|s| MODULE_PATH.is_match(s))
{
remainder.into()
} else {
r
};
Comment on lines +169 to +177

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这个 if let ... else 语句块可以重构为一个更简洁、更符合 Rust 语言习惯的函数式风格链式调用。使用 mapunwrap_or 可以将转换逻辑表达为单个表达式,从而提高可读性。

Suggested change
let r = if let Some(remainder) = r
.strip_prefix('~')
.filter(|s| !s.is_empty() && !s.starts_with('/') && !s.starts_with('\\'))
.filter(|s| MODULE_PATH.is_match(s))
{
remainder.into()
} else {
r
};
let r = r
.strip_prefix('~')
.filter(|s| {
!s.is_empty()
&& !s.starts_with('/')
&& !s.starts_with('\')
&& MODULE_PATH.is_match(s)
})
.map(RcStr::from)
.unwrap_or(r);


if let Some(remainder) = r.strip_prefix("//") {
return Request::Uri {
protocol: rcstr!("//"),
Expand Down
Loading