logo

yarnlock2srcuri

Transform yarn lockfile v1 files into entries for gentoo ebuild SRC_URI
commit: 74c5751809f0eca690f023773516ec224a47e4aa
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed, 26 Oct 2022 15:08:47 +0200

Initial Commit

Diffstat:

ALICENSES/MIT.txt9+++++++++
Ayarnlock2srcuri.pl37+++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) <year> <copyright holders> + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/yarnlock2srcuri.pl b/yarnlock2srcuri.pl @@ -0,0 +1,37 @@ +#!/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; + } +}