Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions eng/common/pipelines/templates/jobs/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reset-npmrc step now runs even when SkipPublishing is set to true (e.g., when no packages are found and publishing is skipped). Previously the registry-change step was conditioned on ne(variables['SkipPublishing'], 'true'). Consider applying the same condition to this template call (or adding a CustomCondition parameter to the template) so the job doesn’t mutate npm config unnecessarily when publishing is skipped.

Suggested change
- template: /eng/common/pipelines/templates/steps/reset-npmrc.yml
- template: /eng/common/pipelines/templates/steps/reset-npmrc.yml
condition: and(succeeded(), ne(variables['SkipPublishing'], 'true'))

Copilot uses AI. Check for mistakes.
parameters:
Registry: ${{ parameters.Registry }}

- task: EsrpRelease@9
displayName: 'Publish ${{ parameters.ArtifactName }} via ESRP'
Expand Down
32 changes: 32 additions & 0 deletions eng/common/pipelines/templates/steps/reset-npmrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
parameters:
Registry: 'https://registry.npmjs.org/'

steps:
- task: PowerShell@2
displayName: 'Set project npm registry'
inputs:
targetType: inline
Comment on lines +3 to +8
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This template uses npm config ... --location=project, which writes to the .npmrc in the current working directory. Since the task doesn’t set workingDirectory, the update could end up in an unexpected folder (and not affect later npm commands that run elsewhere). Consider adding a WorkingDirectory parameter (or otherwise setting workingDirectory on the PowerShell task) so the project .npmrc is updated deterministically.

Suggested change
steps:
- task: PowerShell@2
displayName: 'Set project npm registry'
inputs:
targetType: inline
WorkingDirectory: '$(System.DefaultWorkingDirectory)'
steps:
- task: PowerShell@2
displayName: 'Set project npm registry'
inputs:
targetType: inline
workingDirectory: ${{ parameters.WorkingDirectory }}

Copilot uses AI. Check for mistakes.
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:"
$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