From ac9d733d8b6f12aaf96a29ef9fe583457cee7fe1 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Tue, 22 Nov 2022 13:09:33 +0100 Subject: [PATCH 1/2] match src directory --- .../next/server/get-app-route-from-entrypoint.ts | 4 ++-- test/e2e/app-dir/app-alias.test.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/next/server/get-app-route-from-entrypoint.ts b/packages/next/server/get-app-route-from-entrypoint.ts index 28e4870e709a..3e59c81f7e65 100644 --- a/packages/next/server/get-app-route-from-entrypoint.ts +++ b/packages/next/server/get-app-route-from-entrypoint.ts @@ -1,7 +1,7 @@ import matchBundle from './match-bundle' -// matches app/:path*.js -const APP_ROUTE_NAME_REGEX = /^app[/\\](.*)$/ +// matches app/:path*.js and src/app/:path*.js +const APP_ROUTE_NAME_REGEX = /^(?:app|src[/\\]app)[/\\](.*)$/ export default function getAppRouteFromEntrypoint(entryFile: string) { const pagePath = matchBundle(APP_ROUTE_NAME_REGEX, entryFile) diff --git a/test/e2e/app-dir/app-alias.test.ts b/test/e2e/app-dir/app-alias.test.ts index 3b8c434d0507..b642c9c04140 100644 --- a/test/e2e/app-dir/app-alias.test.ts +++ b/test/e2e/app-dir/app-alias.test.ts @@ -3,6 +3,7 @@ import { NextInstance } from 'test/lib/next-modes/base' import { renderViaHTTP } from 'next-test-utils' import webdriver from 'next-webdriver' import path from 'path' +import { readJSON } from 'fs-extra' describe('app-dir alias handling', () => { if ((global as any).isNextDeploy) { @@ -41,4 +42,15 @@ describe('app-dir alias handling', () => { .getComputedCss('font-size') expect(fontSize).toBe('50px') }) + + if (!(global as any).isNextDev) { + it.only('should generate app-build-manifest correctly', async () => { + // Remove other page CSS files: + const manifest = await readJSON( + path.join(next.testDir, '.next', 'app-build-manifest.json') + ) + + expect(manifest.pages).not.toBeEmptyObject() + }) + } }) From e702ff375cc7a9f89d71ef13a5f0bfcdbce9901d Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Tue, 22 Nov 2022 13:31:14 +0100 Subject: [PATCH 2/2] fix entry creation --- .../next/build/webpack/plugins/flight-client-entry-plugin.ts | 4 +++- packages/next/server/get-app-route-from-entrypoint.ts | 4 ++-- test/e2e/app-dir/app-alias.test.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts b/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts index 2df42a8d9053..77545f5c2b85 100644 --- a/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts +++ b/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts @@ -203,7 +203,9 @@ export class FlightClientEntryPlugin { : entryRequest // Replace file suffix as `.js` will be added. - const bundlePath = relativeRequest.replace(/\.(js|ts)x?$/, '') + const bundlePath = relativeRequest + .replace(/\.(js|ts)x?$/, '') + .replace(/^src[\\/]/, '') promises.push( this.injectClientEntryAndSSRModules({ diff --git a/packages/next/server/get-app-route-from-entrypoint.ts b/packages/next/server/get-app-route-from-entrypoint.ts index 3e59c81f7e65..28e4870e709a 100644 --- a/packages/next/server/get-app-route-from-entrypoint.ts +++ b/packages/next/server/get-app-route-from-entrypoint.ts @@ -1,7 +1,7 @@ import matchBundle from './match-bundle' -// matches app/:path*.js and src/app/:path*.js -const APP_ROUTE_NAME_REGEX = /^(?:app|src[/\\]app)[/\\](.*)$/ +// matches app/:path*.js +const APP_ROUTE_NAME_REGEX = /^app[/\\](.*)$/ export default function getAppRouteFromEntrypoint(entryFile: string) { const pagePath = matchBundle(APP_ROUTE_NAME_REGEX, entryFile) diff --git a/test/e2e/app-dir/app-alias.test.ts b/test/e2e/app-dir/app-alias.test.ts index b642c9c04140..e857c483236b 100644 --- a/test/e2e/app-dir/app-alias.test.ts +++ b/test/e2e/app-dir/app-alias.test.ts @@ -44,7 +44,7 @@ describe('app-dir alias handling', () => { }) if (!(global as any).isNextDev) { - it.only('should generate app-build-manifest correctly', async () => { + it('should generate app-build-manifest correctly', async () => { // Remove other page CSS files: const manifest = await readJSON( path.join(next.testDir, '.next', 'app-build-manifest.json')