| 45 | |
| 46 | |
| 47 | def collect(ui_dir, dep_tree, out): |
| 48 | for name, info in (dep_tree or {}).items(): |
| 49 | version = info.get("version") |
| 50 | if not version: |
| 51 | continue |
| 52 | pkg_dir = os.path.join(ui_dir, "node_modules", *name.split("/")) |
| 53 | try: |
| 54 | with open(os.path.join(pkg_dir, "package.json"), encoding="utf-8") as fh: |
| 55 | meta = json.load(fh) |
| 56 | except (OSError, ValueError): |
| 57 | continue |
| 58 | # Platform-restricted packages (os/cpu) are checked like any other: |
| 59 | # skipping them is how sharp's LGPL libvips binaries passed unseen. |
| 60 | lic = meta.get("license", "") |
| 61 | if isinstance(lic, dict): |
| 62 | lic = lic.get("type", "") |
| 63 | out[(name, version)] = (str(lic or ""), pkg_dir) |
| 64 | collect(ui_dir, info.get("dependencies"), out) |
| 65 | |
| 66 | |
| 67 | def main(): |