fix(generate): improve error handling

Deliver better errors than `Unexpected token } in JSON at position X`
Fix issue #1047

https://github.com/nrwl/nx/issues/1047
This commit is contained in:
Juan Carlos Valerio 2020-06-10 17:39:28 -06:00 committed by Victor Savkin
parent 240c3f62df
commit c1b494c22e

View File

@ -23,7 +23,12 @@ export function updateTsconfig(schema: Schema) {
const tsConfigPath = 'tsconfig.json'; const tsConfigPath = 'tsconfig.json';
if (tree.exists(tsConfigPath)) { if (tree.exists(tsConfigPath)) {
let contents = JSON.parse(tree.read(tsConfigPath).toString('utf-8')); let contents = tree.read(tsConfigPath).toString('utf-8');
try {
contents = JSON.parse(contents);
} catch (e) {
throw new Error(`Cannot parse ${tsConfigPath}: ${e.message}`);
}
delete contents.compilerOptions.paths[ delete contents.compilerOptions.paths[
`@${nxJson.npmScope}/${project.root.substr(5)}` `@${nxJson.npmScope}/${project.root.substr(5)}`
]; ];