diff --git a/eng/common/scripts/TypeSpec-Project-Generate.ps1 b/eng/common/scripts/TypeSpec-Project-Generate.ps1 index 418221982a365..e323f42aff6dc 100644 --- a/eng/common/scripts/TypeSpec-Project-Generate.ps1 +++ b/eng/common/scripts/TypeSpec-Project-Generate.ps1 @@ -46,14 +46,36 @@ function NpmInstallForProject([string]$workingDirectory) { Write-Host("Copying package.json from $replacementPackageJson") Copy-Item -Path $replacementPackageJson -Destination "package.json" -Force + #default to root/eng/emitter-package-lock.json but you can override by writing + #Get-${Language}-EmitterPackageLockPath in your Language-Settings.ps1 + $emitterPackageLock = Join-Path $PSScriptRoot "../../emitter-package-lock.json" + if (Test-Path "Function:$GetEmitterPackageLockPathFn") { + $emitterPackageLock = &$GetEmitterPackageLockPathFn + } + + $usingLockFile = Test-Path $emitterPackageLock + + if ($usingLockFile) { + Write-Host("Copying package-lock.json from $emitterPackageLock") + Copy-Item -Path $emitterPackageLock -Destination "package-lock.json" -Force + } + $useAlphaNpmRegistry = (Get-Content $replacementPackageJson -Raw).Contains("-alpha.") if($useAlphaNpmRegistry) { Write-Host "Package.json contains '-alpha.' in the version, Creating .npmrc using public/azure-sdk-for-js-test-autorest feed." - "registry=https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js-test-autorest/npm/registry/ `n`nalways-auth=true" | Out-File '.npmrc' + "registry=https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js-test-autorest@local/npm/registry/ `n`nalways-auth=true" | Out-File '.npmrc' + } + + if ($usingLockFile) { + Write-Host "> npm ci" + npm ci + } + else { + Write-Host "> npm install" + npm install } - npm install --no-lock-file if ($LASTEXITCODE) { exit $LASTEXITCODE } } finally { diff --git a/eng/common/scripts/common.ps1 b/eng/common/scripts/common.ps1 index 0770de667b14a..e6b5f09fe7c83 100644 --- a/eng/common/scripts/common.ps1 +++ b/eng/common/scripts/common.ps1 @@ -61,6 +61,7 @@ $GetRepositoryLinkFn = "Get-${Language}-RepositoryLink" $GetEmitterAdditionalOptionsFn = "Get-${Language}-EmitterAdditionalOptions" $GetEmitterNameFn = "Get-${Language}-EmitterName" $GetEmitterPackageJsonPathFn = "Get-${Language}-EmitterPackageJsonPath" +$GetEmitterPackageLockPathFn = "Get-${Language}-EmitterPackageLockPath" # Expected to be set in eng/scripts/docs/Docs-Onboarding.ps1 $SetDocsPackageOnboarding = "Set-${Language}-DocsPackageOnboarding"