fix(@angular-devkit/build-angular): browser builder should not swollow error messages

Closes #14813
This commit is contained in:
Alan 2019-06-19 14:14:21 +02:00 committed by Minko Gechev
parent 3cd0931eb7
commit c7135fae35
3 changed files with 24 additions and 5 deletions

View File

@ -270,10 +270,14 @@ export abstract class ArchitectCommand<
},
);
const result = await run.output.toPromise();
const { error, success } = await run.output.toPromise();
await run.stop();
return result.success ? 0 : 1;
if (error) {
this.logger.error(error);
}
return success ? 0 : 1;
}
}

View File

@ -102,7 +102,7 @@ export async function augmentAppWithServiceWorker(
if (!configExists) {
throw new Error(tags.oneLine`
Error: Expected to find an ngsw-config.json configuration
file in the ${appRoot} folder. Either provide one or disable Service Worker
file in the ${getSystemPath(appRoot)} folder. Either provide one or disable Service Worker
in your angular.json configuration file.
`);
}

View File

@ -261,7 +261,7 @@ export function buildWebpackBrowser(
})
.pipe(
map(() => ({ success: true })),
catchError(() => of({ success: false })),
catchError(error => of({ success: false, error: mapErrorToMessage(error) })),
);
} else {
return of({ success });
@ -276,7 +276,10 @@ export function buildWebpackBrowser(
resolve(root, normalize(options.outputPath)),
options.baseHref || '/',
options.ngswConfigPath,
).then(() => ({ success: true }), () => ({ success: false })));
).then(
() => ({ success: true }),
error => ({ success: false, error: mapErrorToMessage(error) }),
));
} else {
return of(buildEvent);
}
@ -291,4 +294,16 @@ export function buildWebpackBrowser(
);
}
function mapErrorToMessage(error: unknown): string | undefined {
if (error instanceof Error) {
return error.message;
}
if (typeof error === 'string') {
return error;
}
return undefined;
}
export default createBuilder<json.JsonObject & BrowserBuilderSchema>(buildWebpackBrowser);