Skip to content

Commit ffeb3eb

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular-devkit/build-angular): use TextDecoder for index reading during index HTML generation
The globally available TextDecoder class will automatically handle the presence of a BOM in text files when decoding. This allows the removal of the utility function present in the package to do the same.
1 parent 9ca3a54 commit ffeb3eb

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

packages/angular_devkit/build_angular/src/utils/index-file/index-html-generator.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { readFile } from 'node:fs/promises';
1010
import { join } from 'node:path';
1111
import { NormalizedCachedOptions } from '../normalize-cache';
1212
import { NormalizedOptimizationOptions } from '../normalize-optimization';
13-
import { stripBom } from '../strip-bom';
1413
import { CrossOriginValue, Entrypoint, FileInfo, augmentIndexHtml } from './augment-index-html';
1514
import { InlineCriticalCssProcessor } from './inline-critical-css';
1615
import { InlineFontsProcessor } from './inline-fonts';
@@ -75,7 +74,7 @@ export class IndexHtmlGenerator {
7574
}
7675

7776
async process(options: IndexHtmlGeneratorProcessOptions): Promise<IndexHtmlTransformResult> {
78-
let content = stripBom(await this.readIndex(this.options.indexPath));
77+
let content = await this.readIndex(this.options.indexPath);
7978
const warnings: string[] = [];
8079
const errors: string[] = [];
8180

@@ -113,9 +112,9 @@ export class IndexHtmlGenerator {
113112

114113
protected async readIndex(path: string): Promise<string> {
115114
try {
116-
return await readFile(path, 'utf-8');
117-
} catch {
118-
throw new Error(`Failed to read index HTML file "${path}".`);
115+
return new TextDecoder('utf-8').decode(await readFile(path));
116+
} catch (cause) {
117+
throw new Error(`Failed to read index HTML file "${path}".`, { cause });
119118
}
120119
}
121120
}

packages/angular_devkit/build_angular/src/utils/strip-bom.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)