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
9 changes: 4 additions & 5 deletions resources/Microsoft.VSCode.Dsc/Microsoft.VSCode.Dsc.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ function Invoke-VSCode {

$stdErrTempFile = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath (New-Guid).Guid
$stdOutTempFile = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath (New-Guid).Guid
$invocationSuccess = $true

$processParams = @{
FilePath = $VSCodeCLIPath
Expand All @@ -160,14 +159,14 @@ function Invoke-VSCode {

$invocation = Start-Process @processParams
$invocationErrors = Get-Content $stdErrTempFile -Raw -ErrorAction SilentlyContinue
$invocationErrors = $invocationErrors -replace '\n', '\n '
$invocationOutput = Get-Content $stdOutTempFile -ErrorAction SilentlyContinue
Remove-Item -Path $stdErrTempFile -ErrorAction Ignore
Remove-Item -Path $stdOutTempFile -ErrorAction Ignore

if (![string]::IsNullOrWhiteSpace($invocationErrors)) { $invocationSuccess = $false }
if ($invocation.ExitCode) { $invocationSuccess = $false }
if (!$invocationSuccess) { throw [System.Configuration.ConfigurationException]::new("Executing '$VSCodeCLIPath $Command' failed. Command Output: '$invocationErrors'") }
if ($invocation.ExitCode -ne 0) {
$details = if ([string]::IsNullOrWhiteSpace($invocationErrors)) { $invocationOutput -join [System.Environment]::NewLine } else { $invocationErrors.Trim() }
Comment thread
AmelBawa-msft marked this conversation as resolved.
throw [System.Configuration.ConfigurationException]::new("Executing '$VSCodeCLIPath $Command' failed with exit code $($invocation.ExitCode). Command Output: '$details'")
}

return $invocationOutput
}
Expand Down
17 changes: 12 additions & 5 deletions resources/NpmDsc/NpmDsc.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ function GetNpmPath {
} elseif (Test-Path $globalNpmCacheDir -ErrorAction SilentlyContinue) {
return $globalNpmCacheDir
} else {
$result = (Invoke-Npm -Command @('config', 'list', '--json') | ConvertFrom-Json -ErrorAction SilentlyContinue).cache
if (Test-Path $result -ErrorAction SilentlyContinue) {
# Call 'npm' directly rather than through Invoke-Npm: this is an error-reporting helper
# and Invoke-Npm's failure path calls back into GetNpmPath, which would recurse indefinitely.
$cacheRoot = (& npm config list --json --logs-max=0 2>$null | ConvertFrom-Json -ErrorAction SilentlyContinue).cache
$result = if ($cacheRoot) { Join-Path $cacheRoot '_logs' } else { $null }
if ($result -and (Test-Path $result -ErrorAction SilentlyContinue)) {
return $result
} else {
return $null
Expand Down Expand Up @@ -428,15 +431,19 @@ class NpmPackage {

[string] WhatIf() {
if ($this.Ensure -eq [Ensure]::Present) {
$whatIfState = Install-NpmPackage -PackageName $this.Name -Global $this.Global -Arguments @('--dry-run')

$out = @{
Name = $this.Name
_metaData = @{
whatif = @()
}
}
$out._metaData.whatif = $LASTEXITCODE -ne 0 ? (GetNpmWhatIfResponse) : ($whatIfState | Where-Object { $_.Trim() -ne '' }) # Removes empty lines from response

try {
$whatIfState = Install-NpmPackage -PackageName $this.Name -Global $this.Global -Arguments @('--dry-run')
$out._metaData.whatif = $whatIfState | Where-Object { $_.Trim() -ne '' } # Removes empty lines from response
} catch {
$out._metaData.whatif = GetNpmWhatIfResponse
}
} else {
# Uninstall does not have --dry-run param
$out = @{}
Expand Down
Loading