Skip to content

Commit 01dce70

Browse files
committed
jsonc-parser doesn't throw
1 parent 18ce3ba commit 01dce70

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/schematics/ng-add.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ function getWorkspace(
1616
if (configBuffer === null) {
1717
throw new SchematicsException(`Could not find angular.json`);
1818
}
19-
const content = configBuffer.toString();
2019

21-
const { parse } = (require('jsonc-parser') as typeof import('jsonc-parser'));
20+
// We can not depend on this library to have be included in older (or newer) Angular versions.
21+
// Require here, since the schematic will add it to the package.json and install it before
22+
// continuing.
23+
const { parse }: typeof import('jsonc-parser') = require('jsonc-parser');
2224

23-
let workspace: Workspace;
24-
try {
25-
workspace = parse(
26-
content,
27-
) as Workspace;
28-
} catch (e) {
29-
throw new SchematicsException(`Could not parse angular.json: ` + e.message);
25+
const workspace = parse(configBuffer.toString()) as Workspace|undefined;
26+
if (!workspace) {
27+
throw new SchematicsException('Could not parse angular.json');
3028
}
3129

3230
return {

0 commit comments

Comments
 (0)