From c6ea2562683cc6e640136a02760db9363ded4352 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 9 Oct 2023 08:15:30 +0000 Subject: [PATCH] fix(@angular-devkit/build-angular): fully downlevel async/await when using vite dev-server with caching enabled Prior to this change, async/await in external packages were not being correctly downlevelled when using vite dev-server with cache enabled.t checkout Closes #25985 (cherry picked from commit 968ee3428046eaad8eb56518c73195f43b6d4ead) --- .../src/builders/dev-server/vite-server.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 4ecea65a1bbb..72401223bb1b 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 @@ -18,7 +18,9 @@ import type { AddressInfo } from 'node:net'; import path, { posix } from 'node:path'; import { Connect, InlineConfig, ViteDevServer, createServer, normalizePath } from 'vite'; import { JavaScriptTransformer } from '../../tools/esbuild/javascript-transformer'; +import { getFeatureSupport, transformSupportedBrowsersToTargets } from '../../tools/esbuild/utils'; import { RenderOptions, renderPage } from '../../utils/server-rendering/render-page'; +import { getSupportedBrowsers } from '../../utils/supported-browsers'; import { buildEsbuildBrowser } from '../browser-esbuild'; import { Schema as BrowserBuilderOptions } from '../browser-esbuild/schema'; import { loadProxyConfiguration } from './load-proxy-config'; @@ -88,6 +90,16 @@ export async function* serveWithVite( if (server) { handleUpdate(generatedFiles, server, serverOptions, context.logger); } else { + const projectName = context.target?.project; + if (!projectName) { + throw new Error('The builder requires a target.'); + } + + const { root = '' } = await context.getProjectMetadata(projectName); + const projectRoot = path.join(context.workspaceRoot, root as string); + const browsers = getSupportedBrowsers(projectRoot, context.logger); + const target = transformSupportedBrowsersToTargets(browsers); + // Setup server and start listening const serverConfiguration = await setupServer( serverOptions, @@ -96,6 +108,7 @@ export async function* serveWithVite( browserOptions.preserveSymlinks, browserOptions.externalDependencies, !!browserOptions.ssr, + target, ); server = await createServer(serverConfiguration); @@ -237,6 +250,7 @@ export async function setupServer( preserveSymlinks: boolean | undefined, prebundleExclude: string[] | undefined, ssr: boolean, + target: string[], ): Promise { const proxy = await loadProxyConfiguration( serverOptions.workspaceRoot, @@ -494,6 +508,9 @@ export async function setupServer( entries: [], // Add an esbuild plugin to run the Angular linker on dependencies esbuildOptions: { + // Set esbuild supported targets. + target, + supported: getFeatureSupport(target), plugins: [ { name: 'angular-vite-optimize-deps',