MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / main

Function main

scripts/license-gate-check-npm.py:67–114  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65
66
67def main():
68 ui_dir, policy_path = sys.argv[1], sys.argv[2]
69 with open(policy_path) as fh:
70 policy = json.load(fh)
71 allowed = {x.lower() for x in policy["allowed_spdx_ids"]}
72 ignored_pkgs = set(policy.get("ignored_npm_packages", []))
73 skip_tokens = {"and", "or", "with", ""}
74
75 # shell=True so the npm shim resolves on every platform (npm.cmd on
76 # Windows is not found by bare-name exec). Constant command, no injection.
77 ls = subprocess.run("npm ls --omit=dev --all --json",
78 shell=True, cwd=ui_dir, capture_output=True, text=True, check=False)
79 tree = json.loads(ls.stdout or "{}")
80 pkgs = {}
81 collect(ui_dir, tree.get("dependencies"), pkgs)
82 if not pkgs:
83 print("FAIL: npm production tree resolved to zero packages — "
84 "is node_modules installed?")
85 sys.exit(1)
86
87 try:
88 validate_browser_build(ui_dir)
89 except ValueError as exc:
90 print(f"BLOCKED: browser build evidence does not verify: {exc}")
91 sys.exit(1)
92
93 violations = []
94 for (name, version), (lic, pkg_dir) in sorted(pkgs.items()):
95 if name in ignored_pkgs:
96 continue
97 if not lic:
98 lic = license_from_file(pkg_dir) or ""
99 if not lic:
100 violations.append((f"{name}@{version}", "no resolvable license"))
101 continue
102 for tok in re.split(r"[\s()]+", lic):
103 if tok.lower() in skip_tokens:
104 continue
105 if tok.lower() not in allowed:
106 violations.append((f"{name}@{version}", lic))
107 break
108
109 if violations:
110 print("BLOCKED: %d UI package(s) outside the license allow-list:" % len(violations))
111 for pkg, lic in violations[:25]:
112 print(f" {pkg}: {lic}")
113 sys.exit(1)
114 print(f"OK: {len(pkgs)} npm packages covered, all allow-listed")
115
116
117if __name__ == "__main__":

Callers 1

Calls 8

validate_browser_buildFunction · 0.90
setFunction · 0.85
license_from_fileFunction · 0.85
loadMethod · 0.80
collectFunction · 0.70
getMethod · 0.65
openFunction · 0.50
runMethod · 0.45

Tested by

no test coverage detected