1
0
mirror of https://github.com/angular/angular-cli.git synced 2025-05-19 04:26:01 +08:00

refactor(@angular-devkit/build-webpack): assert catch clause variable type before usage

Prepares the `@angular-devkit/build-webpack` package for the eventual change of enabling the
TypeScript `useUnknownInCatchVariables` option. This option provides additional
code safety by ensuring that the catch clause variable is the proper type before
attempting to access its properties. Similar changes will be needed in the other
packages in the repository prior to enabling `useUnknownInCatchVariables`.
This commit is contained in:
Charles Lyding 2022-06-10 17:53:45 -04:00 committed by Alan Agius
parent 6a3c0b0db5
commit 3c4ca3fa7f
2 changed files with 2 additions and 2 deletions
packages/angular_devkit/build_webpack/src

@ -90,7 +90,7 @@ export async function getWebpackConfig(configPath: string): Promise<Configuratio
try {
return require(configPath);
} catch (e) {
if (e.code === 'ERR_REQUIRE_ESM') {
if ((e as NodeJS.ErrnoException).code === 'ERR_REQUIRE_ESM') {
// Load the ESM configuration file using the TypeScript dynamic import workaround.
// Once TypeScript provides support for keeping the dynamic import this workaround can be
// changed to a direct dynamic import.

@ -105,7 +105,7 @@ export function runWebpack(
} catch (err) {
if (err) {
context.logger.error(
`\nAn error occurred during the build:\n${(err && err.stack) || err}`,
`\nAn error occurred during the build:\n${err instanceof Error ? err.stack : err}`,
);
}
throw err;