From 67670b612e2397e26a974cd337cdce1a9c6a0f21 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 4 Apr 2023 09:59:05 -0400 Subject: [PATCH] fix(@angular-devkit/build-angular): pass listening port in result for esbuild dev server The deprecated protractor builder requires that the result object from a development server provide the port used to access the application if the port is not the default (4200). The newly introduced esbuild development server will now provide the port when available. --- .../build_angular/src/builders/dev-server/vite-server.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts b/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts index 9114ffb7eef0..53d6dc8a4d4e 100644 --- a/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts +++ b/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts @@ -10,6 +10,7 @@ import type { BuilderContext } from '@angular-devkit/architect'; import type { json } from '@angular-devkit/core'; import assert from 'node:assert'; import { BinaryLike, createHash } from 'node:crypto'; +import type { AddressInfo } from 'node:net'; import path from 'node:path'; import { InlineConfig, ViteDevServer, createServer, normalizePath } from 'vite'; import { buildEsbuildBrowser } from '../browser-esbuild'; @@ -51,6 +52,7 @@ export async function* serveWithVite( )) as json.JsonObject & BrowserBuilderOptions; let server: ViteDevServer | undefined; + let listeningAddress: AddressInfo | undefined; const outputFiles = new Map(); const assets = new Map(); // TODO: Switch this to an architect schedule call when infrastructure settings are supported @@ -136,13 +138,14 @@ export async function* serveWithVite( server = await setupServer(serverOptions, outputFiles, assets); await server.listen(); + listeningAddress = server.httpServer?.address() as AddressInfo; // log connection information server.printUrls(); } // TODO: adjust output typings to reflect both development servers - yield { success: true } as unknown as DevServerBuilderOutput; + yield { success: true, port: listeningAddress?.port } as unknown as DevServerBuilderOutput; } await server?.close();