1
+ use crate :: package:: parsing:: IntoPackageList ;
1
2
use crate :: package:: Package ;
2
3
use anyhow:: Result ;
3
4
use console:: style;
4
- use futures :: stream :: { self , StreamExt } ;
5
+ use reqwest :: Client ;
5
6
use serde:: { Deserialize , Serialize } ;
6
7
use std:: collections:: HashMap ;
7
8
@@ -43,7 +44,7 @@ impl From<ConfigFile> for ParsedConfig {
43
44
packages : from
44
45
. packages
45
46
. into_iter ( )
46
- . map ( |p| ( p. name , p. version ) )
47
+ . map ( |p| ( p. name , p. version . to_string ( ) ) )
47
48
. collect ( ) ,
48
49
}
49
50
}
@@ -58,13 +59,12 @@ impl ParsedConfig {
58
59
} )
59
60
}
60
61
61
- pub async fn into_configfile ( self ) -> ConfigFile {
62
- let packages = stream:: iter ( self . packages . into_iter ( ) )
63
- . map ( |( name, version) | async { Package :: new ( name, version) . await . unwrap ( ) } )
64
- . buffer_unordered ( crate :: PARALLEL )
65
- . collect :: < Vec < Package > > ( )
66
- . await ;
67
- ConfigFile { packages }
62
+ pub async fn into_configfile ( self , client : Client ) -> ConfigFile {
63
+ let mut packages = self . packages . into_package_list ( client) . await . unwrap ( ) ;
64
+ for mut p in & mut packages {
65
+ p. indirect = false
66
+ }
67
+ ConfigFile { packages : packages }
68
68
}
69
69
}
70
70
@@ -80,24 +80,24 @@ impl ConfigFile {
80
80
81
81
/// Creates a new [ConfigFile] from the given text
82
82
/// Panics if the file cant be parsed as toml, hjson or yaml.
83
- pub async fn new ( contents : & String ) -> Self {
83
+ pub async fn new ( contents : & String , client : Client ) -> Self {
84
84
if contents. is_empty ( ) {
85
85
panic ! ( "Empty CFG" ) ;
86
86
}
87
87
88
88
// definetly not going to backfire
89
89
let mut cfg = if contents. as_bytes ( ) [ 0 ] == b'{' {
90
90
// json gets brute forced first so this isnt really needed
91
- Self :: parse ( contents, ConfigType :: JSON )
91
+ Self :: parse ( contents, ConfigType :: JSON , client )
92
92
. await
93
93
. expect ( "Parsing CFG from JSON should work" )
94
94
} else if contents. len ( ) > 3 && contents[ ..3 ] == * "---" {
95
- Self :: parse ( contents, ConfigType :: YAML )
95
+ Self :: parse ( contents, ConfigType :: YAML , client )
96
96
. await
97
97
. expect ( "Parsing CFG from YAML should work" )
98
98
} else {
99
99
for i in [ ConfigType :: JSON , ConfigType :: YAML , ConfigType :: TOML ] . into_iter ( ) {
100
- let res = Self :: parse ( contents, i) . await ;
100
+ let res = Self :: parse ( contents, i, client . clone ( ) ) . await ;
101
101
102
102
// im sure theres some kind of idiomatic rust way to do this that i dont know of
103
103
if res. is_ok ( ) {
@@ -118,16 +118,16 @@ impl ConfigFile {
118
118
cfg
119
119
}
120
120
121
- pub async fn parse ( txt : & str , t : ConfigType ) -> Result < Self > {
122
- Ok ( ParsedConfig :: parse ( txt, t) ?. into_configfile ( ) . await )
121
+ pub async fn parse ( txt : & str , t : ConfigType , client : Client ) -> Result < Self > {
122
+ Ok ( ParsedConfig :: parse ( txt, t) ?. into_configfile ( client ) . await )
123
123
}
124
124
125
125
/// Creates a lockfile for this config file.
126
126
/// note: Lockfiles are currently unused.
127
- pub async fn lock ( & mut self ) -> String {
127
+ pub fn lock ( & mut self ) -> String {
128
128
let mut pkgs = vec ! [ ] ;
129
- for mut p in self . collect ( ) {
130
- if p. is_installed ( ) && p . get_manifest ( ) . await . is_ok ( ) {
129
+ for p in self . collect ( ) {
130
+ if p. is_installed ( ) {
131
131
pkgs. push ( p)
132
132
} ;
133
133
}
@@ -140,7 +140,7 @@ impl ConfigFile {
140
140
for p in pkgs {
141
141
cb ( p) ;
142
142
if p. has_deps ( ) {
143
- inner ( & mut p. dependencies , cb) ;
143
+ inner ( & mut p. manifest . dependencies , cb) ;
144
144
}
145
145
}
146
146
}
@@ -168,10 +168,23 @@ mod tests {
168
168
#[ tokio:: test]
169
169
async fn parse ( ) {
170
170
let _t = crate :: test_utils:: mktemp ( ) ;
171
+ let c = Client :: new ( ) ;
171
172
let cfgs: [ & mut ConfigFile ; 3 ] = [
172
- & mut ConfigFile :: new ( & r#"dependencies: { "@bendn/test": 2.0.10 }"# . into ( ) ) . await , // quoteless fails as a result of https://github.com/Canop/deser-hjson/issues/9
173
- & mut ConfigFile :: new ( & "dependencies:\n \" @bendn/test\" : 2.0.10" . into ( ) ) . await ,
174
- & mut ConfigFile :: new ( & "[dependencies]\n \" @bendn/test\" = \" 2.0.10\" " . into ( ) ) . await ,
173
+ & mut ConfigFile :: new (
174
+ & r#"dependencies: { "@bendn/test": 2.0.10 }"# . into ( ) ,
175
+ c. clone ( ) ,
176
+ )
177
+ . await , // quoteless fails as a result of https://github.com/Canop/deser-hjson/issues/9
178
+ & mut ConfigFile :: new (
179
+ & "dependencies:\n \" @bendn/test\" : 2.0.10" . into ( ) ,
180
+ c. clone ( ) ,
181
+ )
182
+ . await ,
183
+ & mut ConfigFile :: new (
184
+ & "[dependencies]\n \" @bendn/test\" = \" 2.0.10\" " . into ( ) ,
185
+ c. clone ( ) ,
186
+ )
187
+ . await ,
175
188
] ;
176
189
#[ derive( Debug , Deserialize , Clone , Eq , PartialEq ) ]
177
190
struct LockFileEntry {
@@ -185,16 +198,16 @@ mod tests {
185
198
for cfg in cfgs {
186
199
assert_eq ! ( cfg. packages. len( ) , 1 ) ;
187
200
assert_eq ! ( cfg. packages[ 0 ] . to_string( ) , "@bendn/test@2.0.10" ) ;
188
- assert_eq ! ( cfg. packages[ 0 ] . dependencies. len( ) , 1 ) ;
201
+ assert_eq ! ( cfg. packages[ 0 ] . manifest . dependencies. len( ) , 1 ) ;
189
202
assert_eq ! (
190
- cfg. packages[ 0 ] . dependencies[ 0 ] . to_string( ) ,
203
+ cfg. packages[ 0 ] . manifest . dependencies[ 0 ] . to_string( ) ,
191
204
"@bendn/gdcli@1.2.5"
192
205
) ;
193
206
for mut p in cfg. collect ( ) {
194
- p. download ( ) . await
207
+ p. download ( c . clone ( ) ) . await
195
208
}
196
209
assert_eq ! (
197
- serde_json:: from_str:: <Vec <LockFileEntry >>( cfg. lock( ) . await . as_str( ) ) . unwrap( ) ,
210
+ serde_json:: from_str:: <Vec <LockFileEntry >>( cfg. lock( ) . as_str( ) ) . unwrap( ) ,
198
211
wanted_lockfile
199
212
) ;
200
213
}
0 commit comments