@@ -81,7 +81,11 @@ function updateGitignore() {
81
81
if ( ! host . exists ( gitignore ) ) {
82
82
return host ;
83
83
}
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 ( ) ;
85
89
if ( gitIgnoreContent . includes ( '\n/bazel-out\n' ) ) {
86
90
return host ;
87
91
}
@@ -102,8 +106,11 @@ function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
102
106
if ( ! workspacePath ) {
103
107
throw new Error ( 'Could not find angular.json' ) ;
104
108
}
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 ;
107
114
const projects = findPropertyInAstObject ( workspaceJsonAst , 'projects' ) ;
108
115
if ( ! projects ) {
109
116
throw new SchematicsException ( 'Expect projects in angular.json to be an Object' ) ;
@@ -220,7 +227,11 @@ function updateTsconfigJson(): Rule {
220
227
if ( ! host . exists ( tsconfigPath ) ) {
221
228
return host ;
222
229
}
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 ( ) ;
224
235
const ast = parseJsonAst ( content ) ;
225
236
if ( ! isJsonAstObject ( ast ) ) {
226
237
return host ;
@@ -255,8 +266,11 @@ function upgradeRxjs() {
255
266
if ( ! host . exists ( packageJson ) ) {
256
267
throw new Error ( `Could not find ${ packageJson } ` ) ;
257
268
}
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 ( ) ) ;
260
274
if ( ! isJsonAstObject ( jsonAst ) ) {
261
275
throw new Error ( `Failed to parse JSON for ${ packageJson } ` ) ;
262
276
}
@@ -300,8 +314,14 @@ function addPostinstallToGenerateNgSummaries() {
300
314
if ( ! host . exists ( packageJson ) ) {
301
315
throw new Error ( `Could not find ${ packageJson } ` ) ;
302
316
}
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
+ }
305
325
const scripts = findPropertyInAstObject ( jsonAst , 'scripts' ) as JsonAstObject ;
306
326
const recorder = host . beginUpdate ( packageJson ) ;
307
327
if ( scripts ) {
0 commit comments