Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
pshao25 committed Apr 7, 2023
1 parent 9c056d1 commit fe7d415
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions eng/common/scripts/TypeSpec-Project-Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,40 @@ function NpmInstallAtRoot() {
$replacementPackageJson = &$GetEmitterPackageJsonPathFn
}

$replacementVersion = GetEmitterDependencyVersion $replacementPackageJson
Write-Host "Replacement emitter version: $replacementVersion"

$installedPath = Join-Path $root "node_modules" $emitterName "package.json"
Write-Host "Checking installed emitter at $installedPath"
if (Test-Path $installedPath) {
$installedVersion = GetNpmPackageVersion $installedPath
Write-Host "Installed emitter version: $installedVersion"

$replacementVersion = GetEmitterDependencyVersion $replacementPackageJson
Write-Host "Replacement emitter version: $replacementVersion"

if ($installedVersion -eq $replacementVersion) {
Write-Host "Emitter already installed. Skip installing."
return
}
}

Write-Host "Installing package at $root"
Write-Host "Installing package at"(Get-Location)

if (Test-Path "node_modules") {
Write-Host "Remove existing node_modules at"(Get-Location)
Remove-Item -Path "node_modules" -Force -Recurse
}

npm install "$emitterName@$replacementVersion" --no-lock-file
$hasPackageFile = Test-Path "package.json"

$npmInstallCommand = "npm install --prefix $root $emitterName@$replacementVersion --no-package-lock --omit=dev"
Write-Host($npmInstallCommand)
Invoke-Expression $npmInstallCommand

if ($hasPackageFile) {
git restore package.json
}
else {
rm package.json
}

if ($LASTEXITCODE) { exit $LASTEXITCODE }
}
Expand Down

0 comments on commit fe7d415

Please sign in to comment.