logo

yarnlock2srcuri

Transform yarn lockfile v1 files into entries for gentoo ebuild SRC_URI

yarnlock2srcuri.pl (1075B)


  1. #!/usr/bin/env perl
  2. # Transform yarn lockfile v1 files into entries for gentoo ebuild SRC_URI
  3. # Copyright 2022 Haelwenn (lanodan) Monnier <contact+yarnlock2srcuri@hacktivis.me>
  4. # SPDX-License-Identifier: MIT
  5. use File::Basename;
  6. my $placeholder = '__invalid__';
  7. my $name = $placeholder;
  8. my $version = $placeholder;
  9. while (<>) {
  10. # TODO: Figure out accepted characters in package names
  11. # TODO: Better handling of multiple name entries (ie. "ajv@^6.10.0, ajv@^6.12.4:")
  12. if( /^(@?[\/\-\.a-z0-9]+)@([^:]*)(:|,.*)$/) { $name = $1; }
  13. if(/^"(@?[\/\-\.a-z0-9]+)@([^:]*)"(:|,.*)$/) { $name = $1; }
  14. if(/^ version "([^"]*)"$/) { $version=$1; }
  15. if(/^ resolved "([^#]*)#[^"]*"$/) {
  16. my $url = $1;
  17. if($name eq $placeholder) { die "Missing name value for $1"; }
  18. if($version eq $placeholder) { die "Missing version value for $1"; }
  19. my $basename = basename($url);
  20. $name =~ s|/|-|;
  21. my $tarname = "$name-$version.tgz";
  22. if($basename eq $tarname) {
  23. print "$url\n";
  24. } else {
  25. print "$url -> $tarname\n";
  26. }
  27. $name = $placeholder;
  28. $version = $placeholder;
  29. }
  30. }