Skip to content

Don't update npm in sanitize.py #1094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all 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
69 changes: 20 additions & 49 deletions eng/sanitize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ def glob(path):
return [os.path.join(path, filename) for filename in os.listdir(path)]


def remove(*paths):
for path in paths:
path = os.path.abspath(path)
try:
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
except OSError as error:
print(error)


def rewrite_package_json(path):
package = open(path, "r+")
settings = json.load(package)
Expand All @@ -31,52 +19,35 @@ def rewrite_package_json(path):
package.close()


emscripten_path = sys.argv[1]
node_root = sys.argv[2]
node_paths = glob(node_root)
upgrade = True

# Add the local node bin directory to the path so that
# npm can find it when doing the updating or pruning
os.environ["PATH"] = os.path.join(node_paths[0], "bin") + os.pathsep + os.environ["PATH"]

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


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


def prune():
def auditfix(path):
try:
os.system("npm prune --production")
os.chdir(path)
os.system("npm audit fix")
except OSError as error:
print("npm prune failed")
print("npm audit fix failed")
print(error)

if upgrade:
for path in node_paths:
update_npm(path)

os.chdir(emscripten_path)
rewrite_package_json("package.json")
try:
os.system("npm audit fix")
except OSError as error:
print("npm audit fix failed")
print(error)
emscripten_path = sys.argv[1]
node_root = sys.argv[2]
node_paths = glob(node_root)

# Add the local node bin directory to the path so that
# npm can find it when doing the updating or pruning
os.environ["PATH"] = os.path.join(node_paths[0], "bin") + os.pathsep + os.environ["PATH"]

prune()
for path in node_paths:
prune(os.path.join(path, "lib"))

if not upgrade:
for path in node_paths:
remove_npm(path)
rewrite_package_json(os.path.join(emscripten_path, "package.json"))
auditfix(emscripten_path)
prune(emscripten_path)
Loading