@@ -94,13 +94,13 @@ pub fn find_closest_pnp_manifest_path(path: &Path) -> Option<PathBuf> {
94
94
None
95
95
}
96
96
97
- pub fn load_pnp_manifest < P : AsRef < Path > > ( p : P ) -> Result < Manifest , Error > {
98
- let manifest_content = std:: fs:: read_to_string ( p. as_ref ( ) ) . map_err ( |err| {
97
+ pub fn load_pnp_manifest ( p : & Path ) -> Result < Manifest , Error > {
98
+ let manifest_content = std:: fs:: read_to_string ( p) . map_err ( |err| {
99
99
Error :: FailedManifestHydration ( Box :: new ( FailedManifestHydration {
100
100
message : format ! (
101
101
"We failed to read the content of the manifest.\n \n Original error: {err}"
102
102
) ,
103
- manifest_path : p. as_ref ( ) . to_path_buf ( ) ,
103
+ manifest_path : p. to_path_buf ( ) ,
104
104
} ) )
105
105
} ) ?;
106
106
@@ -117,7 +117,7 @@ pub fn load_pnp_manifest<P: AsRef<Path>>(p: P) -> Result<Manifest, Error> {
117
117
. unwrap_or_default ( )
118
118
. ok_or_else ( || Error :: FailedManifestHydration ( Box :: new ( FailedManifestHydration {
119
119
message : String :: from ( "We failed to locate the PnP data payload inside its manifest file. Did you manually edit the file?" ) ,
120
- manifest_path : p. as_ref ( ) . to_path_buf ( ) ,
120
+ manifest_path : p. to_path_buf ( ) ,
121
121
} ) ) ) ?;
122
122
123
123
let iter = manifest_content. chars ( ) . skip ( manifest_match. end ( ) ) ;
@@ -142,18 +142,18 @@ pub fn load_pnp_manifest<P: AsRef<Path>>(p: P) -> Result<Manifest, Error> {
142
142
let mut manifest: Manifest = serde_json:: from_str ( & json_string. to_owned ( ) )
143
143
. map_err ( |err| Error :: FailedManifestHydration ( Box :: new ( FailedManifestHydration {
144
144
message : format ! ( "We failed to parse the PnP data payload as proper JSON; Did you manually edit the file?\n \n Original error: {err}" ) ,
145
- manifest_path : p. as_ref ( ) . to_path_buf ( ) ,
145
+ manifest_path : p. to_path_buf ( ) ,
146
146
} ) ) ) ?;
147
147
148
- init_pnp_manifest ( & mut manifest, p. as_ref ( ) ) ;
148
+ init_pnp_manifest ( & mut manifest, p) ;
149
149
150
150
Ok ( manifest)
151
151
}
152
152
153
- pub fn init_pnp_manifest < P : AsRef < Path > > ( manifest : & mut Manifest , p : P ) {
154
- manifest. manifest_path = p. as_ref ( ) . to_path_buf ( ) ;
153
+ pub fn init_pnp_manifest ( manifest : & mut Manifest , p : & Path ) {
154
+ manifest. manifest_path = p. to_path_buf ( ) ;
155
155
156
- manifest. manifest_dir = p. as_ref ( ) . parent ( ) . expect ( "Should have a parent directory" ) . to_owned ( ) ;
156
+ manifest. manifest_dir = p. parent ( ) . expect ( "Should have a parent directory" ) . to_owned ( ) ;
157
157
158
158
for ( name, ranges) in manifest. package_registry_data . iter_mut ( ) {
159
159
for ( reference, info) in ranges. iter_mut ( ) {
@@ -187,17 +187,14 @@ pub fn init_pnp_manifest<P: AsRef<Path>>(manifest: &mut Manifest, p: P) {
187
187
}
188
188
189
189
pub fn find_pnp_manifest ( parent : & Path ) -> Result < Option < Manifest > , Error > {
190
- find_closest_pnp_manifest_path ( parent) . map_or ( Ok ( None ) , |p| Ok ( Some ( load_pnp_manifest ( p) ?) ) )
190
+ find_closest_pnp_manifest_path ( parent) . map_or ( Ok ( None ) , |p| Ok ( Some ( load_pnp_manifest ( & p) ?) ) )
191
191
}
192
192
193
193
pub fn is_dependency_tree_root < ' a > ( manifest : & ' a Manifest , locator : & ' a PackageLocator ) -> bool {
194
194
manifest. dependency_tree_roots . contains ( locator)
195
195
}
196
196
197
- pub fn find_locator < ' a , P : AsRef < Path > > (
198
- manifest : & ' a Manifest ,
199
- path : & P ,
200
- ) -> Option < & ' a PackageLocator > {
197
+ pub fn find_locator < ' a > ( manifest : & ' a Manifest , path : & Path ) -> Option < & ' a PackageLocator > {
201
198
let rel_path = pathdiff:: diff_paths ( path, & manifest. manifest_dir )
202
199
. expect ( "Assertion failed: Provided path should be absolute" ) ;
203
200
@@ -240,14 +237,14 @@ pub fn find_broken_peer_dependencies(
240
237
[ ] . to_vec ( )
241
238
}
242
239
243
- pub fn resolve_to_unqualified_via_manifest < P : AsRef < Path > > (
240
+ pub fn resolve_to_unqualified_via_manifest (
244
241
manifest : & Manifest ,
245
242
specifier : & str ,
246
- parent : P ,
243
+ parent : & Path ,
247
244
) -> Result < Resolution , Error > {
248
245
let ( ident, module_path) = parse_bare_identifier ( specifier) ?;
249
246
250
- if let Some ( parent_locator) = find_locator ( manifest, & parent) {
247
+ if let Some ( parent_locator) = find_locator ( manifest, parent) {
251
248
let parent_pkg = get_package ( manifest, parent_locator) ?;
252
249
253
250
let mut reference_or_alias: Option < PackageDependency > = None ;
@@ -281,7 +278,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
281
278
} else {
282
279
String :: from( "" )
283
280
} ,
284
- issuer_path = parent. as_ref ( ) . to_string_lossy( ) ,
281
+ issuer_path = parent. to_string_lossy( ) ,
285
282
)
286
283
} else {
287
284
format ! (
@@ -293,7 +290,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
293
290
} else {
294
291
String :: from( "" )
295
292
} ,
296
- issuer_path = parent. as_ref ( ) . to_string_lossy( ) ,
293
+ issuer_path = parent. to_string_lossy( ) ,
297
294
)
298
295
}
299
296
} else if is_dependency_tree_root ( manifest, parent_locator) {
@@ -305,7 +302,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
305
302
} else {
306
303
String :: from( "" )
307
304
} ,
308
- issuer_path = parent. as_ref ( ) . to_string_lossy( ) ,
305
+ issuer_path = parent. to_string_lossy( ) ,
309
306
)
310
307
} else {
311
308
format ! (
@@ -318,7 +315,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
318
315
} else {
319
316
String :: from( "" )
320
317
} ,
321
- issuer_path = parent. as_ref ( ) . to_string_lossy( ) ,
318
+ issuer_path = parent. to_string_lossy( ) ,
322
319
)
323
320
} ;
324
321
@@ -327,7 +324,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
327
324
request : specifier. to_string ( ) ,
328
325
dependency_name : ident,
329
326
issuer_locator : parent_locator. clone ( ) ,
330
- issuer_path : parent. as_ref ( ) . to_path_buf ( ) ,
327
+ issuer_path : parent. to_path_buf ( ) ,
331
328
} ) ) ) ;
332
329
}
333
330
@@ -354,7 +351,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
354
351
} else {
355
352
String :: from( "" )
356
353
} ,
357
- issuer_path = parent. as_ref ( ) . to_string_lossy( ) ,
354
+ issuer_path = parent. to_string_lossy( ) ,
358
355
)
359
356
} else if !broken_ancestors. is_empty ( )
360
357
&& broken_ancestors. iter ( ) . all ( |locator| is_dependency_tree_root ( manifest, locator) )
@@ -369,7 +366,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
369
366
} else {
370
367
String :: from( "" )
371
368
} ,
372
- issuer_path = parent. as_ref ( ) . to_string_lossy( ) ,
369
+ issuer_path = parent. to_string_lossy( ) ,
373
370
)
374
371
} else {
375
372
format ! (
@@ -382,7 +379,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
382
379
} else {
383
380
String :: from( "" )
384
381
} ,
385
- issuer_path = parent. as_ref ( ) . to_string_lossy( ) ,
382
+ issuer_path = parent. to_string_lossy( ) ,
386
383
)
387
384
} ;
388
385
@@ -391,7 +388,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
391
388
request : specifier. to_string ( ) ,
392
389
dependency_name : ident,
393
390
issuer_locator : parent_locator. clone ( ) ,
394
- issuer_path : parent. as_ref ( ) . to_path_buf ( ) ,
391
+ issuer_path : parent. to_path_buf ( ) ,
395
392
broken_ancestors : [ ] . to_vec ( ) ,
396
393
} ) ) )
397
394
}
@@ -400,13 +397,13 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
400
397
}
401
398
}
402
399
403
- pub fn resolve_to_unqualified < P : AsRef < Path > > (
400
+ pub fn resolve_to_unqualified (
404
401
specifier : & str ,
405
- parent : P ,
402
+ parent : & Path ,
406
403
config : & ResolutionConfig ,
407
404
) -> Result < Resolution , Error > {
408
- if let Some ( manifest) = ( config. host . find_pnp_manifest ) ( parent. as_ref ( ) ) ? {
409
- resolve_to_unqualified_via_manifest ( & manifest, specifier, & parent)
405
+ if let Some ( manifest) = ( config. host . find_pnp_manifest ) ( parent) ? {
406
+ resolve_to_unqualified_via_manifest ( & manifest, specifier, parent)
410
407
} else {
411
408
Ok ( Resolution :: Skipped )
412
409
}
0 commit comments