#!/usr/bin/env python3
# Show release times of all devDependencies of our package.lock, sorted by time.
# This is useful to track down build regressions.

import json
import urllib.request

# only read the top-level modules, not the transitive dependencies
deps = []  # (module_name, version, release_time)
with open('package.json') as f:
    for package, specver in json.load(f)['devDependencies'].items():
        if specver.startswith('file:'):
            continue
        with urllib.request.urlopen("https://registry.npmjs.org/" + package) as req:
            npmdata = json.load(req)
            version = npmdata['dist-tags']['latest']
            released = npmdata['time'][version]
        # show some verbose progress
        print("%s: version %s, released %s" % (package, version, released), end=' ' * 20 + '\r')
        deps.append((package, version, released))
    # clear line
    print(end=' ' * 40 + '\r')

deps.sort(key=lambda p: p[2])
for (mod, ver, time) in deps:
    print(mod, ver, time)
