diff --git a/.gitea/workflows/desktop.yml b/.gitea/workflows/desktop.yml index c5bfcfa..fda18f4 100644 --- a/.gitea/workflows/desktop.yml +++ b/.gitea/workflows/desktop.yml @@ -223,85 +223,120 @@ jobs: run: | $ErrorActionPreference = "Stop" - Set-Location fluxer-src + Set-Location "fluxer-src\fluxer_desktop" - $PnpmRoot = "node_modules\.pnpm" + $LiveKitPath = Join-Path ` + (Get-Location) ` + "node_modules\livekit-client" - if (-not (Test-Path $PnpmRoot)) { - throw "pnpm node_modules directory not found" - } + if (-not (Test-Path $LiveKitPath)) { + $Entry = ( + node -e "process.stdout.write(require.resolve('livekit-client'))" + ).Trim() - $LiveKitPackages = Get-ChildItem ` - -Path $PnpmRoot ` - -Directory ` - -Filter "livekit-client@*" | - ForEach-Object { - Join-Path $_.FullName "node_modules\livekit-client" - } | - Where-Object { - Test-Path $_ + if (-not $Entry) { + throw "Unable to resolve livekit-client" } - if (-not $LiveKitPackages) { - throw "livekit-client package not found" + $Dir = Split-Path $Entry -Parent + + while ($Dir) { + $PackageJson = Join-Path $Dir "package.json" + + if (Test-Path $PackageJson) { + $PackageInfo = Get-Content ` + $PackageJson ` + -Raw | + ConvertFrom-Json + + if ($PackageInfo.name -eq "livekit-client") { + $LiveKitPath = $Dir + break + } + } + + $Parent = Split-Path $Dir -Parent + + if ( + -not $Parent -or + $Parent -eq $Dir + ) { + break + } + + $Dir = $Parent + } + } + + if (-not (Test-Path $LiveKitPath)) { + throw "livekit-client package directory not found" + } + + $LiveKitPath = ( + Resolve-Path $LiveKitPath + ).Path + + Write-Host "LiveKit package: $LiveKitPath" + + $PackageJson = Join-Path ` + $LiveKitPath ` + "package.json" + + if (Test-Path $PackageJson) { + $PackageInfo = Get-Content ` + $PackageJson ` + -Raw | + ConvertFrom-Json + + Write-Host ` + "livekit-client version: $($PackageInfo.version)" } $Pattern = "(iceTransportPolicy\s*=\s*['""])(relay)(['""])" $TotalReplacements = 0 - foreach ($PackagePath in $LiveKitPackages) { - Write-Host "Patching LiveKit package: $PackagePath" - - $PackageJson = Join-Path $PackagePath "package.json" - - if (Test-Path $PackageJson) { - $PackageInfo = Get-Content $PackageJson -Raw | - ConvertFrom-Json - - Write-Host "livekit-client version: $($PackageInfo.version)" - } - - $Files = Get-ChildItem ` - -Path $PackagePath ` - -Recurse ` - -File | - Where-Object { - $_.Extension -in @( - ".ts", - ".js", - ".mjs", - ".cjs" - ) - } - - foreach ($File in $Files) { - $Content = Get-Content $File.FullName -Raw - $Count = [regex]::Matches( - $Content, - $Pattern - ).Count - - if ($Count -eq 0) { - continue - } - - $PatchedContent = [regex]::Replace( - $Content, - $Pattern, - '$1all$3' + $Files = Get-ChildItem ` + -Path $LiveKitPath ` + -Recurse ` + -File | + Where-Object { + $_.Extension -in @( + ".js", + ".mjs", + ".cjs" ) - - Set-Content ` - -Path $File.FullName ` - -Value $PatchedContent ` - -NoNewline ` - -Encoding utf8 - - $TotalReplacements += $Count - - Write-Host ` - "Patched $Count occurrence(s): $($File.FullName)" } + + foreach ($File in $Files) { + $Content = Get-Content ` + $File.FullName ` + -Raw + + $Count = [regex]::Matches( + $Content, + $Pattern + ).Count + + if ($Count -eq 0) { + continue + } + + $PatchedContent = [regex]::Replace( + $Content, + $Pattern, + '$1all$3' + ) + + Set-Content ` + -Path $File.FullName ` + -Value $PatchedContent ` + -NoNewline ` + -Encoding utf8 + + $TotalReplacements += $Count + + Write-Host ` + "Patched $Count occurrence(s): $($File.FullName)" } if ($TotalReplacements -lt 1) { @@ -799,33 +834,102 @@ jobs: run: | set -euxo pipefail - cd fluxer-src + cd fluxer-src/fluxer_desktop + + LIVEKIT_DIR="node_modules/livekit-client" + + if [ ! -d "${LIVEKIT_DIR}" ]; then + LIVEKIT_ENTRY="$( + node -e \ + "process.stdout.write(require.resolve('livekit-client'))" + )" + + export LIVEKIT_ENTRY + + LIVEKIT_DIR="$( + python3 <<'PY' + from pathlib import Path + import json + import os + + entry = Path( + os.environ["LIVEKIT_ENTRY"] + ).resolve() + + for directory in [ + entry.parent, + *entry.parents, + ]: + package_json = ( + directory / "package.json" + ) + + if not package_json.is_file(): + continue + + try: + package = json.loads( + package_json.read_text( + encoding="utf-8" + ) + ) + except Exception: + continue + + if ( + package.get("name") + == "livekit-client" + ): + print(directory) + break + else: + raise SystemExit( + "Unable to locate " + "livekit-client package directory" + ) + PY + )" + fi + + LIVEKIT_DIR="$( + readlink -f "${LIVEKIT_DIR}" + )" + + test -d "${LIVEKIT_DIR}" + + export LIVEKIT_DIR python3 <<'PY' from pathlib import Path import json + import os import re - pnpm_root = Path("node_modules/.pnpm") - - if not pnpm_root.is_dir(): - raise SystemExit( - "pnpm node_modules directory not found" - ) - - packages = sorted( - path / "node_modules/livekit-client" - for path in pnpm_root.glob( - "livekit-client@*" - ) - if ( - path / "node_modules/livekit-client" - ).is_dir() + package = Path( + os.environ["LIVEKIT_DIR"] ) - if not packages: - raise SystemExit( - "livekit-client package not found" + print( + f"LiveKit package: {package}" + ) + + package_json = ( + package / "package.json" + ) + + if package_json.is_file(): + package_info = json.loads( + package_json.read_text( + encoding="utf-8" + ) + ) + + print( + "livekit-client version:", + package_info.get( + "version", + "unknown", + ), ) pattern = re.compile( @@ -836,67 +940,42 @@ jobs: total_replacements = 0 - for package in packages: + for path in package.rglob("*"): + if ( + not path.is_file() + or path.suffix + not in { + ".js", + ".mjs", + ".cjs", + } + ): + continue + + data = path.read_text( + encoding="utf-8" + ) + + patched, count = pattern.subn( + r"\1all\2", + data, + ) + + if count == 0: + continue + + path.write_text( + patched, + encoding="utf-8", + ) + + total_replacements += count + print( - f"Patching LiveKit package: {package}" + f"Patched {count} occurrence(s): " + f"{path}" ) - package_json = ( - package / "package.json" - ) - - if package_json.is_file(): - package_info = json.loads( - package_json.read_text( - encoding="utf-8" - ) - ) - - print( - "livekit-client version:", - package_info.get( - "version", - "unknown", - ), - ) - - for path in package.rglob("*"): - if ( - not path.is_file() - or path.suffix - not in { - ".ts", - ".js", - ".mjs", - ".cjs", - } - ): - continue - - data = path.read_text( - encoding="utf-8" - ) - - patched, count = pattern.subn( - r"\1all\2", - data, - ) - - if count == 0: - continue - - path.write_text( - patched, - encoding="utf-8", - ) - - total_replacements += count - - print( - f"Patched {count} occurrence(s): " - f"{path}" - ) - if total_replacements < 1: raise SystemExit( "LiveKit relay ICE policy "