From e58314bbfc89b3f08a10a582d3193a9485e015f6 Mon Sep 17 00:00:00 2001 From: Alexander Sviridov Date: Tue, 18 Oct 2022 00:32:44 +0200 Subject: [PATCH] fix(41456): check src/app folder too in getHasAppDir (#41458) fixes https://github.com/vercel/next.js/issues/41456 When we check if app folder exists, check for src/app path too ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) Co-authored-by: Jiachi Liu Co-authored-by: JJ Kasper --- packages/next/lib/find-pages-dir.ts | 2 +- packages/next/server/dev/next-dev-server.ts | 4 +++- packages/next/server/next-server.ts | 11 ++--------- .../app-dir/app-alias/{ => src}/app/button/page.tsx | 0 test/e2e/app-dir/app-alias/{ => src}/app/layout.tsx | 0 5 files changed, 6 insertions(+), 11 deletions(-) rename test/e2e/app-dir/app-alias/{ => src}/app/button/page.tsx (100%) rename test/e2e/app-dir/app-alias/{ => src}/app/layout.tsx (100%) diff --git a/packages/next/lib/find-pages-dir.ts b/packages/next/lib/find-pages-dir.ts index 0de35966f5616..966766309cfb8 100644 --- a/packages/next/lib/find-pages-dir.ts +++ b/packages/next/lib/find-pages-dir.ts @@ -10,7 +10,7 @@ export const existsSync = (f: string): boolean => { } } -function findDir(dir: string, name: 'pages' | 'app'): string | null { +export function findDir(dir: string, name: 'pages' | 'app'): string | null { // prioritize ./${name} over ./src/${name} let curDir = path.join(dir, name) if (existsSync(curDir)) return curDir diff --git a/packages/next/server/dev/next-dev-server.ts b/packages/next/server/dev/next-dev-server.ts index cc34cfb70d123..c5c2f986039fb 100644 --- a/packages/next/server/dev/next-dev-server.ts +++ b/packages/next/server/dev/next-dev-server.ts @@ -305,7 +305,9 @@ export default class DevServer extends Server { ignored: (pathname: string) => { return ( !files.some((file) => file.startsWith(pathname)) && - !directories.some((dir) => pathname.startsWith(dir)) + !directories.some( + (dir) => pathname.startsWith(dir) || dir.startsWith(pathname) + ) ) }, })) diff --git a/packages/next/server/next-server.ts b/packages/next/server/next-server.ts index 5de216bb08dfa..ef5a0a3bfc325 100644 --- a/packages/next/server/next-server.ts +++ b/packages/next/server/next-server.ts @@ -48,6 +48,7 @@ import { FONT_LOADER_MANIFEST, } from '../shared/lib/constants' import { recursiveReadDirSync } from './lib/recursive-readdir-sync' +import { findDir } from '../lib/find-pages-dir' import { format as formatUrl, UrlWithParsedQuery } from 'url' import compression from 'next/dist/compiled/compression' import { getPathMatch } from '../shared/lib/router/utils/path-match' @@ -474,15 +475,7 @@ export default class NextNodeServer extends BaseServer { } protected getHasAppDir(dev: boolean): boolean { - const appDirectory = dev - ? join(this.dir, 'app') - : join(this.serverDistDir, 'app') - - try { - return fs.statSync(appDirectory).isDirectory() - } catch (err) { - return false - } + return Boolean(findDir(dev ? this.dir : this.serverDistDir, 'app')) } protected generateStaticRoutes(): Route[] { diff --git a/test/e2e/app-dir/app-alias/app/button/page.tsx b/test/e2e/app-dir/app-alias/src/app/button/page.tsx similarity index 100% rename from test/e2e/app-dir/app-alias/app/button/page.tsx rename to test/e2e/app-dir/app-alias/src/app/button/page.tsx diff --git a/test/e2e/app-dir/app-alias/app/layout.tsx b/test/e2e/app-dir/app-alias/src/app/layout.tsx similarity index 100% rename from test/e2e/app-dir/app-alias/app/layout.tsx rename to test/e2e/app-dir/app-alias/src/app/layout.tsx