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(turbopack): Handle fragment in requests #7771

Merged
merged 30 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 23 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
41 changes: 35 additions & 6 deletions crates/turbopack-core/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,7 @@ async fn resolve_internal_inline(
path,
query,
force_in_lookup_dir,
fragment,
} => {
let mut results = Vec::new();
let matches = read_matches(
Expand All @@ -1556,6 +1557,7 @@ async fn resolve_internal_inline(
options_value,
options,
*query,
*fragment,
)
.await?,
);
Expand All @@ -1575,6 +1577,7 @@ async fn resolve_internal_inline(
path,
query,
force_in_lookup_dir,
fragment,
} => {
resolve_relative_request(
lookup_path,
Expand All @@ -1584,13 +1587,15 @@ async fn resolve_internal_inline(
path,
*query,
*force_in_lookup_dir,
*fragment,
)
.await?
}
Request::Module {
module,
path,
query,
fragment,
} => {
resolve_module_request(
lookup_path,
Expand All @@ -1600,13 +1605,18 @@ async fn resolve_internal_inline(
module,
path,
*query,
*fragment,
)
.await?
}
Request::ServerRelative { path, query } => {
Request::ServerRelative {
path,
query,
fragment,
} => {
let mut new_pat = path.clone();
new_pat.push_front(".".to_string().into());
let relative = Request::relative(Value::new(new_pat), *query, true);
let relative = Request::relative(Value::new(new_pat), *query, true, *fragment);

ResolvingIssue {
severity: IssueSeverity::Error.cell(),
Expand All @@ -1631,7 +1641,11 @@ async fn resolve_internal_inline(
)
.await?
}
Request::Windows { path: _, query: _ } => {
Request::Windows {
path: _,
query: _,
fragment: _,
} => {
ResolvingIssue {
severity: IssueSeverity::Error.cell(),
request_type: "windows import: not implemented yet".to_string(),
Expand Down Expand Up @@ -1673,6 +1687,8 @@ async fn resolve_internal_inline(
Request::Uri {
protocol,
remainder,
query: _,
fragment: _,
} => {
let uri = format!("{}{}", protocol, remainder);
ResolveResult::primary_with_key(
Expand Down Expand Up @@ -1803,6 +1819,7 @@ async fn resolve_relative_request(
path_pattern: &Pattern,
query: Vc<String>,
force_in_lookup_dir: bool,
fragment: Vc<String>,
) -> Result<Vc<ResolveResult>> {
// Check alias field for aliases first
let lookup_path_ref = &*lookup_path.await?;
Expand All @@ -1817,6 +1834,7 @@ async fn resolve_relative_request(
Some(request)
},
query,
fragment.clone(),
)
.await?
{
Expand Down Expand Up @@ -1867,6 +1885,7 @@ async fn resolve_relative_request(
options_value,
options,
query,
fragment.clone(),
)
.await?,
);
Expand All @@ -1884,6 +1903,7 @@ async fn resolve_relative_request(
options_value,
options,
query,
fragment.clone(),
)
.await?,
);
Expand All @@ -1907,6 +1927,7 @@ async fn apply_in_package(
options_value: &ResolveOptions,
get_request: impl Fn(&FileSystemPath) -> Option<String>,
query: Vc<String>,
fragment: Vc<String>,
) -> Result<Option<Vc<ResolveResult>>> {
// Check alias field for module aliases first
for in_package in options_value.in_package.iter() {
Expand Down Expand Up @@ -1972,7 +1993,8 @@ async fn apply_in_package(
resolve_internal(
package_path,
Request::parse(Value::new(Pattern::Constant(value.to_string())))
.with_query(query),
.with_query(query)
.with_fragment(fragment),
options,
)
.with_replaced_request_key(value.to_string(), Value::new(request_key))
Expand Down Expand Up @@ -2008,6 +2030,7 @@ async fn resolve_module_request(
module: &str,
path: &Pattern,
query: Vc<String>,
fragment: Vc<String>,
) -> Result<Vc<ResolveResult>> {
// Check alias field for module aliases first
if let Some(result) = apply_in_package(
Expand All @@ -2019,6 +2042,7 @@ async fn resolve_module_request(
full_pattern.into_string()
},
query,
fragment.clone(),
)
.await?
{
Expand Down Expand Up @@ -2053,6 +2077,7 @@ async fn resolve_module_request(
Value::new(path.clone()),
package_path,
query,
fragment.clone(),
options,
));
}
Expand All @@ -2066,6 +2091,7 @@ async fn resolve_module_request(
options_value,
options,
query,
fragment.clone(),
)
.await?;
results.push(resolved)
Expand All @@ -2088,7 +2114,7 @@ async fn resolve_module_request(
"/".to_string().into(),
path.clone(),
]);
let relative = Request::relative(Value::new(pattern), query, true);
let relative = Request::relative(Value::new(pattern), query, true, fragment.clone());
let relative_result =
resolve_internal_boxed(lookup_path, relative.resolve().await?, options).await?;
let relative_result = relative_result.with_replaced_request_key(
Expand All @@ -2107,6 +2133,7 @@ async fn resolve_into_package(
path: Value<Pattern>,
package_path: Vc<FileSystemPath>,
query: Vc<String>,
fragment: Vc<String>,
options: Vc<ResolveOptions>,
) -> Result<Vc<ResolveResult>> {
let path = path.into_value();
Expand Down Expand Up @@ -2171,7 +2198,7 @@ async fn resolve_into_package(
let mut new_pat = path.clone();
new_pat.push_front(".".to_string().into());

let relative = Request::relative(Value::new(new_pat), query, true);
let relative = Request::relative(Value::new(new_pat), query, true, fragment);
results
.push(resolve_internal_inline(package_path, relative.resolve().await?, options).await?);
}
Expand Down Expand Up @@ -2255,6 +2282,7 @@ async fn resolved(
options_value: &ResolveOptions,
options: Vc<ResolveOptions>,
query: Vc<String>,
fragment: Vc<String>,
) -> Result<Vc<ResolveResult>> {
let RealPathResult { path, symlinks } = &*fs_path.realpath_with_links().await?;

Expand All @@ -2266,6 +2294,7 @@ async fn resolved(
options_value,
|package_path| package_path.get_relative_path_to(path_ref),
query,
fragment.clone(),
)
.await?
{
Expand Down
Loading
Loading