@@ -42,50 +42,44 @@ async function resolveGlobbedPath (entries, cwd) {
42
42
return paths
43
43
}
44
44
45
- module . exports = function ( opts , cb ) {
46
- let pkgPath = opts . path
47
- let entries
48
-
49
- const result = promisedReadPackage ( pkgPath )
50
- . catch ( async ( err ) => {
51
- if ( ! err ) {
52
- return Promise . reject ( new Error ( 'Failed to read package.json, but received no error' ) )
53
- } else if ( pkgPath . endsWith ( '/package.json' ) || pkgPath === 'package.json' ) {
54
- return Promise . reject ( new Error ( 'Failed to read package.json: ' + err . message ) )
55
- } else if ( err . code === 'EISDIR' ) {
56
- pkgPath = path . join ( pkgPath , 'package.json' )
57
- return promisedReadPackage ( pkgPath )
58
- }
45
+ module . exports = async function ( opts ) {
46
+ let targetPath = opts . path
47
+ let pkgPath = targetPath
48
+ let entries = [ ]
49
+ let pkg
50
+
51
+ try {
52
+ pkg = await promisedReadPackage ( targetPath )
53
+ } catch ( err ) {
54
+ if ( targetPath . endsWith ( '/package.json' ) || targetPath === 'package.json' ) {
55
+ throw new Error ( 'Failed to read package.json: ' + err . message )
56
+ }
59
57
58
+ if ( err && err . code === 'EISDIR' ) {
59
+ pkgPath = path . join ( targetPath , 'package.json' )
60
+ } else {
60
61
// We've likely been given entries rather than a package.json or module path, try resolving that instead
61
62
entries = await resolveGlobbedPath ( pkgPath )
62
63
63
64
if ( ! entries [ 0 ] ) {
64
- return Promise . reject ( new Error ( 'Failed to find package.json, could not find any matching files' ) )
65
+ throw new Error ( 'Failed to find package.json, could not find any matching files' )
65
66
}
66
67
67
68
opts . noDefaultEntries = true
68
- pkgPath = pkgUp . sync ( { cwd : path . dirname ( entries [ 0 ] ) } )
69
+ pkgPath = await pkgUp ( { cwd : path . dirname ( entries [ 0 ] ) } )
70
+ }
69
71
70
- return promisedReadPackage ( pkgPath )
71
- } )
72
- . then ( pkg => parse ( {
73
- path : pkgPath ,
74
- package : pkg ,
75
- entries : ( entries || [ ] ) . concat ( opts . entries ) ,
76
- noDefaultEntries : opts . noDefaultEntries ,
77
- builtins : opts . builtins ,
78
- extensions : getExtensions ( opts . extensions , opts . detective )
79
- } ) )
80
-
81
- if ( cb ) {
82
- result
83
- . then ( value => { cb ( null , value ) } )
84
- . catch ( err => { cb ( err ) } )
85
- return
72
+ pkg = await promisedReadPackage ( pkgPath )
86
73
}
87
74
88
- return result
75
+ return parse ( {
76
+ path : pkgPath ,
77
+ package : pkg ,
78
+ entries : entries . concat ( opts . entries ) ,
79
+ noDefaultEntries : opts . noDefaultEntries ,
80
+ builtins : opts . builtins ,
81
+ extensions : getExtensions ( opts . extensions , opts . detective )
82
+ } )
89
83
}
90
84
91
85
module . exports . missing = function ( pkg , deps , options ) {
0 commit comments