File tree Expand file tree Collapse file tree 2 files changed +27
-11
lines changed Expand file tree Collapse file tree 2 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -48,11 +48,21 @@ ${chalk.yellow(' -t, --title')} Sets title.
48
48
49
49
let pkg = findPackageFileInPath ( args . flags [ '--package' ] || args . flags [ '-p' ] ) ;
50
50
51
- if ( fs . existsSync ( pkg ) ) {
51
+ try {
52
52
53
- pkg = require ( pkg ) ;
53
+ const pkgStats = fs . statSync ( pkg ) ;
54
54
55
- } else {
55
+ if ( pkgStats . isFile ( ) ) {
56
+
57
+ pkg = require ( pkg ) ;
58
+
59
+ } else {
60
+
61
+ pkg = { } ;
62
+
63
+ }
64
+
65
+ } catch ( err ) {
56
66
57
67
pkg = { } ;
58
68
Original file line number Diff line number Diff line change @@ -17,31 +17,37 @@ const path = require('path');
17
17
18
18
const findPackageFileInPath = input => {
19
19
20
- let pkgPath = null ;
21
-
22
20
if ( ! input ) {
23
21
24
22
input = process . cwd ( ) ;
25
23
26
24
}
27
25
28
- if ( fs . existsSync ( input ) ) {
26
+ try {
29
27
30
28
const stat = fs . statSync ( input ) ;
31
29
32
- if ( stat . isFile ( ) ) {
30
+ if ( stat ) {
31
+
32
+ if ( stat . isFile ( ) ) {
33
+
34
+ return path . resolve ( path . join ( path . dirname ( input ) , '/package.json' ) ) ;
33
35
34
- pkgPath = path . resolve ( path . join ( path . dirname ( input ) , '/package.json' ) ) ;
36
+ } else if ( stat . isDirectory ( ) ) {
35
37
36
- } else {
38
+ return path . resolve ( path . join ( input , '/package.json' ) ) ;
37
39
38
- pkgPath = path . resolve ( path . join ( input , '/package.json' ) ) ;
40
+ }
39
41
40
42
}
41
43
44
+ } catch ( err ) {
45
+
46
+ process . stderr . write ( `${ err . toString ( ) } \n` ) ;
47
+
42
48
}
43
49
44
- return pkgPath ;
50
+ return null ;
45
51
46
52
} ;
47
53
You can’t perform that action at this time.
0 commit comments