From b858596fd6b9b22e0c7821668b99b30b112bc393 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 19:51:41 +0000 Subject: [PATCH 1/4] Initial plan From 940ca47d2381b196ced94431eeca8c00578c404c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 19:57:43 +0000 Subject: [PATCH 2/4] Fix: Don't change working directory when invoking tsp-client Replace Push-Location/Pop-Location with npm --prefix option to avoid changing the working directory before invoking tsp-client. This fixes the issue where tsp-client makes assumptions based on the working directory. Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> --- eng/scripts/Invoke-GenerateAndBuildV2.ps1 | 30 +++++++++-------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/eng/scripts/Invoke-GenerateAndBuildV2.ps1 b/eng/scripts/Invoke-GenerateAndBuildV2.ps1 index 18327d0c7e4e..2f95777ee78d 100644 --- a/eng/scripts/Invoke-GenerateAndBuildV2.ps1 +++ b/eng/scripts/Invoke-GenerateAndBuildV2.ps1 @@ -132,26 +132,20 @@ if ($relatedTypeSpecProjectFolder) { # Install tsp-client dependencies from eng/common/tsp-client $tspClientDir = Resolve-Path (Join-Path $PSScriptRoot "../common/tsp-client") - Push-Location $tspClientDir - try { - Write-Host "Installing tsp-client dependencies from $tspClientDir" - npm ci - if ($LASTEXITCODE) { - Write-Error "Failed to install tsp-client dependencies" - exit $LASTEXITCODE - } - - # Use tsp-client from pinned version by running from tsp-client directory - $tspclientCommand = "npm exec --no -- tsp-client init --update-if-exists --tsp-config $tspConfigFile --repo $repo --commit $commitid" - if ($swaggerDir) { - $tspclientCommand += " --local-spec-repo $typespecFolder" - } - Write-Host $tspclientCommand - Invoke-Expression $tspclientCommand + Write-Host "Installing tsp-client dependencies from $tspClientDir" + npm ci --prefix $tspClientDir + if ($LASTEXITCODE) { + Write-Error "Failed to install tsp-client dependencies" + exit $LASTEXITCODE } - finally { - Pop-Location + + # Use tsp-client from pinned version by passing --prefix to use tsp-client from that directory + $tspclientCommand = "npm exec --prefix $tspClientDir --no -- tsp-client init --update-if-exists --tsp-config $tspConfigFile --repo $repo --commit $commitid" + if ($swaggerDir) { + $tspclientCommand += " --local-spec-repo $typespecFolder" } + Write-Host $tspclientCommand + Invoke-Expression $tspclientCommand if ($LASTEXITCODE) { # If Process script call fails, then return with failure to CI and don't need to call GeneratePackage From 01ad6c93151647f87bc9b6bc15e2e918944beedb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 20:10:52 +0000 Subject: [PATCH 3/4] Use full path to tsp-client binary instead of npm exec Keep Push-Location for npm ci as required, but execute tsp-client using the full path to the binary. This ensures npm ci runs from the correct directory while tsp-client executes from the current working directory. Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> --- eng/scripts/Invoke-GenerateAndBuildV2.ps1 | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/eng/scripts/Invoke-GenerateAndBuildV2.ps1 b/eng/scripts/Invoke-GenerateAndBuildV2.ps1 index 2f95777ee78d..3082defa7994 100644 --- a/eng/scripts/Invoke-GenerateAndBuildV2.ps1 +++ b/eng/scripts/Invoke-GenerateAndBuildV2.ps1 @@ -132,15 +132,22 @@ if ($relatedTypeSpecProjectFolder) { # Install tsp-client dependencies from eng/common/tsp-client $tspClientDir = Resolve-Path (Join-Path $PSScriptRoot "../common/tsp-client") - Write-Host "Installing tsp-client dependencies from $tspClientDir" - npm ci --prefix $tspClientDir - if ($LASTEXITCODE) { - Write-Error "Failed to install tsp-client dependencies" - exit $LASTEXITCODE + Push-Location $tspClientDir + try { + Write-Host "Installing tsp-client dependencies from $tspClientDir" + npm ci + if ($LASTEXITCODE) { + Write-Error "Failed to install tsp-client dependencies" + exit $LASTEXITCODE + } + } + finally { + Pop-Location } - # Use tsp-client from pinned version by passing --prefix to use tsp-client from that directory - $tspclientCommand = "npm exec --prefix $tspClientDir --no -- tsp-client init --update-if-exists --tsp-config $tspConfigFile --repo $repo --commit $commitid" + # Use tsp-client from pinned version by using the full path to the binary + $tspClientBin = Join-Path $tspClientDir "node_modules" ".bin" "tsp-client" + $tspclientCommand = "$tspClientBin init --update-if-exists --tsp-config $tspConfigFile --repo $repo --commit $commitid" if ($swaggerDir) { $tspclientCommand += " --local-spec-repo $typespecFolder" } From f5243ee9040043b031dc08b0ad38d0e54a2e506c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 20:16:35 +0000 Subject: [PATCH 4/4] Use npm exec --prefix to invoke tsp-client Keep Push-Location/Pop-Location for npm ci, then use npm exec --prefix to invoke tsp-client from the current working directory while using the pinned version from tsp-client directory. Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> --- eng/scripts/Invoke-GenerateAndBuildV2.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eng/scripts/Invoke-GenerateAndBuildV2.ps1 b/eng/scripts/Invoke-GenerateAndBuildV2.ps1 index 3082defa7994..bca153638fa3 100644 --- a/eng/scripts/Invoke-GenerateAndBuildV2.ps1 +++ b/eng/scripts/Invoke-GenerateAndBuildV2.ps1 @@ -145,9 +145,8 @@ if ($relatedTypeSpecProjectFolder) { Pop-Location } - # Use tsp-client from pinned version by using the full path to the binary - $tspClientBin = Join-Path $tspClientDir "node_modules" ".bin" "tsp-client" - $tspclientCommand = "$tspClientBin init --update-if-exists --tsp-config $tspConfigFile --repo $repo --commit $commitid" + # Use tsp-client from pinned version by passing --prefix to use tsp-client from that directory + $tspclientCommand = "npm exec --prefix $tspClientDir --no -- tsp-client init --update-if-exists --tsp-config $tspConfigFile --repo $repo --commit $commitid" if ($swaggerDir) { $tspclientCommand += " --local-spec-repo $typespecFolder" }