fix(angular): handle indexHtmlTransformer option in dev-server correctly (#21520)

This commit is contained in:
Leosvel Pérez Espinosa 2024-02-02 12:00:03 +01:00 committed by GitHub
parent d6d7b1c689
commit 3b5f4a21ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 9 deletions

View File

@ -554,9 +554,10 @@
"x-priority": "important", "x-priority": "important",
"additionalProperties": false "additionalProperties": false
}, },
"indexFileTransformer": { "indexHtmlTransformer": {
"description": "Path to transformer function to transform the index.html", "description": "Path to transformer function to transform the index.html",
"type": "string" "type": "string",
"alias": "indexFileTransformer"
}, },
"buildLibsFromSource": { "buildLibsFromSource": {
"type": "boolean", "type": "boolean",

View File

@ -44,6 +44,7 @@ type BuildTargetOptions = {
tsConfig: string; tsConfig: string;
buildLibsFromSource?: boolean; buildLibsFromSource?: boolean;
customWebpackConfig?: { path?: string }; customWebpackConfig?: { path?: string };
indexHtmlTransformer?: string;
indexFileTransformer?: string; indexFileTransformer?: string;
plugins?: string[] | PluginSpec[]; plugins?: string[] | PluginSpec[];
esbuildMiddleware?: string[]; esbuildMiddleware?: string[];
@ -111,11 +112,14 @@ export function executeDevServerBuilder(
} }
} }
const normalizedIndexHtmlTransformer =
buildTargetOptions.indexHtmlTransformer ??
buildTargetOptions.indexFileTransformer;
let pathToIndexFileTransformer: string; let pathToIndexFileTransformer: string;
if (buildTargetOptions.indexFileTransformer) { if (normalizedIndexHtmlTransformer) {
pathToIndexFileTransformer = joinPathFragments( pathToIndexFileTransformer = joinPathFragments(
context.workspaceRoot, context.workspaceRoot,
buildTargetOptions.indexFileTransformer normalizedIndexHtmlTransformer
); );
if (pathToIndexFileTransformer && !existsSync(pathToIndexFileTransformer)) { if (pathToIndexFileTransformer && !existsSync(pathToIndexFileTransformer)) {
@ -313,6 +317,7 @@ function cleanBuildTargetOptions(
| BrowserEsbuildBuilderOptions { | BrowserEsbuildBuilderOptions {
delete options.buildLibsFromSource; delete options.buildLibsFromSource;
delete options.customWebpackConfig; delete options.customWebpackConfig;
delete options.indexHtmlTransformer;
delete options.indexFileTransformer; delete options.indexFileTransformer;
delete options.plugins; delete options.plugins;

View File

@ -4,6 +4,10 @@ export type BrowserBuilderSchema = Schema & {
customWebpackConfig?: { customWebpackConfig?: {
path: string; path: string;
}; };
indexFileTransformer?: string; indexHtmlTransformer?: string;
buildLibsFromSource?: boolean; buildLibsFromSource?: boolean;
/**
* @deprecated Use `indexHtmlTransformer` instead. It will be removed in Nx 19.
*/
indexFileTransformer?: string;
}; };

View File

@ -458,9 +458,10 @@
"x-priority": "important", "x-priority": "important",
"additionalProperties": false "additionalProperties": false
}, },
"indexFileTransformer": { "indexHtmlTransformer": {
"description": "Path to transformer function to transform the index.html", "description": "Path to transformer function to transform the index.html",
"type": "string" "type": "string",
"alias": "indexFileTransformer"
}, },
"buildLibsFromSource": { "buildLibsFromSource": {
"type": "boolean", "type": "boolean",

View File

@ -55,6 +55,7 @@ export function executeWebpackBrowserBuilder(
const { const {
buildLibsFromSource, buildLibsFromSource,
customWebpackConfig, customWebpackConfig,
indexHtmlTransformer,
indexFileTransformer, indexFileTransformer,
...delegateBuilderOptions ...delegateBuilderOptions
} = options; } = options;
@ -71,9 +72,11 @@ export function executeWebpackBrowserBuilder(
); );
} }
const normalizedIndexHtmlTransformer =
indexHtmlTransformer ?? indexFileTransformer;
const pathToIndexFileTransformer = const pathToIndexFileTransformer =
indexFileTransformer && normalizedIndexHtmlTransformer &&
joinPathFragments(context.workspaceRoot, indexFileTransformer); joinPathFragments(context.workspaceRoot, normalizedIndexHtmlTransformer);
if (pathToIndexFileTransformer && !existsSync(pathToIndexFileTransformer)) { if (pathToIndexFileTransformer && !existsSync(pathToIndexFileTransformer)) {
throw new Error( throw new Error(
`File containing Index File Transformer function Not Found!\n Please ensure the path to the file containing the function is correct: \n${pathToIndexFileTransformer}` `File containing Index File Transformer function Not Found!\n Please ensure the path to the file containing the function is correct: \n${pathToIndexFileTransformer}`