Skip to content

Commit e02d737

Browse files
committed
fix(@angular-devkit/build-angular): handle promise rejection in IndexHtmlWebpackPlugin
Webpack doesn't handle promise rejections properly. With this change use use a try/catch block and add the error to the compilation. Closes #19893
1 parent 60b2cb7 commit e02d737

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

packages/angular_devkit/build_angular/src/webpack/plugins/index-html-webpack-plugin.ts

+36-32
Original file line numberDiff line numberDiff line change
@@ -59,41 +59,45 @@ export class IndexHtmlWebpackPlugin extends IndexHtmlGenerator {
5959
const noModuleFiles: FileInfo[] = [];
6060
const moduleFiles: FileInfo[] = [];
6161

62-
for (const [entryName, entrypoint] of this.compilation.entrypoints) {
63-
const entryFiles: FileInfo[] = entrypoint?.getFiles()?.map(
64-
(f: string): FileInfo => ({
65-
name: entryName,
66-
file: f,
67-
extension: extname(f),
68-
}),
69-
);
70-
71-
if (!entryFiles) {
72-
continue;
62+
try {
63+
for (const [entryName, entrypoint] of this.compilation.entrypoints) {
64+
const entryFiles: FileInfo[] = entrypoint?.getFiles()?.map(
65+
(f: string): FileInfo => ({
66+
name: entryName,
67+
file: f,
68+
extension: extname(f),
69+
}),
70+
);
71+
72+
if (!entryFiles) {
73+
continue;
74+
}
75+
76+
if (this.options.noModuleEntrypoints.includes(entryName)) {
77+
noModuleFiles.push(...entryFiles);
78+
} else if (this.options.moduleEntrypoints.includes(entryName)) {
79+
moduleFiles.push(...entryFiles);
80+
} else {
81+
files.push(...entryFiles);
82+
}
7383
}
7484

75-
if (this.options.noModuleEntrypoints.includes(entryName)) {
76-
noModuleFiles.push(...entryFiles);
77-
} else if (this.options.moduleEntrypoints.includes(entryName)) {
78-
moduleFiles.push(...entryFiles);
79-
} else {
80-
files.push(...entryFiles);
81-
}
85+
const { content, warnings, errors } = await this.process({
86+
files,
87+
noModuleFiles,
88+
moduleFiles,
89+
outputPath: dirname(this.options.outputPath),
90+
baseHref: this.options.baseHref,
91+
lang: this.options.lang,
92+
});
93+
94+
assets[this.options.outputPath] = new RawSource(content);
95+
96+
warnings.forEach(msg => addWarning(this.compilation, msg));
97+
errors.forEach(msg => addError(this.compilation, msg));
98+
} catch (error) {
99+
addError(this.compilation, error.message);
82100
}
83-
84-
const { content, warnings, errors } = await this.process({
85-
files,
86-
noModuleFiles,
87-
moduleFiles,
88-
outputPath: dirname(this.options.outputPath),
89-
baseHref: this.options.baseHref,
90-
lang: this.options.lang,
91-
});
92-
93-
assets[this.options.outputPath] = new RawSource(content);
94-
95-
warnings.forEach(msg => addWarning(this.compilation, msg));
96-
errors.forEach(msg => addError(this.compilation, msg));
97101
};
98102
}
99103

0 commit comments

Comments
 (0)