fix: use @yarnpkg/cli instead of yarn@berry/1.x
yarn@berry and yarn@latest install yarn 1.x, not yarn 4.x. @yarnpkg/cli is the actual yarn 4.x npm package. Also restore yarn 1.x before 'yarn set version stable' on METHOD 4.
This commit is contained in:
1 parent
bdf291466e
commit
e2eb3fa65d
1 file changed
+36
-17
+36
-17
@@ -2232,35 +2232,54 @@ def _build_frontend(src_frontend: Path, dest_frontend: Path):
|
|||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(f" ⚠ 'yarn set version' failed: {e}")
|
print(f" ⚠ 'yarn set version' failed: {e}")
|
||||||
|
|
||||||
# METHOD 3: npm install yarn@berry
|
# METHOD 3: npm install @yarnpkg/cli (yarn 4.x)
|
||||||
try:
|
try:
|
||||||
run(["npm", "install", "-g", "yarn@berry"], check=False)
|
run(["npm", "install", "-g", "@yarnpkg/cli"], check=False)
|
||||||
|
|
||||||
if shutil.which("yarn"):
|
if shutil.which("yarn"):
|
||||||
major = _get_yarn_major_version(["yarn"])
|
major = _get_yarn_major_version(["yarn"])
|
||||||
|
|
||||||
if major and major >= 4:
|
if major and major >= 4:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(f" ✓ Yarn {major}.x installed via npm")
|
print(f" ✓ Yarn {major}.x installed via @yarnpkg/cli")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(f" ⚠ npm install yarn@berry failed: {e}")
|
print(f" ⚠ npm install @yarnpkg/cli failed: {e}")
|
||||||
|
|
||||||
# METHOD 4: Force install latest yarn
|
# METHOD 4: yarn set version stable (requires yarn 1.x)
|
||||||
try:
|
# First install yarn 1.x if not present
|
||||||
run(["npm", "install", "-g", "yarn@latest", "--force"], check=False)
|
if not shutil.which("yarn"):
|
||||||
|
try:
|
||||||
if shutil.which("yarn"):
|
run(["npm", "install", "-g", "yarn@1"], check=False)
|
||||||
major = _get_yarn_major_version(["yarn"])
|
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)
|
||||||
|
|
||||||
if major and major >= 4:
|
# yarn 1.x can upgrade itself to 4.x
|
||||||
if DEBUG:
|
result = subprocess.run(
|
||||||
print(f" ✓ Yarn {major}.x installed via npm --force")
|
["yarn", "set", "version", "stable"],
|
||||||
return True
|
capture_output=True,
|
||||||
except Exception as e:
|
timeout=120,
|
||||||
if DEBUG:
|
text=True,
|
||||||
print(f" ⚠ npm install --force failed: {e}")
|
check=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
if result.returncode == 0:
|
||||||
|
major = _get_yarn_major_version(["yarn"])
|
||||||
|
|
||||||
|
if major and major >= 4:
|
||||||
|
if DEBUG:
|
||||||
|
print(f" ✓ Yarn {major}.x installed via 'yarn set version'")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
if DEBUG:
|
||||||
|
print(f" ⚠ 'yarn set version' failed: {e}")
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user