From 2b92e7b6d612e3901539be23e4dc5cd960dbaed7 Mon Sep 17 00:00:00 2001 From: Sergey Bahmatov Date: Mon, 5 Oct 2026 15:21:57 +0500 Subject: [PATCH] fix: change CWD to /tmp in _ensure_yarn_installed All yarn/npm commands now run from /tmp to completely avoid workspace package.json with patch: entries. Restores original CWD after install. --- npm_install.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/npm_install.py b/npm_install.py index 7cff2bb..06e879f 100644 --- a/npm_install.py +++ b/npm_install.py @@ -2142,6 +2142,10 @@ def _build_frontend(src_frontend: Path, dest_frontend: Path): step_msg = f"Reinstalling Yarn 4.x (attempt {retry_count + 1}/{max_retries + 1})" with step(step_msg): + # Change CWD to /tmp to avoid workspace/package.json issues + original_cwd = os.getcwd() + os.chdir("/tmp") + # Cleanup on retry if retry_count > 0: _cleanup_yarn_artifacts() @@ -2199,10 +2203,11 @@ def _build_frontend(src_frontend: Path, dest_frontend: Path): if shutil.which("yarn"): major = _get_yarn_major_version(["yarn"]) - if major and major >= 4: - if DEBUG: - print(f" ✓ Yarn {major}.x installed via corepack") - return True + if major and major >= 4: + if DEBUG: + print(f" ✓ Yarn {major}.x installed via corepack") + os.chdir(original_cwd) + return True except Exception as e: if DEBUG: print(f" ⚠ Corepack method failed: {e}") @@ -2245,7 +2250,8 @@ def _build_frontend(src_frontend: Path, dest_frontend: Path): if major and major >= 4: if DEBUG: - print(f" ✓ Yarn {major}.x installed via @yarnpkg/cli") + print(f" ✓ Yarn {major}.x installed via 'yarn set version'") + os.chdir(original_cwd) return True except Exception as e: if DEBUG: @@ -2297,6 +2303,7 @@ def _build_frontend(src_frontend: Path, dest_frontend: Path): if DEBUG: print(f" ⚠ 'yarn set version' failed: {e}") + os.chdir(original_cwd) return False # Main logic: Find or install Yarn 4.x