From fe7d415f1e7732ddba70d4e64cfc5df4c65ab28f Mon Sep 17 00:00:00 2001 From: pshao25 <97225342+pshao25@users.noreply.github.com> Date: Fri, 7 Apr 2023 12:47:29 +0800 Subject: [PATCH] Update --- .../scripts/TypeSpec-Project-Generate.ps1 | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/eng/common/scripts/TypeSpec-Project-Generate.ps1 b/eng/common/scripts/TypeSpec-Project-Generate.ps1 index 3638202e4a2..839e0c6182f 100644 --- a/eng/common/scripts/TypeSpec-Project-Generate.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Generate.ps1 @@ -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 } }