File tree 2 files changed +24
-6
lines changed
packages/cli/src/commands
2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -43,13 +43,23 @@ const getAppName = async (root: string) => {
43
43
throw new CLIError ( `Unable to find package.json inside ${ root } ` ) ;
44
44
}
45
45
46
- let { name} = JSON . parse ( readFileSync ( pkgJsonPath , 'utf8' ) ) ;
46
+ let name ;
47
+
48
+ try {
49
+ name = JSON . parse ( readFileSync ( pkgJsonPath , 'utf8' ) ) ;
50
+ } catch ( e ) {
51
+ throw new CLIError ( `Failed to read ${ pkgJsonPath } file.` , e as Error ) ;
52
+ }
47
53
48
54
if ( ! name ) {
49
55
const appJson = join ( root , 'app.json' ) ;
50
56
if ( appJson ) {
51
57
logger . log ( `Reading ${ chalk . cyan ( 'name' ) } from app.json…` ) ;
52
- name = JSON . parse ( readFileSync ( appJson , 'utf8' ) ) . name ;
58
+ try {
59
+ name = JSON . parse ( readFileSync ( appJson , 'utf8' ) ) . name ;
60
+ } catch ( e ) {
61
+ throw new CLIError ( `Failed to read ${ pkgJsonPath } file.` , e as Error ) ;
62
+ }
53
63
}
54
64
55
65
if ( ! name ) {
Original file line number Diff line number Diff line change @@ -278,9 +278,17 @@ export function getTemplateName(cwd: string) {
278
278
// We use package manager to infer the name of the template module for us.
279
279
// That's why we get it from temporary package.json, where the name is the
280
280
// first and only dependency (hence 0).
281
- const name = Object . keys (
282
- JSON . parse ( fs . readFileSync ( path . join ( cwd , './package.json' ) , 'utf8' ) )
283
- . dependencies ,
284
- ) [ 0 ] ;
281
+ let name ;
282
+ try {
283
+ name = Object . keys (
284
+ JSON . parse ( fs . readFileSync ( path . join ( cwd , './package.json' ) , 'utf8' ) )
285
+ . dependencies ,
286
+ ) [ 0 ] ;
287
+ } catch {
288
+ throw new CLIError (
289
+ 'Failed to read template name from package.json. Please make sure that the template you are using has a valid package.json file.' ,
290
+ ) ;
291
+ }
292
+
285
293
return name ;
286
294
}
You can’t perform that action at this time.
0 commit comments