Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): pass listening port in result for…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
clydin authored and angular-robot[bot] committed Apr 5, 2023
1 parent ce46eca commit 67670b6
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,6 +52,7 @@ export async function* serveWithVite(
)) as json.JsonObject & BrowserBuilderOptions;

let server: ViteDevServer | undefined;
let listeningAddress: AddressInfo | undefined;
const outputFiles = new Map<string, OutputFileRecord>();
const assets = new Map<string, string>();
// TODO: Switch this to an architect schedule call when infrastructure settings are supported
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 67670b6

Please sign in to comment.