|
|
d709f2 |
#!/usr/bin/env python3
|
|
|
d709f2 |
import sys
|
|
|
d709f2 |
import json
|
|
|
d709f2 |
import re
|
|
|
d709f2 |
from packaging import version
|
|
|
d709f2 |
|
|
|
d709f2 |
|
|
|
d709f2 |
def read_declared_pkgs(package_json_path):
|
|
|
d709f2 |
with open(package_json_path) as f:
|
|
|
d709f2 |
package_json = json.load(f)
|
|
|
d709f2 |
return list(package_json['dependencies'].keys())
|
|
|
d709f2 |
|
|
|
d709f2 |
|
|
|
d709f2 |
def read_installed_pkgs(yarn_lock_path):
|
|
|
d709f2 |
with open(yarn_lock_path) as f:
|
|
|
d709f2 |
lockfile = f.read()
|
|
|
d709f2 |
return re.findall(r'^"?' # can start with a "
|
|
|
d709f2 |
r'(.+?)@.+(?:,.*)?:\n' # characters up to @
|
|
|
d709f2 |
r' version "(.+)"', # and the version
|
|
|
d709f2 |
lockfile, re.MULTILINE)
|
|
|
d709f2 |
|
|
|
d709f2 |
|
|
|
d709f2 |
def list_provides(declared_pkgs, installed_pkgs):
|
|
|
d709f2 |
for declared_pkg in declared_pkgs:
|
|
|
d709f2 |
# there can be multiple versions installed of one package (transitive dependencies)
|
|
|
d709f2 |
# but rpm doesn't support Provides: with a single package and multiple versions
|
|
|
d709f2 |
# so let's declare the oldest version here
|
|
|
d709f2 |
versions = [version.parse(pkg_version)
|
|
|
d709f2 |
for pkg_name, pkg_version in installed_pkgs if pkg_name == declared_pkg]
|
|
|
d709f2 |
oldest_version = sorted(versions)[0]
|
|
|
d709f2 |
yield f"Provides: bundled(nodejs-{declared_pkg}) = {oldest_version}"
|
|
|
d709f2 |
|
|
|
d709f2 |
|
|
|
d709f2 |
if __name__ == "__main__":
|
|
|
d709f2 |
if len(sys.argv) != 2:
|
|
|
d709f2 |
print(f"usage: {sys.argv[0]} grafana-X.Y.Z/", file=sys.stdout)
|
|
|
d709f2 |
sys.exit(1)
|
|
|
d709f2 |
|
|
|
d709f2 |
grafana_dir = sys.argv[1]
|
|
|
d709f2 |
declared_pkgs = read_declared_pkgs(f"{grafana_dir}/package.json")
|
|
|
d709f2 |
installed_pkgs = read_installed_pkgs(f"{grafana_dir}/yarn.lock")
|
|
|
d709f2 |
provides = list_provides(declared_pkgs, installed_pkgs)
|
|
|
d709f2 |
for provide in sorted(provides):
|
|
|
d709f2 |
print(provide)
|