From c8ce0bdd84558de63a685c5a84d875c27b834384 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Thu, 18 Jun 2026 13:59:53 -0700 Subject: [PATCH 1/4] Use authenticated npmrc --- eng/pipelines/templates/install.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/eng/pipelines/templates/install.yml b/eng/pipelines/templates/install.yml index 4b10656b5e..fce4d69f9c 100644 --- a/eng/pipelines/templates/install.yml +++ b/eng/pipelines/templates/install.yml @@ -17,15 +17,27 @@ steps: displayName: Install Node.js retryCountOnTaskFailure: 3 + - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml + parameters: + npmrcPath: $(Agent.TempDirectory)/install/.npmrc + - task: Cache@2 inputs: key: 'pnpm | "$(Agent.OS)" | pnpm-lock.yaml' path: ${{ parameters.pnpmStorePath }} displayName: Cache pnpm store + env: + npm_config_userconfig: "$(Agent.TempDirectory)/install/.npmrc" + - script: npm install -g pnpm # Pnpm manage-package-manager-versions will respect packageManager field displayName: Install pnpm + env: + npm_config_userconfig: "$(Agent.TempDirectory)/install/.npmrc" + - script: pnpm config set store-dir ${{ parameters.pnpmStorePath }} displayName: Setup pnpm cache dir + env: + npm_config_userconfig: "$(Agent.TempDirectory)/install/.npmrc" - script: | echo "Node:" @@ -38,3 +50,5 @@ steps: - script: pnpm install displayName: Install JavaScript Dependencies retryCountOnTaskFailure: 3 + env: + npm_config_userconfig: "$(Agent.TempDirectory)/install/.npmrc" From 17f252c7c969fa6fc0d31af48745160aae87bda8 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 19 Jun 2026 22:56:54 -0700 Subject: [PATCH 2/4] Add create-authenticated-npmrc.yml --- .../steps/create-authenticated-npmrc.yml | 41 +++++++++++++++++++ eng/pipelines/templates/install.yml | 19 ++++----- 2 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml diff --git a/eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml b/eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml new file mode 100644 index 0000000000..3fa699b387 --- /dev/null +++ b/eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml @@ -0,0 +1,41 @@ +parameters: + - name: npmrcPath + type: string + # When empty, defaults to the agent user's .npmrc ($HOME/.npmrc on + # Linux/macOS, %USERPROFILE%\.npmrc on Windows) so every subsequent + # npm / pnpm / npx call in the job inherits the registry + auth. + default: "" + - name: registryUrl + type: string + default: "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js/npm/registry/" + - name: CustomCondition + type: string + default: succeeded() + - name: ServiceConnection + type: string + default: "" + +steps: + - pwsh: | + $npmrcPath = '${{ parameters.npmrcPath }}' + if (-not $npmrcPath) { $npmrcPath = Join-Path $HOME '.npmrc' } + + Write-Host "Creating .npmrc file $npmrcPath for registry ${{ parameters.registryUrl }}" + $parentFolder = Split-Path -Path $npmrcPath -Parent + + if ($parentFolder -and -not (Test-Path $parentFolder)) { + Write-Host "Creating folder $parentFolder" + New-Item -Path $parentFolder -ItemType Directory | Out-Null + } + + "registry=${{ parameters.registryUrl }}" | Out-File $npmrcPath + Write-Host "##vso[task.setvariable variable=resolvedNpmrcPath]$npmrcPath" + displayName: "Create .npmrc" + condition: ${{ parameters.CustomCondition }} + + - task: npmAuthenticate@0 + displayName: Authenticate .npmrc + condition: ${{ parameters.CustomCondition }} + inputs: + workingFile: $(resolvedNpmrcPath) + azureDevOpsServiceConnection: ${{ parameters.ServiceConnection }} diff --git a/eng/pipelines/templates/install.yml b/eng/pipelines/templates/install.yml index fce4d69f9c..ba863ceac0 100644 --- a/eng/pipelines/templates/install.yml +++ b/eng/pipelines/templates/install.yml @@ -18,26 +18,27 @@ steps: retryCountOnTaskFailure: 3 - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml - parameters: - npmrcPath: $(Agent.TempDirectory)/install/.npmrc - task: Cache@2 inputs: key: 'pnpm | "$(Agent.OS)" | pnpm-lock.yaml' path: ${{ parameters.pnpmStorePath }} displayName: Cache pnpm store - env: - npm_config_userconfig: "$(Agent.TempDirectory)/install/.npmrc" - script: npm install -g pnpm # Pnpm manage-package-manager-versions will respect packageManager field displayName: Install pnpm - env: - npm_config_userconfig: "$(Agent.TempDirectory)/install/.npmrc" + + - script: | + node -e " + const fs = require('fs'); + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); + delete pkg.packageManager; + fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)); + " + displayName: Remove packageManager for pipeline - script: pnpm config set store-dir ${{ parameters.pnpmStorePath }} displayName: Setup pnpm cache dir - env: - npm_config_userconfig: "$(Agent.TempDirectory)/install/.npmrc" - script: | echo "Node:" @@ -50,5 +51,3 @@ steps: - script: pnpm install displayName: Install JavaScript Dependencies retryCountOnTaskFailure: 3 - env: - npm_config_userconfig: "$(Agent.TempDirectory)/install/.npmrc" From fc2558fcd05ada29d6c9b94212d9bab2ad00f855 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Wed, 24 Jun 2026 09:24:44 -0700 Subject: [PATCH 3/4] Don't delete package manager --- eng/pipelines/templates/install.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/eng/pipelines/templates/install.yml b/eng/pipelines/templates/install.yml index ba863ceac0..5a12551761 100644 --- a/eng/pipelines/templates/install.yml +++ b/eng/pipelines/templates/install.yml @@ -25,18 +25,9 @@ steps: path: ${{ parameters.pnpmStorePath }} displayName: Cache pnpm store - - script: npm install -g pnpm # Pnpm manage-package-manager-versions will respect packageManager field + - script: npm install -g pnpm@10.30.2 # Pnpm manage-package-manager-versions will respect packageManager field displayName: Install pnpm - - script: | - node -e " - const fs = require('fs'); - const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); - delete pkg.packageManager; - fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)); - " - displayName: Remove packageManager for pipeline - - script: pnpm config set store-dir ${{ parameters.pnpmStorePath }} displayName: Setup pnpm cache dir From 87e44f51157e9b72cb3f37ba477aeda63b66d058 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 29 Jun 2026 14:05:43 -0700 Subject: [PATCH 4/4] User packageManager from packageJson --- eng/pipelines/templates/install.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/templates/install.yml b/eng/pipelines/templates/install.yml index 5a12551761..048335430c 100644 --- a/eng/pipelines/templates/install.yml +++ b/eng/pipelines/templates/install.yml @@ -25,7 +25,9 @@ steps: path: ${{ parameters.pnpmStorePath }} displayName: Cache pnpm store - - script: npm install -g pnpm@10.30.2 # Pnpm manage-package-manager-versions will respect packageManager field + - pwsh: | + $packageJson = Get-Content -Raw "$(Build.SourcesDirectory)/package.json" | ConvertFrom-Json + npm install -g $packageJson.packageManager # Pnpm manage-package-manager-versions will respect packageManager field displayName: Install pnpm - script: pnpm config set store-dir ${{ parameters.pnpmStorePath }}