@@ -341,54 +341,53 @@ nvm_normalize_semver() {
341
341
if [ -z " $semver " ]; then
342
342
return 1
343
343
fi
344
+ local comparator_set
345
+ local validated_comparator_set
344
346
local validated_semver
345
347
validated_semver=' ' ;
346
348
while [ -n " $semver " ]; do
347
- local comparator_set
348
349
comparator_set=$( command printf " %s" " $semver " | command head -n1)
349
350
semver=$( command printf " %s" " $semver " | command tail -n +2)
350
351
[ -n " $comparator_set " ] || continue
351
352
352
353
# convert comparators into required grammar
353
- local validated_comparator_set
354
- validated_comparator_set=$( command printf " %s " " $comparator_set " \
355
- | command sed -E "
356
- # exactly 1 space is needed before and after every comparator (including the first and last comparators)
357
- s/\011/ /g;s/ +/ /g;
358
-
359
- # normalize all wildcards to x
360
- s/X|\*/x/g;
361
-
362
- # space out numbers surrounding '-'
363
- s/ ?- ?/ - /g;
364
-
365
- # ' 1 ' => ' 1.x.x '
366
- # ' x ' => ' x.x.x '
367
- s/ ([0-9]+|x) / \1.x.x /g;
368
-
369
- # ' 1.2 ' => ' 1.2.x '
370
- # ' 1.x ' => ' 1.x.x '
371
- # ' x.x ' => ' x.x.x '
372
- s/ (([0-9]+|x)\.([0-9]+|x)) / \1.x /g;
373
-
374
- # ' 1.2.3 - 1.2.4 ' => ' >=1.2.3 <=1.2.4 '
375
- s/ (([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) ?\- ?(([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) / >=\1 <=\5 /g;
376
-
377
- # ' > 1.2.3 ' => ' >1.2.3 '
378
- # ' < 1.2.5 ' => ' <1.2.5 '
379
- # ' <= 1.2.3 ' => ' <=1.2.3 '
380
- # ' >= 1.2.3 ' => ' >=1.2.3 '
381
- # ' = 1.2.3 ' => ' =1.2.3 '
382
- # ' ~ 1.2.3 ' => ' ~1.2.3 '
383
- # ' ^ 1.2.3 ' => ' ^1.2.3 '
384
- # ' v 1.2.3 ' => ' v1.2.3 '
385
- s/ (v|<|>|<=|>=|=|~|\^) (([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) / \1\2 /g;
386
-
387
- # ' =1.2.3 ' => ' 1.2.3 '
388
- # ' v1.2.3 ' => ' 1.2.3 '
389
- s/ (=|v)//g;
390
- " \
391
- | command awk ' {
354
+ validated_comparator_set=$( command printf " %s " " $comparator_set " |
355
+ command sed -E "
356
+ # exactly 1 space is needed before and after every comparator (including the first and last comparators)
357
+ s/\011/ /g;s/ +/ /g;
358
+
359
+ # normalize all wildcards to x
360
+ s/X|\*/x/g;
361
+
362
+ # space out numbers surrounding '-'
363
+ s/ ?- ?/ - /g;
364
+
365
+ # ' 1 ' => ' 1.x.x '
366
+ # ' x ' => ' x.x.x '
367
+ s/ ([0-9]+|x) / \1.x.x /g;
368
+
369
+ # ' 1.2 ' => ' 1.2.x '
370
+ # ' 1.x ' => ' 1.x.x '
371
+ # ' x.x ' => ' x.x.x '
372
+ s/ (([0-9]+|x)\.([0-9]+|x)) / \1.x /g;
373
+
374
+ # ' 1.2.3 - 1.2.4 ' => ' >=1.2.3 <=1.2.4 '
375
+ s/ (([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) ?\- ?(([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) / >=\1 <=\5 /g;
376
+
377
+ # ' > 1.2.3 ' => ' >1.2.3 '
378
+ # ' < 1.2.5 ' => ' <1.2.5 '
379
+ # ' <= 1.2.3 ' => ' <=1.2.3 '
380
+ # ' >= 1.2.3 ' => ' >=1.2.3 '
381
+ # ' = 1.2.3 ' => ' =1.2.3 '
382
+ # ' ~ 1.2.3 ' => ' ~1.2.3 '
383
+ # ' ^ 1.2.3 ' => ' ^1.2.3 '
384
+ # ' v 1.2.3 ' => ' v1.2.3 '
385
+ s/ (v|<|>|<=|>=|=|~|\^) (([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)) / \1\2 /g;
386
+
387
+ # ' =1.2.3 ' => ' 1.2.3 '
388
+ # ' v1.2.3 ' => ' 1.2.3 '
389
+ s/ (=|v)//g;" |
390
+ command awk ' {
392
391
# handle conversions of comparators with ^ or ~ or x into required grammar
393
392
# ` ^0.0.1 ` => ` >=0.0.1 <0.0.2 `
394
393
# ` ^0.1.2 ` => ` >=0.1.2 <0.2.0 `
@@ -462,8 +461,8 @@ nvm_normalize_semver() {
462
461
}
463
462
}
464
463
print output
465
- }' \
466
- | command sed -E ' s/^ +//;s/ +$//'
464
+ }' |
465
+ command sed -E ' s/^ +//;s/ +$//'
467
466
)
468
467
469
468
# only comparator_sets composed of the required grammar are marked as valid
@@ -500,13 +499,17 @@ nvm_interpret_complex_semver() {
500
499
# - Add the discovered newest compatible version to highest_compatible_versions.
501
500
# - Choose the highest version among all the versions collected in highest_compatible_versions.
502
501
semver=$( command printf " %s" " $semver " | command tr ' ||' ' \n' )
502
+ local version_list_copy
503
+ local current_comparator_set
504
+ local current_version
505
+ local current_comparator_set_copy
506
+ local current_comparator
507
+ local stripped_version_from_comparator
503
508
local highest_compatible_versions
504
509
highest_compatible_versions=' '
505
510
506
511
while [ -n " $semver " ]; do
507
- local version_list_copy
508
512
version_list_copy=$( command printf " %s" " $version_list " )
509
- local current_comparator_set
510
513
current_comparator_set=$( command printf " %s" " $semver " | command head -n1 | command sed -E ' s/^ +//;s/ +$//' )
511
514
semver=$( command printf " %s" " $semver " | command tail -n +2)
512
515
[ -n " $current_comparator_set " ] || continue
@@ -515,22 +518,18 @@ nvm_interpret_complex_semver() {
515
518
# - If current_version satisfies all comparators in current_comparator_set, we've found the newest version compatible with all comparators in current current_comparator_set.
516
519
# - Add discovered version to highest_compatible_versions and stop iterating through versions for current_comparator_set.
517
520
while [ -n " $version_list_copy " ]; do
518
- local current_version
519
521
current_version=$( command printf " %s" " $version_list_copy " | command tail -n1 | command sed -E ' s/^ +//;s/ +$//' | nvm_grep -o ' ^[0-9]\+\.[0-9]\+\.[0-9]\+$' )
520
522
version_list_copy=$( command printf " %s" " $version_list_copy " | command sed ' $d' )
521
523
[ -n " $current_version " ] || continue
522
524
523
525
# For each comparator in the current_comparator_set_copy:
524
526
# - If current_version is compatible with all comparators, we know current_version is the newest compatible version
525
- local current_comparator_set_copy
526
527
current_comparator_set_copy=$( command printf " %s" " $current_comparator_set " | command tr ' ' ' \n' )
527
528
while [ -n " $current_comparator_set_copy " ]; do
528
- local current_comparator
529
529
current_comparator=$( command printf " %s" " $current_comparator_set_copy " | command head -n1 | command sed -E ' s/^ +//;s/ +$//' )
530
530
current_comparator_set_copy=$( command printf " %s" " $current_comparator_set_copy " | command tail -n +2)
531
531
[ -n " $current_comparator " ] || continue
532
532
533
- local stripped_version_from_comparator
534
533
stripped_version_from_comparator=$( command printf " %s" " $current_comparator " | nvm_grep -o ' [0-9]\+\.[0-9]\+\.[0-9]\+$' )
535
534
if [ -z " $stripped_version_from_comparator " ]; then
536
535
return 1
@@ -618,10 +617,10 @@ nvm_interpret_complex_semver() {
618
617
# Since comparator sets are separated by '||', choosing any of the highest versions compatible with any of the comparator_sets would be compatible with the whole semver.
619
618
# Therefore, we should resolve to the highest version in highest_compatible_versions.
620
619
local highest_compatible_version
620
+ local compatible_node_version
621
621
highest_compatible_version=' 0.0.0'
622
622
highest_compatible_versions=$( command printf " %s" " $highest_compatible_versions " | command tr ' ' ' \n' )
623
623
while [ -n " $highest_compatible_versions " ]; do
624
- local compatible_node_version
625
624
compatible_node_version=$( command printf " %s" " $highest_compatible_versions " | command head -n1 | command sed -E ' s/^ +//;s/ +$//' )
626
625
highest_compatible_versions=$( command printf " %s" " $highest_compatible_versions " | command tail -n +2)
627
626
[ -n " $compatible_node_version " ] || continue
0 commit comments