fix(angular): resolve the index html transformer correctly for esbuild based build targets in dev-server (#21679)

This commit is contained in:
Leosvel Pérez Espinosa 2024-02-08 10:24:34 +01:00 committed by GitHub
parent bf45f08992
commit db4c617c2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,6 +24,7 @@ import { combineLatest, from } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils';
import {
loadIndexHtmlTransformer,
loadMiddleware,
loadPlugins,
type PluginSpec,
@ -182,8 +183,22 @@ export function executeDevServerBuilder(
from(
loadMiddleware(options.esbuildMiddleware, buildTargetOptions.tsConfig)
),
from(
loadIndexHtmlFileTransformer(
pathToIndexFileTransformer,
buildTargetOptions.tsConfig,
context,
isUsingWebpackBuilder
)
),
]).pipe(
switchMap(([{ executeDevServerBuilder }, plugins, middleware]) =>
switchMap(
([
{ executeDevServerBuilder },
plugins,
middleware,
indexHtmlTransformer,
]) =>
executeDevServerBuilder(
delegateBuilderOptions,
context,
@ -223,13 +238,9 @@ export function executeDevServerBuilder(
}
: undefined,
...(pathToIndexFileTransformer
...(indexHtmlTransformer
? {
indexHtml: resolveIndexHtmlTransformer(
pathToIndexFileTransformer,
buildTargetOptions.tsConfig,
context.target
),
indexHtml: indexHtmlTransformer,
}
: {}),
},
@ -267,6 +278,25 @@ function getDelegateBuilderOptions(
return delegateBuilderOptions;
}
async function loadIndexHtmlFileTransformer(
pathToIndexFileTransformer: string | undefined,
tsConfig: string,
context: BuilderContext,
isUsingWebpackBuilder: boolean
) {
if (!pathToIndexFileTransformer) {
return undefined;
}
return isUsingWebpackBuilder
? resolveIndexHtmlTransformer(
pathToIndexFileTransformer,
tsConfig,
context.target
)
: await loadIndexHtmlTransformer(pathToIndexFileTransformer, tsConfig);
}
const executorToBuilderMap = new Map<string, string>([
[
'@nx/angular:browser-esbuild',