From 29bb07659b33c42231e1477db133070c4bf5b131 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Wed, 4 Mar 2026 16:36:39 -0800 Subject: [PATCH 1/2] Add setting the registry in the npmrc --- .../pipelines/templates/jobs/npm-publish.yml | 17 +++-------------- .../pipelines/templates/steps/reset-npmrc.yml | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 eng/common/pipelines/templates/steps/reset-npmrc.yml diff --git a/eng/common/pipelines/templates/jobs/npm-publish.yml b/eng/common/pipelines/templates/jobs/npm-publish.yml index 74d733744c9d..e435a213c9eb 100644 --- a/eng/common/pipelines/templates/jobs/npm-publish.yml +++ b/eng/common/pipelines/templates/jobs/npm-publish.yml @@ -70,20 +70,9 @@ jobs: - ${{ if eq(parameters.Registry, 'https://registry.npmjs.org/') }}: - - task: PowerShell@2 - displayName: 'Delete repo .npmrc' - condition: and(succeeded(), ne(variables['SkipPublishing'], 'true')) - inputs: - targetType: inline - script: | - $npmrcPath = "$(System.DefaultWorkingDirectory)/.npmrc" - if (Test-Path $npmrcPath) { - Remove-Item -Path $npmrcPath -Force - Write-Host "Deleted $npmrcPath to use default npmjs registry." - } else { - Write-Host "No repo .npmrc found at $npmrcPath." - } - pwsh: true + - template: /eng/common/pipelines/templates/steps/reset-npmrc.yml + parameters: + Registry: ${{ parameters.Registry }} - task: EsrpRelease@9 displayName: 'Publish ${{ parameters.ArtifactName }} via ESRP' diff --git a/eng/common/pipelines/templates/steps/reset-npmrc.yml b/eng/common/pipelines/templates/steps/reset-npmrc.yml new file mode 100644 index 000000000000..7abac5fdda67 --- /dev/null +++ b/eng/common/pipelines/templates/steps/reset-npmrc.yml @@ -0,0 +1,17 @@ +parameters: + Registry: 'https://registry.npmjs.org/' + +steps: + - task: PowerShell@2 + displayName: 'Set project npm registry' + inputs: + targetType: inline + script: | + Write-Host "Registry before update:" + npm config get registry --location=project + + npm config set registry "${{ parameters.Registry }}" --location=project + + Write-Host "Registry after update:" + npm config get registry --location=project + pwsh: true From 1204f276e9ac9b3b6dc1615503421eceaadec956 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Wed, 4 Mar 2026 17:06:10 -0800 Subject: [PATCH 2/2] Check for errors --- .../pipelines/templates/steps/reset-npmrc.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/reset-npmrc.yml b/eng/common/pipelines/templates/steps/reset-npmrc.yml index 7abac5fdda67..45977de6def3 100644 --- a/eng/common/pipelines/templates/steps/reset-npmrc.yml +++ b/eng/common/pipelines/templates/steps/reset-npmrc.yml @@ -7,11 +7,26 @@ steps: inputs: targetType: inline script: | + $ErrorActionPreference = 'Stop' + Write-Host "Registry before update:" npm config get registry --location=project + if ($LASTEXITCODE -ne 0) { + throw "Failed to read current project npm registry." + } npm config set registry "${{ parameters.Registry }}" --location=project + if ($LASTEXITCODE -ne 0) { + throw "Failed to set project npm registry to '${{ parameters.Registry }}'." + } Write-Host "Registry after update:" - npm config get registry --location=project + $updatedRegistry = npm config get registry --location=project + if ($LASTEXITCODE -ne 0) { + throw "Failed to read updated project npm registry." + } + + if ($updatedRegistry.Trim() -ne "${{ parameters.Registry }}") { + throw "Project npm registry mismatch. Expected '${{ parameters.Registry }}' but got '$updatedRegistry'." + } pwsh: true