Skip to content

Commit 9a7f560

Browse files
gregmagolankara
authored andcommittedMar 13, 2019
fix(bazel): fix strict null checks compile error in packages/bazel/src/schematics/ng-add/index.ts (#29282)
PR Close #29282
1 parent 955e4e7 commit 9a7f560

File tree

1 file changed

+28
-8
lines changed
  • packages/bazel/src/schematics/ng-add

1 file changed

+28
-8
lines changed
 

‎packages/bazel/src/schematics/ng-add/index.ts

+28-8
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ function updateGitignore() {
8181
if (!host.exists(gitignore)) {
8282
return host;
8383
}
84-
const gitIgnoreContent = host.read(gitignore).toString();
84+
const gitIgnoreContentRaw = host.read(gitignore);
85+
if (!gitIgnoreContentRaw) {
86+
return host;
87+
}
88+
const gitIgnoreContent = gitIgnoreContentRaw.toString();
8589
if (gitIgnoreContent.includes('\n/bazel-out\n')) {
8690
return host;
8791
}
@@ -102,8 +106,11 @@ function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
102106
if (!workspacePath) {
103107
throw new Error('Could not find angular.json');
104108
}
105-
const workspaceContent = host.read(workspacePath).toString();
106-
const workspaceJsonAst = parseJsonAst(workspaceContent) as JsonAstObject;
109+
const workspaceContent = host.read(workspacePath);
110+
if (!workspaceContent) {
111+
throw new Error('Failed to read angular.json content');
112+
}
113+
const workspaceJsonAst = parseJsonAst(workspaceContent.toString()) as JsonAstObject;
107114
const projects = findPropertyInAstObject(workspaceJsonAst, 'projects');
108115
if (!projects) {
109116
throw new SchematicsException('Expect projects in angular.json to be an Object');
@@ -220,7 +227,11 @@ function updateTsconfigJson(): Rule {
220227
if (!host.exists(tsconfigPath)) {
221228
return host;
222229
}
223-
const content = host.read(tsconfigPath).toString();
230+
const contentRaw = host.read(tsconfigPath).toString();
231+
if (!contentRaw) {
232+
return host;
233+
}
234+
const content = contentRaw.toString();
224235
const ast = parseJsonAst(content);
225236
if (!isJsonAstObject(ast)) {
226237
return host;
@@ -255,8 +266,11 @@ function upgradeRxjs() {
255266
if (!host.exists(packageJson)) {
256267
throw new Error(`Could not find ${packageJson}`);
257268
}
258-
const content = host.read(packageJson).toString();
259-
const jsonAst = parseJsonAst(content);
269+
const content = host.read(packageJson);
270+
if (!content) {
271+
throw new Error('Failed to read package.json content');
272+
}
273+
const jsonAst = parseJsonAst(content.toString());
260274
if (!isJsonAstObject(jsonAst)) {
261275
throw new Error(`Failed to parse JSON for ${packageJson}`);
262276
}
@@ -300,8 +314,14 @@ function addPostinstallToGenerateNgSummaries() {
300314
if (!host.exists(packageJson)) {
301315
throw new Error(`Could not find ${packageJson}`);
302316
}
303-
const content = host.read(packageJson).toString();
304-
const jsonAst = parseJsonAst(content) as JsonAstObject;
317+
const content = host.read(packageJson);
318+
if (!content) {
319+
throw new Error('Failed to read package.json content');
320+
}
321+
const jsonAst = parseJsonAst(content.toString());
322+
if (!isJsonAstObject(jsonAst)) {
323+
throw new Error(`Failed to parse JSON for ${packageJson}`);
324+
}
305325
const scripts = findPropertyInAstObject(jsonAst, 'scripts') as JsonAstObject;
306326
const recorder = host.beginUpdate(packageJson);
307327
if (scripts) {

0 commit comments

Comments
 (0)
Please sign in to comment.