@@ -140,7 +140,6 @@ fn vpm_search(keywords []string) {
140
140
joined := search_keys.join (', ' )
141
141
mut index := 0
142
142
for mod in modules {
143
- // TODO for some reason .filter results in substr error, so do it manually
144
143
for k in search_keys {
145
144
if ! mod.contains (k) {
146
145
continue
@@ -209,7 +208,7 @@ fn vpm_install_from_vpm(module_names []string) {
209
208
vpm_update ([name])
210
209
continue
211
210
}
212
- println ('Installing module "$name " from $mod.url to $final_module_path ...' )
211
+ println ('Installing module "$name " from " $mod.url " to " $final_module_path " ...' )
213
212
vcs_install_cmd := supported_vcs_install_cmds[vcs]
214
213
cmd := '$vcs_install_cmd "$mod.url " "$final_module_path "'
215
214
verbose_println (' command: $cmd ' )
@@ -250,7 +249,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
250
249
251
250
first_cut_pos := url.last_index ('/' ) or {
252
251
errors++
253
- println ('Errors while retrieving name for module $url :' )
252
+ println ('Errors while retrieving name for module " $url " :' )
254
253
println (err)
255
254
continue
256
255
}
@@ -259,7 +258,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
259
258
260
259
second_cut_pos := url.substr (0 , first_cut_pos).last_index ('/' ) or {
261
260
errors++
262
- println ('Errors while retrieving name for module $url :' )
261
+ println ('Errors while retrieving name for module " $url " :' )
263
262
println (err)
264
263
continue
265
264
}
@@ -277,7 +276,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
277
276
println ('VPM needs `$vcs_key ` to be installed.' )
278
277
continue
279
278
}
280
- println ('Installing module "$name " from $url to $final_module_path ...' )
279
+ println ('Installing module "$name " from " $url " to " $final_module_path " ...' )
281
280
vcs_install_cmd := supported_vcs_install_cmds[vcs_key]
282
281
cmd := '$vcs_install_cmd "$url " "$final_module_path "'
283
282
verbose_println (' command: $cmd ' )
@@ -294,7 +293,7 @@ fn vpm_install_from_vcs(module_names []string, vcs_key string) {
294
293
vmod := parse_vmod (data)
295
294
mod_path := os.real_path (os.join_path (settings.vmodules_path, vmod.name.replace ('.' ,
296
295
os.path_separator)))
297
- println ('Relocating module from "$name " to "$vmod.name " ( $mod_path ) ...' )
296
+ println ('Relocating module from "$name " to "$vmod.name " ( " $mod_path " ) ...' )
298
297
if os.exists (mod_path) {
299
298
println ('Warning module "$mod_path " already exsits!' )
300
299
println ('Removing module "$mod_path " ...' )
@@ -359,11 +358,14 @@ fn vpm_update(m []string) {
359
358
module_names = get_installed_modules ()
360
359
}
361
360
mut errors := 0
362
- for name in module_names {
363
- final_module_path := valid_final_path_of_existing_module (name) or { continue }
361
+ for modulename in module_names {
362
+ mut zname := modulename
363
+ if mod := get_mod_by_url (modulename) {
364
+ zname = mod.name
365
+ }
366
+ final_module_path := valid_final_path_of_existing_module (modulename) or { continue }
364
367
os.chdir (final_module_path) or {}
365
- println ('Updating module "$name "...' )
366
- verbose_println (' work folder: $final_module_path ' )
368
+ println ('Updating module "$zname " in "$final_module_path " ...' )
367
369
vcs := vcs_used_in_dir (final_module_path) or { continue }
368
370
if ! ensure_vcs_is_installed (vcs[0 ]) {
369
371
errors++
@@ -375,13 +377,13 @@ fn vpm_update(m []string) {
375
377
vcs_res := os.execute ('$vcs_cmd ' )
376
378
if vcs_res.exit_code != 0 {
377
379
errors++
378
- println ('Failed updating module "$name " .' )
380
+ println ('Failed updating module "$zname " in " $final_module_path " .' )
379
381
print_failed_cmd (vcs_cmd, vcs_res)
380
382
continue
381
383
} else {
382
384
verbose_println (' $vcs_res.output.trim_space ()' )
383
385
}
384
- resolve_dependencies (name , final_module_path, module_names)
386
+ resolve_dependencies (modulename , final_module_path, module_names)
385
387
}
386
388
if errors > 0 {
387
389
exit (1 )
@@ -402,7 +404,7 @@ fn get_outdated() ?[]string {
402
404
if res.exit_code < 0 {
403
405
verbose_println ('Error command: $step ' )
404
406
verbose_println ('Error details:\n $res.output ' )
405
- return error ('Error while checking latest commits for "$name ".' )
407
+ return error ('Error while checking latest commits for "$name " .' )
406
408
}
407
409
if vcs[0 ] == 'hg' {
408
410
if res.exit_code == 1 {
@@ -463,7 +465,7 @@ fn vpm_remove(module_names []string) {
463
465
}
464
466
for name in module_names {
465
467
final_module_path := valid_final_path_of_existing_module (name) or { continue }
466
- println ('Removing module "$name "...' )
468
+ println ('Removing module "$name " ...' )
467
469
verbose_println ('removing folder $final_module_path ' )
468
470
os.rmdir_all (final_module_path) or {
469
471
verbose_println ('error while removing "$final_module_path ": $err.msg ' )
@@ -483,7 +485,11 @@ fn vpm_remove(module_names []string) {
483
485
}
484
486
}
485
487
486
- fn valid_final_path_of_existing_module (name string ) ? string {
488
+ fn valid_final_path_of_existing_module (modulename string ) ? string {
489
+ mut name := modulename
490
+ if mod := get_mod_by_url (name) {
491
+ name = mod.name
492
+ }
487
493
mod_name_as_path := name.replace ('.' , os.path_separator).replace ('-' , '_' ).to_lower ()
488
494
name_of_vmodules_folder := os.join_path (settings.vmodules_path, mod_name_as_path)
489
495
final_module_path := os.real_path (name_of_vmodules_folder)
@@ -504,7 +510,7 @@ fn valid_final_path_of_existing_module(name string) ?string {
504
510
505
511
fn ensure_vmodules_dir_exist () {
506
512
if ! os.is_dir (settings.vmodules_path) {
507
- println ('Creating $settings.vmodules_path / ...' )
513
+ println ('Creating " $settings.vmodules_path /" ...' )
508
514
os.mkdir (settings.vmodules_path) or { panic (err) }
509
515
}
510
516
}
@@ -601,7 +607,7 @@ fn resolve_dependencies(name string, module_path string, module_names []string)
601
607
}
602
608
}
603
609
if deps.len > 0 {
604
- println ('Resolving $deps.len dependencies for module "$name "...' )
610
+ println ('Resolving $deps.len dependencies for module "$name " ...' )
605
611
verbose_println ('Found dependencies: $deps ' )
606
612
vpm_install (deps, Source.vpm)
607
613
}
@@ -663,39 +669,44 @@ fn verbose_println(s string) {
663
669
}
664
670
}
665
671
666
- fn get_module_meta_info (name string ) ? Mod {
667
- mut errors := []string {}
668
-
672
+ fn get_mod_by_url (name string ) ? Mod {
669
673
if purl := urllib.parse (name) {
670
674
verbose_println ('purl: $purl ' )
671
675
mod := Mod{
672
- name: purl.path.trim_left ('/' ).trim_right ('/' )
676
+ name: purl.path.trim_left ('/' ).trim_right ('/' ). replace ( '/' , '.' )
673
677
url: name
674
678
}
675
679
verbose_println (mod.str ())
676
680
return mod
677
681
}
682
+ return error ('invalid url: $name ' )
683
+ }
678
684
685
+ fn get_module_meta_info (name string ) ? Mod {
686
+ if mod := get_mod_by_url (name) {
687
+ return mod
688
+ }
689
+ mut errors := []string {}
679
690
for server_url in default_vpm_server_urls {
680
691
modurl := server_url + '/jsmod/$name '
681
- verbose_println ('Retrieving module metadata from: $modurl ...' )
692
+ verbose_println ('Retrieving module metadata from: " $modurl " ...' )
682
693
r := http.get (modurl) or {
683
- errors << 'Http server did not respond to our request for ${modurl} .'
694
+ errors << 'Http server did not respond to our request for " ${modurl} " .'
684
695
errors << 'Error details: $err '
685
696
continue
686
697
}
687
698
if r.status_code == 404 || r.text.trim_space () == '404' {
688
- errors << 'Skipping module "$name ", since $server_url reported that "$name " does not exist.'
699
+ errors << 'Skipping module "$name ", since " $server_url " reported that "$name " does not exist.'
689
700
continue
690
701
}
691
702
if r.status_code != 200 {
692
- errors << 'Skipping module "$name ", since $server_url responded with $r.status_code http status code. Please try again later.'
703
+ errors << 'Skipping module "$name ", since " $server_url " responded with $r.status_code http status code. Please try again later.'
693
704
continue
694
705
}
695
706
s := r.text
696
707
if s.len > 0 && s[0 ] != `{` {
697
708
errors << 'Invalid json data'
698
- errors << s.trim_space ().limit (100 ) + '...'
709
+ errors << s.trim_space ().limit (100 ) + ' ...'
699
710
continue
700
711
}
701
712
mod := json.decode (Mod, s) or {
0 commit comments