Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): handle promise rejection in Index…
Browse files Browse the repository at this point in the history
…HtmlWebpackPlugin

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

(cherry picked from commit e02d737)
  • Loading branch information
alan-agius4 committed Jan 28, 2021
1 parent bffd0e2 commit df9ae9e
Showing 1 changed file with 36 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,41 +59,45 @@ export class IndexHtmlWebpackPlugin extends IndexHtmlGenerator {
const noModuleFiles: FileInfo[] = [];
const moduleFiles: FileInfo[] = [];

for (const [entryName, entrypoint] of this.compilation.entrypoints) {
const entryFiles: FileInfo[] = entrypoint?.getFiles()?.map(
(f: string): FileInfo => ({
name: entryName,
file: f,
extension: extname(f),
}),
);

if (!entryFiles) {
continue;
try {
for (const [entryName, entrypoint] of this.compilation.entrypoints) {
const entryFiles: FileInfo[] = entrypoint?.getFiles()?.map(
(f: string): FileInfo => ({
name: entryName,
file: f,
extension: extname(f),
}),
);

if (!entryFiles) {
continue;
}

if (this.options.noModuleEntrypoints.includes(entryName)) {
noModuleFiles.push(...entryFiles);
} else if (this.options.moduleEntrypoints.includes(entryName)) {
moduleFiles.push(...entryFiles);
} else {
files.push(...entryFiles);
}
}

if (this.options.noModuleEntrypoints.includes(entryName)) {
noModuleFiles.push(...entryFiles);
} else if (this.options.moduleEntrypoints.includes(entryName)) {
moduleFiles.push(...entryFiles);
} else {
files.push(...entryFiles);
}
const { content, warnings, errors } = await this.process({
files,
noModuleFiles,
moduleFiles,
outputPath: dirname(this.options.outputPath),
baseHref: this.options.baseHref,
lang: this.options.lang,
});

assets[this.options.outputPath] = new RawSource(content);

warnings.forEach(msg => addWarning(this.compilation, msg));
errors.forEach(msg => addError(this.compilation, msg));
} catch (error) {
addError(this.compilation, error.message);
}

const { content, warnings, errors } = await this.process({
files,
noModuleFiles,
moduleFiles,
outputPath: dirname(this.options.outputPath),
baseHref: this.options.baseHref,
lang: this.options.lang,
});

assets[this.options.outputPath] = new RawSource(content);

warnings.forEach(msg => addWarning(this.compilation, msg));
errors.forEach(msg => addError(this.compilation, msg));
};
}

Expand Down

0 comments on commit df9ae9e

Please sign in to comment.