2020-06-11 00:54:34 +02:00
|
|
|
import os
|
2016-08-18 13:51:25 +02:00
|
|
|
|
2023-03-22 02:34:50 +01:00
|
|
|
from scripts.lib.zulip_tools import get_deploy_root, run
|
2016-08-18 13:51:25 +02:00
|
|
|
|
2017-07-28 00:18:23 +02:00
|
|
|
DEFAULT_PRODUCTION = False
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2023-03-20 19:52:59 +01:00
|
|
|
def setup_node_modules(production: bool = DEFAULT_PRODUCTION) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
if os.path.islink("node_modules"):
|
2023-03-20 19:52:59 +01:00
|
|
|
os.unlink("node_modules")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2023-03-20 19:52:59 +01:00
|
|
|
try:
|
|
|
|
with open("node_modules/.pnpm/lock.yaml") as a, open("pnpm-lock.yaml") as b:
|
|
|
|
if a.read() == b.read():
|
|
|
|
return
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
2017-07-27 23:22:52 +02:00
|
|
|
|
2023-03-22 02:34:50 +01:00
|
|
|
pnpm_command = ["/usr/local/bin/pnpm", "install", "--frozen-lockfile"]
|
|
|
|
if production:
|
|
|
|
pnpm_command += ["--prod"]
|
|
|
|
|
|
|
|
deploy_root = get_deploy_root()
|
|
|
|
with open("/proc/self/mounts") as mounts:
|
|
|
|
for line in mounts:
|
|
|
|
fields = line.split()
|
|
|
|
if fields[1] == deploy_root and fields[2] in ("fuse.grpcfuse", "fakeowner"):
|
|
|
|
print("Working around https://github.com/pnpm/pnpm/issues/5803")
|
|
|
|
pnpm_command += ["--package-import-method=copy"]
|
|
|
|
|
|
|
|
run(pnpm_command)
|