@@ -97,17 +97,23 @@ function overrideNode () {
97
97
}
98
98
99
99
patchFn ( 'lstatSync' , lstatSync => p => {
100
- const resolved = pkglock . resolve ( p )
101
- if ( resolved == null ) {
100
+ try {
102
101
return lstatSync ( p )
103
- } else if ( ! resolved ) {
104
- return notFoundError ( p )
105
- } else {
106
- const stats = pkglock . statSync ( resolved )
107
- if ( ! stats ) {
108
- notFoundError ( p )
102
+ } catch ( err ) {
103
+ if ( err . code !== 'ENOENT' ) {
104
+ throw err
105
+ } else {
106
+ const resolved = pkglock . resolve ( p )
107
+ if ( ! resolved ) {
108
+ return notFoundError ( p )
109
+ } else {
110
+ const stats = pkglock . statSync ( resolved )
111
+ if ( ! stats ) {
112
+ notFoundError ( p )
113
+ }
114
+ return stats
115
+ }
109
116
}
110
- return stats
111
117
}
112
118
} )
113
119
@@ -129,17 +135,23 @@ function overrideNode () {
129
135
} )
130
136
131
137
patchFn ( 'statSync' , statSync => p => {
132
- const resolved = pkglock . resolve ( p )
133
- if ( resolved == null ) {
138
+ try {
134
139
return statSync ( p )
135
- } else if ( ! resolved ) {
136
- return notFoundError ( p )
137
- } else {
138
- const stats = pkglock . statSync ( resolved )
139
- if ( ! stats ) {
140
- notFoundError ( p )
140
+ } catch ( err ) {
141
+ if ( err . code !== 'ENOENT' ) {
142
+ throw err
143
+ } else {
144
+ const resolved = pkglock . resolve ( p )
145
+ if ( ! resolved ) {
146
+ return notFoundError ( p )
147
+ } else {
148
+ const stats = pkglock . statSync ( resolved )
149
+ if ( ! stats ) {
150
+ notFoundError ( p )
151
+ }
152
+ return stats
153
+ }
141
154
}
142
- return stats
143
155
}
144
156
} )
145
157
@@ -161,47 +173,54 @@ function overrideNode () {
161
173
} )
162
174
163
175
patchFn ( 'statSyncNoException' , statSyncNoException => p => {
164
- const resolved = pkglock . resolve ( p )
165
- if ( resolved == null ) {
166
- return statSyncNoException ( p )
167
- } else if ( ! resolved ) {
168
- return false
176
+ const ret = statSyncNoException ( p )
177
+ if ( ret ) {
178
+ return ret
169
179
} else {
170
- const stats = pkglock . statSync ( resolved )
171
- if ( ! stats ) {
180
+ const resolved = pkglock . resolve ( p )
181
+ if ( ! resolved ) {
172
182
return false
183
+ } else {
184
+ const stats = pkglock . statSync ( resolved )
185
+ if ( ! stats ) {
186
+ return false
187
+ }
188
+ return stats
173
189
}
174
- return stats
175
190
}
176
191
} )
177
192
178
- patchFn ( 'realpathSync' , realpathSync => function ( p ) {
179
- const resolved = pkglock . resolve ( p )
180
- if ( resolved == null ) {
181
- return realpathSync . apply ( this , arguments )
182
- } else if ( ! resolved ) {
183
- return notFoundError ( p )
184
- } else {
185
- return resolved . resolvedPath
193
+ patchFn ( 'realpathSync' , realpathSync => ( p , ...args ) => {
194
+ try {
195
+ return realpathSync ( p , ...args )
196
+ } catch ( err ) {
197
+ if ( err . code !== 'ENOENT' ) { throw err }
198
+ const resolved = pkglock . resolve ( p )
199
+ if ( ! resolved ) {
200
+ return notFoundError ( p )
201
+ } else {
202
+ return resolved . resolvedPath
203
+ }
186
204
}
187
205
} )
188
206
189
207
patchFn ( 'realpath' , realpath => function ( p , cache , cb ) {
190
- const resolved = pkglock . resolve ( p )
191
- if ( resolved == null ) {
192
- return realpath . apply ( this , arguments )
193
- }
194
- if ( typeof cache === 'function' ) {
195
- cb = cache
196
- cache = void 0
197
- }
198
-
199
- process . nextTick ( ( ) => {
200
- if ( resolved ) {
201
- cb ( null , resolved . resolvedPath )
202
- } else {
203
- notFoundError ( p , cb )
208
+ realpath ( p , cache , ( err , rp ) => {
209
+ if ( err && err . code !== 'ENOENT' ) { return cb ( err ) }
210
+ if ( ! err ) { return cb ( null , rp ) }
211
+ const resolved = pkglock . resolve ( p )
212
+ if ( typeof cache === 'function' ) {
213
+ cb = cache
214
+ cache = void 0
204
215
}
216
+
217
+ process . nextTick ( ( ) => {
218
+ if ( resolved ) {
219
+ cb ( null , resolved . resolvedPath )
220
+ } else {
221
+ notFoundError ( p , cb )
222
+ }
223
+ } )
205
224
} )
206
225
} )
207
226
0 commit comments