Skip to content

Commit 14edf91

Browse files
authored
Add .npmrc next to package.json and add lockfile for PublishAIEvaluationReport (#7108)
* Add .npmrc next to package.json The .npmrc is not transitively looked up in parent directories like other config files, it needs to be next to the package.json Also remove the always-auth entry since it is deprecated/unused in npm and will be removed: actions/setup-node#1305 * Don't run npm install in CI, it should only be run locally by an authenticated developer * Update vulnerable npm packages * Make sure we're using AzDO feed in package-lock.json * Add UpdateNpmDependencies.ps1 script
1 parent fabf857 commit 14edf91

File tree

13 files changed

+1142
-668
lines changed

13 files changed

+1142
-668
lines changed

.npmrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
registry=https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/
2-
always-auth=true

scripts/UpdateNpmDependencies.ps1

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This script needs to be run on PowerShell 7+ (for ConvertFrom-Json) in the directory of the project
2+
3+
param (
4+
[switch]$WhatIf
5+
)
6+
7+
$ErrorActionPreference = "Stop"
8+
9+
if (-not (Test-Path .\package.json)) {
10+
Write-Error "package.json not found in the current directory. Please run this script in the directory of the project."
11+
exit 1
12+
}
13+
14+
try {
15+
Get-Command artifacts-npm-credprovider | Out-Null
16+
Write-Host "artifacts-npm-credprovider is already installed"
17+
}
18+
catch {
19+
Write-Host "Installing artifacts-npm-credprovider"
20+
if (-not $WhatIf) {
21+
npm install -g @microsoft/artifacts-npm-credprovider --registry https://pkgs.dev.azure.com/artifacts-public/23934c1b-a3b5-4b70-9dd3-d1bef4cc72a0/_packaging/AzureArtifacts/npm/registry/
22+
}
23+
}
24+
25+
Write-Host "Provisioning a token for the NPM registry. You might be prompted to authenticate."
26+
if (-not $WhatIf) {
27+
# This command provisions a token for the AzDO NPM registry to run npm install and ensure any missing package is mirrored.
28+
artifacts-npm-credprovider -f -c .\.npmrc
29+
}
30+
31+
Write-Host "Running npm install"
32+
if (-not $WhatIf) {
33+
npm install --prefer-online --include optional
34+
}
35+
36+
# Add optional dependencies to the cache to ensure that they get mirrored
37+
Write-Host "Adding optional dependencies to the cache"
38+
$packages = (Get-Content .\package-lock.json | ConvertFrom-Json -AsHashtable).packages
39+
40+
$allOptionalDependencies = @()
41+
foreach ($packagePath in $packages.Keys) {
42+
$package = $packages[$packagePath]
43+
if ($null -eq $package.optionalDependencies) {
44+
continue
45+
}
46+
47+
$optionalDependencies = $package.optionalDependencies
48+
foreach ($optionalDependencyName in $optionalDependencies.Keys) {
49+
$optionalDependencyVersion = $optionalDependencies[$optionalDependencyName]
50+
$allOptionalDependencies += "$optionalDependencyName@$optionalDependencyVersion"
51+
}
52+
}
53+
54+
if ($allOptionalDependencies.Count -gt 0) {
55+
Write-Host "Found $($allOptionalDependencies.Count) optional dependencies:"
56+
$allOptionalDependencies | ForEach-Object { Write-Host " $_" }
57+
if (-not $WhatIf) {
58+
npm cache add @allOptionalDependencies
59+
}
60+
}

src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Target Name="NpmInstall"
1010
Inputs="$(_TypescriptRootPath)\package.json"
1111
Outputs="$(_NpmInstallStampFile)">
12-
<Exec Command="npm install" WorkingDirectory="$(_TypescriptRootPath)" />
12+
<Exec Command="npm ci" WorkingDirectory="$(_TypescriptRootPath)" />
1313
<Touch Files="$(_NpmInstallStampFile)" AlwaysCreate="true" />
1414
</Target>
1515

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/

src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting/TypeScript/azure-devops-report/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
override.json
2-
package-lock.json
32
VSIXPackageVersion.json
43
LICENSE
54

src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting/TypeScript/azure-devops-report/build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Write-Host "Using version $PackageVersion"
2323

2424
# Write-Information "Building Report Publishing task"
2525
Set-Location $PSScriptRoot/tasks/PublishAIEvaluationReport
26-
npm install --omit=dev
26+
npm ci --omit=dev
2727
# Copy task files to dist folder
2828
New-Item -ItemType Directory -Path ./dist -Force
2929
copy-item -Path ./task.json -Destination ./dist/ -Force
@@ -39,7 +39,7 @@ remove-item -Path ./dist/node_modules/resolve/test -Recurse -Force -ErrorAction
3939

4040
# Write-Information "Building Extension Package"
4141
Set-Location $PSScriptRoot
42-
npm install
42+
npm ci
4343
npx tsc -b
4444
npx vite build
4545

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/

0 commit comments

Comments
 (0)