fix: run yarn install from /tmp to avoid patch: protocol error
npm reads workspace package.json when run from source directory. The frontend package.json contains patch: entries (Yarn 4.x PnP) that npm can't understand. Run from /tmp instead. Also fix 'run() got an unexpected keyword argument stdout' by using subprocess.run() directly for npm uninstall/cache clean.
This commit is contained in:
1 parent
e2eb3fa65d
commit
6d4c69ff16
1 file changed
+7
-9
+7
-9
@@ -2148,15 +2148,13 @@ def _build_frontend(src_frontend: Path, dest_frontend: Path):
|
||||
|
||||
# Uninstall old Yarn 1.x
|
||||
try:
|
||||
run(["npm", "uninstall", "-g", "yarn"], check=False,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
subprocess.run(["npm", "uninstall", "-g", "yarn"], check=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Clear cache
|
||||
try:
|
||||
run(["npm", "cache", "clean", "--force"], check=False,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
subprocess.run(["npm", "cache", "clean", "--force"], check=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -2232,9 +2230,9 @@ def _build_frontend(src_frontend: Path, dest_frontend: Path):
|
||||
if DEBUG:
|
||||
print(f" ⚠ 'yarn set version' failed: {e}")
|
||||
|
||||
# METHOD 3: npm install @yarnpkg/cli (yarn 4.x)
|
||||
# METHOD 3: npm install @yarnpkg/cli (yarn 4.x) — run from /tmp to avoid reading workspace package.json with patch: entries
|
||||
try:
|
||||
run(["npm", "install", "-g", "@yarnpkg/cli"], check=False)
|
||||
subprocess.run(["npm", "install", "-g", "@yarnpkg/cli"], check=False, cwd="/tmp")
|
||||
|
||||
if shutil.which("yarn"):
|
||||
major = _get_yarn_major_version(["yarn"])
|
||||
@@ -2251,15 +2249,14 @@ def _build_frontend(src_frontend: Path, dest_frontend: Path):
|
||||
# First install yarn 1.x if not present
|
||||
if not shutil.which("yarn"):
|
||||
try:
|
||||
run(["npm", "install", "-g", "yarn@1"], check=False)
|
||||
subprocess.run(["npm", "install", "-g", "yarn@1"], check=False, cwd="/tmp")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if shutil.which("yarn"):
|
||||
try:
|
||||
# Uninstall any global yarn 4.x first
|
||||
run(["npm", "uninstall", "-g", "@yarnpkg/cli"], check=False,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
subprocess.run(["npm", "uninstall", "-g", "@yarnpkg/cli"], check=False, cwd="/tmp")
|
||||
|
||||
# yarn 1.x can upgrade itself to 4.x
|
||||
result = subprocess.run(
|
||||
@@ -2267,6 +2264,7 @@ def _build_frontend(src_frontend: Path, dest_frontend: Path):
|
||||
capture_output=True,
|
||||
timeout=120,
|
||||
text=True,
|
||||
cwd="/tmp",
|
||||
check=False,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user