2020-06-11 00:54:34 +02:00
|
|
|
import os
|
2016-08-18 13:51:25 +02:00
|
|
|
|
2023-03-31 00:31:05 +02:00
|
|
|
from scripts.lib.zulip_tools import 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
|
|
|
|
2024-06-25 19:21:45 +02:00
|
|
|
skip = False
|
|
|
|
|
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():
|
2024-06-25 19:21:45 +02:00
|
|
|
skip = True
|
2023-03-20 19:52:59 +01:00
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
2017-07-27 23:22:52 +02:00
|
|
|
|
2024-06-25 19:21:45 +02:00
|
|
|
# We need this check when switching between branches without `help-beta`
|
|
|
|
# package. `node_modules` will be removed when working on a non `help-beta`
|
|
|
|
# branch, but if `node_modules/.pnpm/lock.yaml` has not been updated by that
|
|
|
|
# branch, we will end up in a situation where we might not have `node_modules`
|
|
|
|
# even when we run the provision command.
|
|
|
|
if not os.path.exists("help-beta/node_modules"):
|
|
|
|
skip = False
|
|
|
|
|
|
|
|
if not skip:
|
|
|
|
run(
|
|
|
|
[
|
|
|
|
"/usr/local/bin/corepack",
|
|
|
|
"pnpm",
|
|
|
|
"install",
|
|
|
|
"--frozen-lockfile",
|
|
|
|
"--prefer-offline",
|
|
|
|
*(["--prod"] if production else []),
|
|
|
|
]
|
|
|
|
)
|