remove bash -lc
This commit is contained in:
@@ -584,43 +584,41 @@ def install_node_and_yarn(node_pkg: str):
|
||||
os.symlink("/usr/bin/yarnpkg","/usr/bin/yarn")
|
||||
|
||||
def _build_frontend(src_frontend: Path, dest_frontend: Path):
|
||||
def _which(cmd: str) -> bool:
|
||||
import shutil as _s
|
||||
return _s.which(cmd) is not None
|
||||
|
||||
def _semver(s: str) -> bool:
|
||||
return bool(re.match(r"^\d+(?:\.\d+){1,3}$", (s or "").strip()))
|
||||
|
||||
def _good_yarn(cmd: str) -> bool:
|
||||
out = (run_out([cmd, "--version"], check=False) or "").strip()
|
||||
return bool(re.match(r"^\d+(?:\.\d+){1,3}$", out))
|
||||
v = (run_out([cmd, "--version"], check=False) or "").strip()
|
||||
return _semver(v)
|
||||
|
||||
yarn = None
|
||||
for cand in ("yarn", "yarnpkg"):
|
||||
if _which(cand) and _good_yarn(cand):
|
||||
yarn = cand
|
||||
break
|
||||
if not yarn:
|
||||
run(["corepack", "enable"], check=False)
|
||||
run(["corepack", "prepare", "yarn@stable", "--activate"], check=False)
|
||||
for cand in ("yarn", "yarnpkg"):
|
||||
if _which(cand) and _good_yarn(cand):
|
||||
yarn = cand
|
||||
break
|
||||
if not yarn:
|
||||
yarn_cmd = None
|
||||
if shutil.which("yarn") and _good_yarn("yarn"):
|
||||
yarn_cmd = ["yarn"]
|
||||
elif shutil.which("yarnpkg") and _good_yarn("yarnpkg"):
|
||||
yarn_cmd = ["yarnpkg"]
|
||||
elif shutil.which("npm"):
|
||||
if (run_out(["npm", "--version"], check=False) or "").strip():
|
||||
yarn_cmd = ["npm", "exec", "--yes", "yarn@stable"]
|
||||
if not yarn_cmd:
|
||||
raise RuntimeError("No yarn in system")
|
||||
|
||||
with step("Installing frontend dependencies (yarn)"):
|
||||
os.environ["NODE_ENV"] = "development"
|
||||
os.chdir(src_frontend)
|
||||
cache_dir = (run_out([yarn, "cache", "dir"], check=False) or "").strip()
|
||||
|
||||
cache_dir = (run_out(yarn_cmd + ["cache", "dir"], check=False) or "").strip()
|
||||
if cache_dir and not Path(cache_dir).exists():
|
||||
Path(cache_dir).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
run([yarn, "cache", "clean"], check=False)
|
||||
run([yarn, "install"])
|
||||
run(yarn_cmd + ["cache", "clean"], check=False)
|
||||
|
||||
run(yarn_cmd + ["install"])
|
||||
|
||||
with step("Building frontend (yarn build)"):
|
||||
env = os.environ.copy()
|
||||
env["NODE_OPTIONS"] = "--openssl-legacy-provider"
|
||||
run([yarn, "build"], env=env)
|
||||
run(yarn_cmd + ["build"], env=env)
|
||||
|
||||
with step("Copying frontend artifacts"):
|
||||
shutil.copytree(src_frontend / "dist", dest_frontend, dirs_exist_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user