Skip to content

Commit

Permalink
Update native dependency install to install msal-node-extensions (#14343
Browse files Browse the repository at this point in the history
)

msal-node-extension has native dependency in the same way keytar package has. So this package needs to be reinstalled before running test. PR modified current native dep install code to support more dependency.
  • Loading branch information
praveenkuttappan authored Mar 17, 2021
1 parent bd143c6 commit db762b7
Showing 1 changed file with 44 additions and 13 deletions.
57 changes: 44 additions & 13 deletions eng/pipelines/templates/steps/use-node-test-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,53 @@ steps:

# Packages with native dependencies must be reinstalled after changing Node versions
- pwsh: |
$KeytarSymlinkPath = "common/temp/node_modules/.pnpm/node_modules/keytar"
$nativeDependencySymlinkPaths = "common/temp/node_modules/.pnpm/node_modules/keytar,common/temp/node_modules/.pnpm/node_modules/@azure/msal-node-extensions"
$currentLocation = Get-Location
$dependencySymlinks = $nativeDependencySymlinkPaths.Split(",")
# Map from the symlink path to the target path (npm has issues installing into symlink dirs)
# Example: common/temp/node_modules/.pnpm/keytar@5.6.0/node_modules/keytar
$KeytarTargetPath = (Get-Item $KeytarSymlinkPath).Target
foreach ($symlink in $dependencySymlinks)
{
Write-Host "Reinstalling native dependency $($symlink)"
# Need to run "npm install" at path containing "node_modules" folder
# Example: common/temp/node_modules/.pnpm/keytar@5.6.0
$KeytarInstallPath = Join-Path $KeytarTargetPath "../.."
if(-not (Test-Path $symlink))
{
Write-Host "Path $($symlink) doesn't exist. Skipping reinstall of this dependency."
continue
}
# Map from the symlink path to the target path (npm has issues installing into symlink dirs)
# Example: common/temp/node_modules/.pnpm/keytar@5.6.0/node_modules/keytar
$targetPath = (Get-Item $symlink).Target
# <pkg>@<version> is the leaf node of the path
# Example: keytar@5.6.0
$KeytarPackageAtVersion = Split-Path -Leaf $KeytarInstallPath
# Need to run "npm install" at path containing "node_modules" folder
# Example: common/temp/node_modules/.pnpm/keytar@5.6.0
$packageInstallPath = Join-Path $targetPath "../.."
Set-Location $KeytarInstallPath
# <pkg>@<version> is the leaf node of the path
# Example: keytar@5.6.0
# Move one more level up if package has org name
# for e.g. node_modules\.pnpm\@azure\msal-node-extensions@1.0.0-alpha.6\node_modules\@azure\msal-node-extensions
if ((Split-Path -Leaf $packageInstallPath) -eq "node_modules") {
$packageInstallPath = Join-Path $packageInstallPath ".."
}
$packageAtVersion = Split-Path -Leaf $packageInstallPath
# Check if package has org name. for e.g @azure/msal-node-enxtensions
# This returns either @azure or .pnpm( if no org is present)
$packageParentName = Split-path -Leaf (Split-Path -Parent -Resolve $packageInstallPath)
if ($packageParentName.StartsWith("@"))
{
# Include org name in package name to install
$packageAtVersion = $packageParentName + "/" + $packageAtVersion
}
Set-Location $packageInstallPath
Write-Host "Installing $($packageAtVersion)"
# Install matching version of package
npm install --no-package-lock $packageAtVersion
Set-Location $currentLocation
}
# Install matching version of package
npm install --no-package-lock $KeytarPackageAtVersion
displayName: Reinstall native dependencies

0 comments on commit db762b7

Please sign in to comment.