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