From 31c14698102cd2a8abec5de5b4a886e71113260a Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 1 Jul 2023 15:20:31 +0200 Subject: [PATCH 1/2] entry.server and entry.client --- packages/project-config/src/paths.ts | 8 +++++++- packages/vite/src/buildFeServer.ts | 4 +++- packages/vite/src/devFeServer.ts | 4 +++- packages/vite/src/runFeServer.ts | 4 +--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/project-config/src/paths.ts b/packages/project-config/src/paths.ts index 56f7c42272ca..03c1eef8757b 100644 --- a/packages/project-config/src/paths.ts +++ b/packages/project-config/src/paths.ts @@ -46,6 +46,7 @@ export interface WebPaths { storybookManagerConfig: string dist: string distServer: string + distEntryServer: string distRouteHooks: string routeManifest: string types: string @@ -105,7 +106,7 @@ const PATH_WEB_DIR_CONFIG = 'web/config' const PATH_WEB_DIR_CONFIG_WEBPACK = 'web/config/webpack.config.js' const PATH_WEB_DIR_CONFIG_VITE = 'web/vite.config' // .js,.ts const PATH_WEB_DIR_ENTRY_CLIENT = 'web/src/entry.client' // .jsx,.tsx -const PATH_WEB_DIR_ENTRY_SERVER = 'web/src/entry-server' // .jsx,.tsx +const PATH_WEB_DIR_ENTRY_SERVER = 'web/src/entry.server' // .jsx,.tsx const PATH_WEB_DIR_CONFIG_POSTCSS = 'web/config/postcss.config.js' const PATH_WEB_DIR_CONFIG_STORYBOOK_CONFIG = 'web/config/storybook.config.js' @@ -114,6 +115,7 @@ const PATH_WEB_DIR_CONFIG_STORYBOOK_MANAGER = 'web/config/storybook.manager.js' const PATH_WEB_DIR_DIST = 'web/dist' const PATH_WEB_DIR_DIST_SERVER = 'web/dist/server' +const PATH_WEB_DIR_DIST_SERVER_ENTRY_SERVER = 'web/dist/server/entry.server.js' const PATH_WEB_DIR_DIST_SERVER_ROUTEHOOKS = 'web/dist/server/routeHooks' const PATH_WEB_DIR_ROUTE_MANIFEST = 'web/dist/server/route-manifest.json' @@ -221,6 +223,10 @@ export const getPaths = (BASE_DIR: string = getBaseDir()): Paths => { ), dist: path.join(BASE_DIR, PATH_WEB_DIR_DIST), distServer: path.join(BASE_DIR, PATH_WEB_DIR_DIST_SERVER), + distEntryServer: path.join( + BASE_DIR, + PATH_WEB_DIR_DIST_SERVER_ENTRY_SERVER + ), distRouteHooks: path.join(BASE_DIR, PATH_WEB_DIR_DIST_SERVER_ROUTEHOOKS), routeManifest: path.join(BASE_DIR, PATH_WEB_DIR_ROUTE_MANIFEST), types: path.join(BASE_DIR, 'web/types'), diff --git a/packages/vite/src/buildFeServer.ts b/packages/vite/src/buildFeServer.ts index 7eb123f411e4..938d26d603e2 100644 --- a/packages/vite/src/buildFeServer.ts +++ b/packages/vite/src/buildFeServer.ts @@ -29,7 +29,9 @@ export const buildFeServer = async ({ verbose }: BuildOptions) => { if (!rwPaths.web.entryServer || !rwPaths.web.entryClient) { throw new Error( - 'Vite entry points not found. Please check that your project has an entry-client.{jsx,tsx} and entry-server.{jsx,tsx} file in the web/src directory.' + 'Vite entry points not found. Please check that your project has an ' + + 'entry.client.{jsx,tsx} and entry.server.{jsx,tsx} file in the ' + + 'web/src directory.' ) } diff --git a/packages/vite/src/devFeServer.ts b/packages/vite/src/devFeServer.ts index 7f0a95194655..81ce742eef94 100644 --- a/packages/vite/src/devFeServer.ts +++ b/packages/vite/src/devFeServer.ts @@ -97,7 +97,9 @@ async function createServer() { if (!rwPaths.web.entryServer || !rwPaths.web.entryClient) { throw new Error( - 'Vite entry points not found. Please check that your project has an entry-client.{jsx,tsx} and entry-server.{jsx,tsx} file in the web/src directory.' + 'Vite entry points not found. Please check that your project has ' + + 'an entry.client.{jsx,tsx} and entry.server.{jsx,tsx} file in ' + + 'the web/src directory.' ) } diff --git a/packages/vite/src/runFeServer.ts b/packages/vite/src/runFeServer.ts index 9aefa342c38a..bc5deb487785 100644 --- a/packages/vite/src/runFeServer.ts +++ b/packages/vite/src/runFeServer.ts @@ -95,9 +95,7 @@ export async function runFeServer() { const currentPathName = stripQueryStringAndHashFromPath(req.originalUrl) try { - const { serverEntry } = await import( - path.join(rwPaths.web.distServer, '/entry-server.js') - ) + const { serverEntry } = await import(rwPaths.web.distEntryServer) // TODO (STREAMING) should we generate individual express Routes for each Route? // This would make handling 404s and favicons / public assets etc. easier From 48e6878e0b9d50bcbe2aa3c15ca8ac7292039a07 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 1 Jul 2023 15:54:38 +0200 Subject: [PATCH 2/2] Fix unit tests --- .../src/__tests__/paths.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/project-config/src/__tests__/paths.test.ts b/packages/project-config/src/__tests__/paths.test.ts index df64ffd2eb0f..eb223a5a2413 100644 --- a/packages/project-config/src/__tests__/paths.test.ts +++ b/packages/project-config/src/__tests__/paths.test.ts @@ -142,6 +142,13 @@ describe('paths', () => { 'storybook.manager.js' ), dist: path.join(FIXTURE_BASEDIR, 'web', 'dist'), + distEntryServer: path.join( + FIXTURE_BASEDIR, + 'web', + 'dist', + 'server', + 'entry.server.js' + ), distRouteHooks: path.join( FIXTURE_BASEDIR, 'web', @@ -397,6 +404,13 @@ describe('paths', () => { 'storybook.manager.js' ), dist: path.join(FIXTURE_BASEDIR, 'web', 'dist'), + distEntryServer: path.join( + FIXTURE_BASEDIR, + 'web', + 'dist', + 'server', + 'entry.server.js' + ), distRouteHooks: path.join( FIXTURE_BASEDIR, 'web', @@ -700,6 +714,13 @@ describe('paths', () => { entryClient: null, entryServer: null, dist: path.join(FIXTURE_BASEDIR, 'web', 'dist'), + distEntryServer: path.join( + FIXTURE_BASEDIR, + 'web', + 'dist', + 'server', + 'entry.server.js' + ), distRouteHooks: path.join( FIXTURE_BASEDIR, 'web', @@ -956,6 +977,13 @@ describe('paths', () => { 'storybook.manager.js' ), dist: path.join(FIXTURE_BASEDIR, 'web', 'dist'), + distEntryServer: path.join( + FIXTURE_BASEDIR, + 'web', + 'dist', + 'server', + 'entry.server.js' + ), distRouteHooks: path.join( FIXTURE_BASEDIR, 'web',