Skip to content

Commit 55cdfdc

Browse files
alan-agius4alexeagle
authored andcommitted
fix(@ngtools/webpack): always strip BOM when reading files
This is to align with the tsc readFile logic https://github.com/microsoft/TypeScript/blob/9da05243ff7ba9a2776d5a52118d680348b1454d/src/compiler/sys.ts#L1067
1 parent 91ec0e1 commit 55cdfdc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/ngtools/webpack/src/compiler_host.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,15 @@ export class WebpackCompilerHost implements ts.CompilerHost {
147147
const filePath = this.resolve(fileName);
148148

149149
try {
150+
let content: ArrayBuffer;
150151
if (this._memoryHost.isFile(filePath)) {
151-
return virtualFs.fileBufferToString(this._memoryHost.read(filePath));
152+
content = this._memoryHost.read(filePath);
152153
} else {
153-
const content = this._syncHost.read(filePath);
154-
155-
return virtualFs.fileBufferToString(content);
154+
content = this._syncHost.read(filePath);
156155
}
156+
157+
// strip BOM
158+
return virtualFs.fileBufferToString(content).replace(/^\uFEFF/, '');
157159
} catch {
158160
return undefined;
159161
}

0 commit comments

Comments
 (0)