Skip to content

Instantly share code, notes, and snippets.

@rinsuki
Last active October 19, 2019 03:18
Show Gist options
  • Save rinsuki/45362663b7ed8fd56f75d86b8403a943 to your computer and use it in GitHub Desktop.
Save rinsuki/45362663b7ed8fd56f75d86b8403a943 to your computer and use it in GitHub Desktop.
import json
f = json.load(open("package.json", "r"))
packages = open("packages.txt", "r")
def sorted_dict(input):
r = sorted(input.items(), key=lambda x:x)
d = {}
for k, v in r:
d[k] = v
return d
for p in packages.readlines():
p = p.strip()
if f["dependencies"].get(p) == None:
print(p)
if f["devDependencies"].get(p) != None:
f["dependencies"][p] = f["devDependencies"][p]
del f["devDependencies"][p]
else:
print("WARN!! " + p +" is used in built/**/*.js, but not found on devDependencies")
f["dependencies"] = sorted_dict(f["dependencies"])
f["devDependencies"] = sorted_dict(f["devDependencies"])
json.dump(f, open("package.json", "w"), indent=2)
#!/bin/zsh
python3 search.py | sort | uniq > packages.txt
import re
import os
import glob
r = re.compile(r"require\(['\"]([@a-zA-Z0-9\-/]+)['\"]\)")
for file in glob.glob('built/**/*.js', recursive = True):
if "client/assets" in file:
continue
s = open(file, "r").read()
for g in r.finditer(s):
print(g.group(1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment