From 6c3d7d1c10907d8d57b5f84f298b324d6f972226 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 19 Oct 2023 07:19:05 +0000 Subject: [PATCH] fix(@angular-devkit/build-angular): update `ssr` option definition This commits updates the `ssr` application builder option definition. The main change is that now the option does not accept the entry-point as a value. Instead it should be passed in the `entry` suboption. Example ```json "ssr": { "entry": "server.ts" } ``` This change in this option is important to allow us in the future to add additional sub options. Like potentially a `platform` or `target`. (cherry picked from commit 17fd0ade13deda0e9a8e6d24d4f5263bd56f4016) --- .../public-api/angular_devkit/build_angular/index.md | 2 +- .../build_angular/src/builders/application/options.ts | 6 ++++-- .../build_angular/src/builders/application/schema.json | 10 ++++++++-- .../src/builders/application/tests/options/ssr_spec.ts | 4 ++-- packages/schematics/angular/ssr/index.ts | 4 +++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/goldens/public-api/angular_devkit/build_angular/index.md b/goldens/public-api/angular_devkit/build_angular/index.md index 1b25ec2e56c7..fbd5c2266cc2 100644 --- a/goldens/public-api/angular_devkit/build_angular/index.md +++ b/goldens/public-api/angular_devkit/build_angular/index.md @@ -47,7 +47,7 @@ export interface ApplicationBuilderOptions { server?: string; serviceWorker?: ServiceWorker_2; sourceMap?: SourceMapUnion_2; - ssr?: ServiceWorker_2; + ssr?: SsrUnion; statsJson?: boolean; stylePreprocessorOptions?: StylePreprocessorOptions_2; styles?: StyleElement_2[]; diff --git a/packages/angular_devkit/build_angular/src/builders/application/options.ts b/packages/angular_devkit/build_angular/src/builders/application/options.ts index 0f3b2d63aab5..88ee9d8e9db2 100644 --- a/packages/angular_devkit/build_angular/src/builders/application/options.ts +++ b/packages/angular_devkit/build_angular/src/builders/application/options.ts @@ -210,9 +210,11 @@ export async function normalizeOptions( let ssrOptions; if (options.ssr === true) { ssrOptions = {}; - } else if (typeof options.ssr === 'string') { + } else if (typeof options.ssr === 'object') { + const { entry } = options.ssr; + ssrOptions = { - entry: path.join(workspaceRoot, options.ssr), + entry: entry && path.join(workspaceRoot, entry), }; } diff --git a/packages/angular_devkit/build_angular/src/builders/application/schema.json b/packages/angular_devkit/build_angular/src/builders/application/schema.json index 47d0254e4a0d..cd471774c7d4 100644 --- a/packages/angular_devkit/build_angular/src/builders/application/schema.json +++ b/packages/angular_devkit/build_angular/src/builders/application/schema.json @@ -447,8 +447,14 @@ "description": "Enable the server bundles to be written to disk." }, { - "type": "string", - "description": "The server entry-point that when executed will spawn the web server." + "type": "object", + "properties": { + "entry": { + "type": "string", + "description": "The server entry-point that when executed will spawn the web server." + } + }, + "additionalProperties": false } ] }, diff --git a/packages/angular_devkit/build_angular/src/builders/application/tests/options/ssr_spec.ts b/packages/angular_devkit/build_angular/src/builders/application/tests/options/ssr_spec.ts index e1f7b74c2ddf..2caef3e3e14f 100644 --- a/packages/angular_devkit/build_angular/src/builders/application/tests/options/ssr_spec.ts +++ b/packages/angular_devkit/build_angular/src/builders/application/tests/options/ssr_spec.ts @@ -27,7 +27,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { harness.useTarget('build', { ...BASE_OPTIONS, server: 'src/main.server.ts', - ssr: 'src/server.ts', + ssr: { entry: 'src/server.ts' }, }); const { result } = await harness.executeOnce(); @@ -43,7 +43,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { harness.useTarget('build', { ...BASE_OPTIONS, server: 'src/main.server.ts', - ssr: '/file.mjs', + ssr: { entry: '/file.mjs' }, }); const { result } = await harness.executeOnce(); diff --git a/packages/schematics/angular/ssr/index.ts b/packages/schematics/angular/ssr/index.ts index 433de59993c5..52fbcb9f4093 100644 --- a/packages/schematics/angular/ssr/index.ts +++ b/packages/schematics/angular/ssr/index.ts @@ -116,7 +116,9 @@ function updateApplicationBuilderWorkspaceConfigRule( buildTarget.options = { ...buildTarget.options, prerender: true, - ssr: join(normalize(projectRoot), 'server.ts'), + ssr: { + entry: join(normalize(projectRoot), 'server.ts'), + }, }; }); }