Skip to content

Commit

Permalink
fix(turbopack): ignore underscore_started path
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Apr 26, 2023
1 parent 2f6ff0d commit 25feecd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/next-swc/crates/next-core/src/app_structure.rs
Expand Up @@ -373,6 +373,7 @@ async fn add_app_page(
key: String,
loader_tree: LoaderTreeVc,
) -> Result<()> {
let key = get_underscore_normalized_path(&key);
match result.entry(key) {
Entry::Occupied(mut e) => {
let value = e.get_mut();
Expand Down Expand Up @@ -401,6 +402,7 @@ async fn add_app_route(
key: String,
path: FileSystemPathVc,
) -> Result<()> {
let key = get_underscore_normalized_path(&key);
match result.entry(key) {
Entry::Occupied(mut e) => {
DirectoryTreeIssue {
Expand Down Expand Up @@ -442,6 +444,11 @@ async fn directory_tree_to_entrypoints_internal(
) -> Result<EntrypointsVc> {
let mut result = IndexMap::new();

// appDir ignores paths starting with an underscore
if directory_name.starts_with('_') {
return Ok(Entrypoints(result).cell());
}

let directory_tree = &*directory_tree.await?;

let subdirectories = &directory_tree.subdirectories;
Expand All @@ -467,7 +474,7 @@ async fn directory_tree_to_entrypoints_internal(
.cell()
} else {
LoaderTree {
segment: directory_name.to_string(),
segment: get_underscore_normalized_path(directory_name),
parallel_routes: indexmap! {
"children".to_string() => LoaderTree {
segment: "__PAGE__".to_string(),
Expand Down Expand Up @@ -506,7 +513,7 @@ async fn directory_tree_to_entrypoints_internal(
.cell()
} else {
LoaderTree {
segment: directory_name.to_string(),
segment: get_underscore_normalized_path(directory_name),
parallel_routes: indexmap! {
"children".to_string() => LoaderTree {
segment: "__DEFAULT__".to_string(),
Expand Down Expand Up @@ -556,7 +563,7 @@ async fn directory_tree_to_entrypoints_internal(
} else {
let key = parallel_route_key.unwrap_or("children").to_string();
let child_loader_tree = LoaderTree {
segment: directory_name.to_string(),
segment: get_underscore_normalized_path(directory_name),
parallel_routes: indexmap! {
key => loader_tree,
},
Expand All @@ -576,6 +583,12 @@ async fn directory_tree_to_entrypoints_internal(
Ok(EntrypointsVc::cell(result))
}

/// ref: https://github.com/vercel/next.js/blob/c390c1662bc79e12cf7c037dcb382ef5ead6e492/packages/next/src/build/entries.ts#L119
/// if path contains %5F, replace it with _.
fn get_underscore_normalized_path(path: &str) -> String {
path.replace("%5F", "_")
}

#[turbo_tasks::value(shared)]
struct DirectoryTreeIssue {
pub severity: IssueSeverityVc,
Expand Down

0 comments on commit 25feecd

Please sign in to comment.