@@ -64,43 +64,48 @@ try {
6464 }
6565}
6666
67- # Create pak lockfile from project dependencies (only if it doesn't exist)
67+ # Create temporary pak lockfile to scan project dependencies
68+ Write-Host "🔧 Scanning project for R package dependencies..." -ForegroundColor Cyan
6869$pkgLockPath = Join-Path $projectRoot "pkg.lock"
69- if (-not (Test-Path $pkgLockPath)) {
70- Write-Host "🔧 Creating pak lockfile from project dependencies..." -ForegroundColor Cyan
71- try {
72- Rscript -e "setwd('$projectRoot'); pak::lockfile_create()"
73- if ($LASTEXITCODE -eq 0) {
74- Write-Host "✅ Pak lockfile created successfully" -ForegroundColor Green
75- } else {
76- throw "Creation failed"
77- }
78- } catch {
79- Write-Host "❌ Error: Failed to create pak lockfile" -ForegroundColor Red
80- exit 2
81- }
82- } else {
83- Write-Host "ℹ️ Pak lockfile already exists, skipping creation" -ForegroundColor Blue
84- }
8570
86- # Install packages from lockfile
87- if (Test-Path $pkgLockPath) {
88- Write-Host "📦 Installing packages from pak lockfile..." -ForegroundColor Cyan
71+ try {
72+ Rscript -e "setwd('$projectRoot'); pak::lockfile_create(lockfile = 'pkg.lock')"
73+ if ($LASTEXITCODE -eq 0) {
74+ Write-Host "✅ Project dependencies scanned successfully" -ForegroundColor Green
8975
90- try {
91- Rscript -e "setwd('$projectRoot'); pak::lockfile_install(lockfile = 'pkg.lock')"
92- if ($LASTEXITCODE -eq 0) {
93- Write-Host "✅ Packages installed successfully from pak lockfile" -ForegroundColor Green
94- } else {
95- throw "Installation failed"
76+ # Install packages from temporary lockfile
77+ Write-Host "📦 Installing packages from scanned dependencies..." -ForegroundColor Cyan
78+ try {
79+ Rscript -e "setwd('$projectRoot'); pak::lockfile_install(lockfile = 'pkg.lock')"
80+ if ($LASTEXITCODE -eq 0) {
81+ Write-Host "✅ Packages installed successfully" -ForegroundColor Green
82+ } else {
83+ throw "Installation failed"
84+ }
85+ } catch {
86+ Write-Host "❌ Error: Failed to install packages" -ForegroundColor Red
87+ # Clean up lockfile even on failure
88+ if (Test-Path $pkgLockPath) {
89+ Remove-Item $pkgLockPath -Force
90+ }
91+ exit 2
9692 }
97- } catch {
98- Write-Host "❌ Error: Failed to install packages from pak lockfile" -ForegroundColor Red
99- Write-Host "Please check the pkg.lock file and try again" -ForegroundColor Yellow
100- exit 2
93+
94+ # Clean up temporary lockfile
95+ Write-Host "🧹 Cleaning up temporary lockfile..." -ForegroundColor Cyan
96+ if (Test-Path $pkgLockPath) {
97+ Remove-Item $pkgLockPath -Force
98+ Write-Host "✅ Temporary lockfile removed" -ForegroundColor Green
99+ }
100+ } else {
101+ throw "Scan failed"
102+ }
103+ } catch {
104+ Write-Host "❌ Error: Failed to scan project dependencies" -ForegroundColor Red
105+ # Clean up lockfile if it was partially created
106+ if (Test-Path $pkgLockPath) {
107+ Remove-Item $pkgLockPath -Force
101108 }
102- } else {
103- Write-Host "❌ Error: Pak lockfile was not created" -ForegroundColor Red
104109 exit 2
105110}
106111
0 commit comments