|
| 1 | +--- |
| 2 | +external help file: NpmDsc.psm1-Help.xml |
| 3 | +Module Name: NpmDsc |
| 4 | +ms.date: 11/16/2024 |
| 5 | +online version: |
| 6 | +schema: 2.0.0 |
| 7 | +title: NpmPackage |
| 8 | +--- |
| 9 | + |
| 10 | +# NpmPackage |
| 11 | + |
| 12 | +## SYNOPSIS |
| 13 | + |
| 14 | +The `NpmPackage` DSC Resource allows you to manage the installation, update, and removal of npm packages. This resource ensures that the specified npm package is in the desired state. |
| 15 | + |
| 16 | +## DESCRIPTION |
| 17 | + |
| 18 | +The `NpmPackage` DSC Resource allows you to manage the installation, update, and removal of npm packages. This resource ensures that the specified npm package is in the desired state. |
| 19 | + |
| 20 | +## PARAMETERS |
| 21 | + |
| 22 | +| **Parameter** | **Attribute** | **DataType** | **Description** | **Allowed Values** | |
| 23 | +| ------------------ | -------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | |
| 24 | +| `Ensure` | Optional | String | Specifies whether the npm package should be present or absent. The default value is `Present`. | `Present`, `Absent` | |
| 25 | +| `Name` | Key, Mandatory | String | The name of the npm package to manage. This is a key property. | Any valid npm package name | |
| 26 | +| `Version` | Optional | String | The version of the npm package to install. If not specified, the latest version will be installed. | Any valid version string (e.g., `4.17.1`) | |
| 27 | +| `PackageDirectory` | Optional | String | The directory where the npm package should be installed. If not specified, the package will be installed in the current directory. | Any valid directory path | |
| 28 | +| `Global` | Optional | Boolean | Indicates whether the npm package should be installed globally. The default value is `$false`. | `$true`, `$false` | |
| 29 | + |
| 30 | +## EXAMPLES |
| 31 | + |
| 32 | +### EXAMPLE 1 - Install React package in default directory |
| 33 | + |
| 34 | +```powershell |
| 35 | +PS C:\> Invoke-DscResource -ModuleName NpmDsc -Name NpmPackage -Method Set -Property @{ Name = 'react' } |
| 36 | +
|
| 37 | +# This example installs the npm package 'react' in the current directory. |
| 38 | +``` |
| 39 | + |
| 40 | +### EXAMPLE 2 - Install Babel package in global directory |
| 41 | + |
| 42 | +```powershell |
| 43 | +PS C:\> Invoke-DscResource -ModuleName NpmDsc -Name NpmPackage -Method Set -Property @{ Name = 'babel'; Global = $true } |
| 44 | +
|
| 45 | +# This example installs the npm package 'babel' globally. |
| 46 | +``` |
| 47 | + |
| 48 | +### EXAMPLE 3 - Get WhatIf result for React package |
| 49 | + |
| 50 | +```powershell |
| 51 | +PS C:\> ([NpmPackage]@{ Name = 'react' }).WhatIf() |
| 52 | +
|
| 53 | +# This example returns the whatif result for installing the npm package 'react'. Note: This does not actually install the package and requires the module to be imported using 'using module <moduleName>'. |
| 54 | +``` |
0 commit comments