yarnlock2srcuri.pl (1075B)
- #!/usr/bin/env perl
- # Transform yarn lockfile v1 files into entries for gentoo ebuild SRC_URI
- # Copyright 2022 Haelwenn (lanodan) Monnier <contact+yarnlock2srcuri@hacktivis.me>
- # SPDX-License-Identifier: MIT
- use File::Basename;
- my $placeholder = '__invalid__';
- my $name = $placeholder;
- my $version = $placeholder;
- while (<>) {
- # TODO: Figure out accepted characters in package names
- # TODO: Better handling of multiple name entries (ie. "ajv@^6.10.0, ajv@^6.12.4:")
- if( /^(@?[\/\-\.a-z0-9]+)@([^:]*)(:|,.*)$/) { $name = $1; }
- if(/^"(@?[\/\-\.a-z0-9]+)@([^:]*)"(:|,.*)$/) { $name = $1; }
- if(/^ version "([^"]*)"$/) { $version=$1; }
- if(/^ resolved "([^#]*)#[^"]*"$/) {
- my $url = $1;
- if($name eq $placeholder) { die "Missing name value for $1"; }
- if($version eq $placeholder) { die "Missing version value for $1"; }
- my $basename = basename($url);
- $name =~ s|/|-|;
- my $tarname = "$name-$version.tgz";
- if($basename eq $tarname) {
- print "$url\n";
- } else {
- print "$url -> $tarname\n";
- }
- $name = $placeholder;
- $version = $placeholder;
- }
- }