Skip to content
Closed
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
30 changes: 23 additions & 7 deletions resources/NpmDsc/NpmDsc.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,31 @@
}

[void] Set() {
$inDesiredState = $this.Test()
if ($this.Test()) {
return
}

$installParams = @{
PackageName = $this.Name
Arguments = $this.Arguments
Global = $this.Global
}

if ($this.Ensure -eq [Ensure]::Present) {
if (-not $inDesiredState) {
Install-NpmPackage -PackageName $this.Name -Arguments $this.Arguments -Global $this.Global
}
[NpmPackage]::EnsureValidPackageName($this.Name)
Install-NpmPackage @installParams
} else {
if (-not $inDesiredState) {
Uninstall-NpmPackage -PackageName $this.Name -Arguments $this.Arguments -Global $this.Global
}
Uninstall-NpmPackage @installParams
}
}

hidden static [void] EnsureValidPackageName($name) {
# TODO: Handling owner/repo package references pointing to GH repositories requires accounting
# for git errors (missing git, failed authentication, etc.).
#
# See: https://docs.npmjs.com/cli/v11/commands/npm-install#description

Check warning on line 365 in resources/NpmDsc/NpmDsc.psm1

View workflow job for this annotation

GitHub Actions / Check Spelling

`npmjs` is not a recognized word. (unrecognized-spelling)
if (($name -notmatch '^git(?:\+(?:ssh|https?|file))?://') -and $name.Contains('/') -and -not $name.StartsWith('@')) {
throw "The Set operation currently only supports packages specified as [<@scope>/]<name>. The given package looks like a GitHub repository: $($name)."
}
}

Expand Down
Loading