From 10bc223107b32cc3bca1ad24f0f43fba44821f6a Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Wed, 30 Aug 2023 12:15:28 +0100 Subject: [PATCH] fix(angular): use the correct output path for mf ssr #18849 --- .../generators/host/__snapshots__/host.spec.ts.snap | 4 ++-- .../generators/host/files/src/main.server.ts__tmpl__ | 2 +- packages/angular/src/generators/host/host.spec.ts | 2 +- packages/angular/src/generators/host/lib/add-ssr.ts | 6 ++++++ .../remote/__snapshots__/remote.spec.ts.snap | 4 ++-- .../remote/files/base/src/main.server.ts__tmpl__ | 4 ++-- packages/angular/src/generators/remote/lib/add-ssr.ts | 11 +++++++++++ 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap b/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap index a8c1a5cf82a78a..a3562d04943c1c 100644 --- a/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap +++ b/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap @@ -51,7 +51,7 @@ import { AppServerModule } from './bootstrap.server'; // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); - const browserBundles = join(process.cwd(), 'dist/apps/test/browser'); + const browserBundles = join(process.cwd(), 'dist/test/browser'); server.use(cors()); const indexHtml = existsSync(join(browserBundles, 'index.original.html')) @@ -223,7 +223,7 @@ import bootstrap from './bootstrap.server'; // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); - const browserBundles = join(process.cwd(), 'dist/apps/test/browser'); + const browserBundles = join(process.cwd(), 'dist/test/browser'); server.use(cors()); const indexHtml = existsSync(join(browserBundles, 'index.original.html')) diff --git a/packages/angular/src/generators/host/files/src/main.server.ts__tmpl__ b/packages/angular/src/generators/host/files/src/main.server.ts__tmpl__ index 18327a24df28a4..905a0fd39a60f0 100644 --- a/packages/angular/src/generators/host/files/src/main.server.ts__tmpl__ +++ b/packages/angular/src/generators/host/files/src/main.server.ts__tmpl__ @@ -12,7 +12,7 @@ import<% if(standalone) { %> bootstrap <% } else { %> { AppServerModule } <% } % // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); - const browserBundles = join(process.cwd(), 'dist/apps/<%= appName %>/browser'); + const browserBundles = join(process.cwd(), '<%= browserBundleOutput %>'); server.use(cors()); const indexHtml = existsSync(join(browserBundles, 'index.original.html')) diff --git a/packages/angular/src/generators/host/host.spec.ts b/packages/angular/src/generators/host/host.spec.ts index a6340adc552a81..e6aea5698153f1 100644 --- a/packages/angular/src/generators/host/host.spec.ts +++ b/packages/angular/src/generators/host/host.spec.ts @@ -1,4 +1,4 @@ -import { stripIndents, updateJson } from '@nx/devkit'; +import { stripIndents, updateJson, updateNxJson } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { getProjects, diff --git a/packages/angular/src/generators/host/lib/add-ssr.ts b/packages/angular/src/generators/host/lib/add-ssr.ts index 85c519cba85a9c..452da0af06f51b 100644 --- a/packages/angular/src/generators/host/lib/add-ssr.ts +++ b/packages/angular/src/generators/host/lib/add-ssr.ts @@ -35,8 +35,14 @@ export async function addSsr(tree: Tree, options: Schema, appName: string) { "import('./src/main.server');" ); + const browserBundleOutput = joinPathFragments( + project.targets.build.options.outputPath, + 'browser' + ); + generateFiles(tree, join(__dirname, '../files'), project.root, { appName, + browserBundleOutput, standalone: options.standalone, tmpl: '', }); diff --git a/packages/angular/src/generators/remote/__snapshots__/remote.spec.ts.snap b/packages/angular/src/generators/remote/__snapshots__/remote.spec.ts.snap index 468ffefb7530ac..d4616f812880f8 100644 --- a/packages/angular/src/generators/remote/__snapshots__/remote.spec.ts.snap +++ b/packages/angular/src/generators/remote/__snapshots__/remote.spec.ts.snap @@ -60,8 +60,8 @@ import { AppServerModule } from './bootstrap.server'; // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); - const browserBundles = join(process.cwd(), 'dist/apps/test/browser'); - const serverBundles = join(process.cwd(), 'dist/apps/test/server'); + const browserBundles = join(process.cwd(), 'dist/test/browser'); + const serverBundles = join(process.cwd(), 'dist/test/server'); server.use(cors()); const indexHtml = existsSync(join(browserBundles, 'index.original.html')) diff --git a/packages/angular/src/generators/remote/files/base/src/main.server.ts__tmpl__ b/packages/angular/src/generators/remote/files/base/src/main.server.ts__tmpl__ index a35272773bdd65..2551ff8dd4977a 100644 --- a/packages/angular/src/generators/remote/files/base/src/main.server.ts__tmpl__ +++ b/packages/angular/src/generators/remote/files/base/src/main.server.ts__tmpl__ @@ -12,8 +12,8 @@ import<% if(standalone) { %> bootstrap <% } else { %> { AppServerModule } <% } % // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); - const browserBundles = join(process.cwd(), 'dist/apps/<%= appName %>/browser'); - const serverBundles = join(process.cwd(), 'dist/apps/<%= appName %>/server'); + const browserBundles = join(process.cwd(), '<%= browserBundleOutput %>'); + const serverBundles = join(process.cwd(), '<%= serverBundleOutput %>'); server.use(cors()); const indexHtml = existsSync(join(browserBundles, 'index.original.html')) diff --git a/packages/angular/src/generators/remote/lib/add-ssr.ts b/packages/angular/src/generators/remote/lib/add-ssr.ts index ac404035fab5f3..ff388769457b60 100644 --- a/packages/angular/src/generators/remote/lib/add-ssr.ts +++ b/packages/angular/src/generators/remote/lib/add-ssr.ts @@ -41,12 +41,23 @@ export async function addSsr( "import('./src/main.server');" ); + const browserBundleOutput = joinPathFragments( + project.targets.build.options.outputPath, + 'browser' + ); + const serverBundleOutput = joinPathFragments( + project.targets.build.options.outputPath, + 'server' + ); + generateFiles( tree, joinPathFragments(__dirname, '../files/base'), project.root, { appName, + browserBundleOutput, + serverBundleOutput, standalone, tmpl: '', }