Unverified Commit 85a77c4c authored by Justin Ridgewell's avatar Justin Ridgewell Committed by GitHub

turbopack: Fix pageExtensions with dots (#58504)

### What?

Fixes finding Page/App pages when using a `pageExtension` that itself contains a `.`. Eg, `pages/index.page.js` should match as a Page when using `pageExtensions: ["page.js"]`

### Why?

Matching webpack configurations.

### How?

We split in reverse direction, meaning we'd have a `(basename, ext)` of `('index.page', 'js')`. Webpack [uses forward splitting](https://github.com/vercel/next.js/blob/9ab8828f72e96f5de86a7c50b67a1c5abe6e146c/packages/next/src/build/webpack/loaders/next-metadata-route-loader.ts#L27-L31), giving a proper `('index', 'page.js')`.

Closes PACK-1970
Fixes https://github.com/vercel/turbo/issues/6106
Fixes https://github.com/vercel/next.js/issues/57603
parent 4deb6979
...@@ -377,12 +377,10 @@ async fn get_pages_structure_for_directory( ...@@ -377,12 +377,10 @@ async fn get_pages_structure_for_directory(
} }
fn page_basename<'a>(name: &'a str, page_extensions: &'a [String]) -> Option<&'a str> { fn page_basename<'a>(name: &'a str, page_extensions: &'a [String]) -> Option<&'a str> {
if let Some((basename, extension)) = name.rsplit_once('.') { page_extensions.iter().find_map(|allowed| {
if page_extensions.iter().any(|allowed| allowed == extension) { name.strip_suffix(allowed)
return Some(basename); .and_then(|name| name.strip_suffix('.'))
} })
}
None
} }
fn next_router_path_for_basename( fn next_router_path_for_basename(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment