Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/mono/wasm/sanitize.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import sys, json, os, shutil
import json
import os
import shutil
import sys

Comment thread
radical marked this conversation as resolved.

def glob(path):
return [os.path.join(path, filename) for filename in os.listdir(path)]


Comment thread
radical marked this conversation as resolved.
def remove(*paths):
for path in paths:
path = os.path.abspath(path)
Expand All @@ -14,60 +19,60 @@ def remove(*paths):
except OSError as error:
print(error)


Comment thread
radical marked this conversation as resolved.
def rewrite_package_json(path):
package = open(path,"rb+")
package = open(path, "rb+")
settings = json.load(package)
settings["devDependencies"] = {}
package.seek(0)
package.truncate()
json.dump(settings, package, indent=4)
package.close()


Comment thread
radical marked this conversation as resolved.
emsdk_path = sys.argv[1]
emscripten_path = os.path.join(emsdk_path, "upstream", "emscripten")
node_root = os.path.join(emsdk_path, "node")
node_paths = glob(node_root)
upgrade = False
upgrade = True

npm = os.path.join(node_paths[0], "bin", "npm")
if not os.path.exists(npm):
npm = "npm"
os.environ["PATH"] += os.pathsep + os.path.join(node_paths[0], "bin")

def update_npm(path):
try:
os.chdir(os.path.join(path, "lib"))
os.system(npm + " install npm@latest")
os.system("npm install npm@latest")
prune()
except OSError as error:
print("npm update failed")
print(error)


def remove_npm(path):
os.chdir(path)
remove("bin/npx", "bin/npm", "include", "lib", "share")


def prune():
try:
os.system(npm + " prune --production")
os.system("npm prune --production")
except OSError as error:
print("npm prune failed")
print(error)


Comment thread
radical marked this conversation as resolved.
os.chdir(emscripten_path)
rewrite_package_json("package.json")
prune()

remove("tests",
"node_modules/google-closure-compiler",
"node_modules/google-closure-compiler-java",
"node_modules/google-closure-compiler-osx",
"node_modules/google-closure-compiler-windows",
"node_modules/google-closure-compiler-linux",
remove(
"tests",
"third_party/closure-compiler",
"third_party/jni",
"third_party/ply",
"third_party/uglify-js",
"third_party/websockify")
"third_party/websockify",
)

for path in node_paths:
if upgrade:
Expand Down