From c37af244dc574d9a8a42fb22ac2b297b29324541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Fri, 24 Oct 2025 09:40:14 +0200 Subject: [PATCH] remove bash -lc --- npm_install.py | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/npm_install.py b/npm_install.py index 309206e..ecf8893 100644 --- a/npm_install.py +++ b/npm_install.py @@ -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)