@@ -11,6 +11,7 @@ import {
11
11
JsonObject ,
12
12
JsonParseMode ,
13
13
experimental ,
14
+ isJsonObject ,
14
15
normalize ,
15
16
parseJson ,
16
17
parseJsonAst ,
@@ -197,7 +198,7 @@ export function migrateLegacyGlobalConfig(): boolean {
197
198
if ( existsSync ( legacyGlobalConfigPath ) ) {
198
199
const content = readFileSync ( legacyGlobalConfigPath , 'utf-8' ) ;
199
200
const legacy = parseJson ( content , JsonParseMode . Loose ) ;
200
- if ( ! legacy || typeof legacy != 'object' || Array . isArray ( legacy ) ) {
201
+ if ( ! isJsonObject ( legacy ) ) {
201
202
return false ;
202
203
}
203
204
@@ -208,16 +209,13 @@ export function migrateLegacyGlobalConfig(): boolean {
208
209
cli [ 'packageManager' ] = legacy . packageManager ;
209
210
}
210
211
211
- if ( legacy . defaults && typeof legacy . defaults == 'object' && ! Array . isArray ( legacy . defaults )
212
- && legacy . defaults . schematics && typeof legacy . defaults . schematics == 'object'
213
- && ! Array . isArray ( legacy . defaults . schematics )
214
- && typeof legacy . defaults . schematics . collection == 'string' ) {
212
+ if ( isJsonObject ( legacy . defaults )
213
+ && isJsonObject ( legacy . defaults . schematics )
214
+ && typeof legacy . defaults . schematics . collection == 'string' ) {
215
215
cli [ 'defaultCollection' ] = legacy . defaults . schematics . collection ;
216
216
}
217
217
218
- if ( legacy . warnings && typeof legacy . warnings == 'object'
219
- && ! Array . isArray ( legacy . warnings ) ) {
220
-
218
+ if ( isJsonObject ( legacy . warnings ) ) {
221
219
const warnings : JsonObject = { } ;
222
220
if ( typeof legacy . warnings . versionMismatch == 'boolean' ) {
223
221
warnings [ 'versionMismatch' ] = legacy . warnings . versionMismatch ;
@@ -249,7 +247,7 @@ function getLegacyPackageManager(): string | null {
249
247
const content = readFileSync ( legacyGlobalConfigPath , 'utf-8' ) ;
250
248
251
249
const legacy = parseJson ( content , JsonParseMode . Loose ) ;
252
- if ( ! legacy || typeof legacy != 'object' || Array . isArray ( legacy ) ) {
250
+ if ( ! isJsonObject ( legacy ) ) {
253
251
return null ;
254
252
}
255
253
@@ -278,7 +276,7 @@ export async function getSchematicDefaults(
278
276
result = { ...result , ...( schematicObject as { } ) } ;
279
277
}
280
278
const collectionObject = workspace . getSchematics ( ) [ collection ] ;
281
- if ( typeof collectionObject == 'object' && ! Array . isArray ( collectionObject ) ) {
279
+ if ( isJsonObject ( collectionObject ) ) {
282
280
result = { ...result , ...( collectionObject [ schematic ] as { } ) } ;
283
281
}
284
282
@@ -293,7 +291,7 @@ export async function getSchematicDefaults(
293
291
result = { ...result , ...( schematicObject as { } ) } ;
294
292
}
295
293
const collectionObject = workspace . getSchematics ( ) [ collection ] ;
296
- if ( typeof collectionObject == 'object' && ! Array . isArray ( collectionObject ) ) {
294
+ if ( isJsonObject ( collectionObject ) ) {
297
295
result = { ...result , ...( collectionObject [ schematic ] as { } ) } ;
298
296
}
299
297
}
@@ -305,7 +303,7 @@ export async function getSchematicDefaults(
305
303
result = { ...result , ...( schematicObject as { } ) } ;
306
304
}
307
305
const collectionObject = workspace . getProjectSchematics ( project ) [ collection ] ;
308
- if ( typeof collectionObject == 'object' && ! Array . isArray ( collectionObject ) ) {
306
+ if ( isJsonObject ( collectionObject ) ) {
309
307
result = { ...result , ...( collectionObject [ schematic ] as { } ) } ;
310
308
}
311
309
}
@@ -321,7 +319,7 @@ export async function isWarningEnabled(warning: string): Promise<boolean> {
321
319
const project = getProjectByCwd ( workspace ) ;
322
320
if ( project && workspace . getProjectCli ( project ) ) {
323
321
const warnings = workspace . getProjectCli ( project ) [ 'warnings' ] ;
324
- if ( typeof warnings == 'object' && ! Array . isArray ( warnings ) ) {
322
+ if ( isJsonObject ( warnings ) ) {
325
323
const value = warnings [ warning ] ;
326
324
if ( typeof value == 'boolean' ) {
327
325
return value ;
@@ -330,7 +328,7 @@ export async function isWarningEnabled(warning: string): Promise<boolean> {
330
328
}
331
329
if ( workspace . getCli ( ) ) {
332
330
const warnings = workspace . getCli ( ) [ 'warnings' ] ;
333
- if ( typeof warnings == 'object' && ! Array . isArray ( warnings ) ) {
331
+ if ( isJsonObject ( warnings ) ) {
334
332
const value = warnings [ warning ] ;
335
333
if ( typeof value == 'boolean' ) {
336
334
return value ;
@@ -342,7 +340,7 @@ export async function isWarningEnabled(warning: string): Promise<boolean> {
342
340
workspace = await getWorkspace ( 'global' ) ;
343
341
if ( workspace && workspace . getCli ( ) ) {
344
342
const warnings = workspace . getCli ( ) [ 'warnings' ] ;
345
- if ( typeof warnings == 'object' && ! Array . isArray ( warnings ) ) {
343
+ if ( isJsonObject ( warnings ) ) {
346
344
const value = warnings [ warning ] ;
347
345
if ( typeof value == 'boolean' ) {
348
346
return value ;
0 commit comments