Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): provide better error messages for…
Browse files Browse the repository at this point in the history
… failed file reads

This commit adds a more actionable error message when `readFile` fails during index generation.
  • Loading branch information
alan-agius4 committed Dec 20, 2023
1 parent 6999c2e commit ceffafe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Expand Up @@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import * as fs from 'fs';
import { join } from 'path';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { NormalizedCachedOptions } from '../normalize-cache';
import { NormalizedOptimizationOptions } from '../normalize-optimization';
import { stripBom } from '../strip-bom';
Expand Down Expand Up @@ -104,11 +104,19 @@ export class IndexHtmlGenerator {
}

async readAsset(path: string): Promise<string> {
return fs.promises.readFile(path, 'utf-8');
try {
return await readFile(path, 'utf-8');
} catch {
throw new Error(`Failed to read asset "${path}".`);
}
}

protected async readIndex(path: string): Promise<string> {
return fs.promises.readFile(path, 'utf-8');
try {
return await readFile(path, 'utf-8');
} catch {
throw new Error(`Failed to read index HTML file "${path}".`);
}
}
}

Expand Down
Expand Up @@ -57,6 +57,10 @@ export default function (): Rule {
continue;
}

if (options['index'] === '') {
options['index'] = false;
}

// Rename and transform options
options['browser'] = options['main'];
if (hasServerTarget && typeof options['browser'] === 'string') {
Expand Down

0 comments on commit ceffafe

Please sign in to comment.