Unverified Commit b3071ad4 authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

fix(turbopack): ignore underscore_started path (#48792)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change



### Why?

### How?

Closes NEXT-
Fixes #

-->

### What?

This PR changes turbopack's appDir source lookup to honor existing
behavior to ignore `_` started path. With this changes, turbopack able
to pass test
`test/e2e/app-dir/underscore-ignore-app-paths/underscore-ignore-app-paths.test.ts`,
fixes WEB-844.

Internally it simply amends two parts, first if given path starts with
_, do not add those into entrypoints to it will not be served. If path
starts with `%5F` instead, replacing path to _ so it can be served.

---------
Co-authored-by: 's avatarTobias Koppers <tobias.koppers@googlemail.com>
parent 59e9b433
...@@ -378,8 +378,11 @@ async fn get_directory_tree( ...@@ -378,8 +378,11 @@ async fn get_directory_tree(
} }
} }
DirectoryEntry::Directory(dir) => { DirectoryEntry::Directory(dir) => {
let result = get_directory_tree(dir, page_extensions); // appDir ignores paths starting with an underscore
subdirectories.insert(basename.to_string(), result); if !basename.starts_with('_') {
let result = get_directory_tree(dir, page_extensions);
subdirectories.insert(get_underscore_normalized_path(basename), result);
}
} }
// TODO(WEB-952) handle symlinks in app dir // TODO(WEB-952) handle symlinks in app dir
_ => {} _ => {}
...@@ -694,6 +697,12 @@ async fn directory_tree_to_entrypoints_internal( ...@@ -694,6 +697,12 @@ async fn directory_tree_to_entrypoints_internal(
Ok(EntrypointsVc::cell(result)) 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", "_")
}
/// Returns the global metadata for an app directory. /// Returns the global metadata for an app directory.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn get_global_metadata( pub async fn get_global_metadata(
......
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