# AssetPackage

> Maintains Composer-provided dependencies in a frontend package manifest.

[API reference](/docs/api/index.md) › [Foxy](/docs/extensions/foxy/reference/index.md) › [Asset](/docs/extensions/foxy/reference/asset/index.md) › AssetPackage

| final class | `Foxy\Asset\AssetPackage` |
| --- | --- |
| Implements | [`AssetPackageInterface`](/docs/extensions/foxy/reference/asset/assetpackageinterface/index.md) |
| Source | [`src/Asset/AssetPackage.php`](https://github.com/php-forge/foxy/blob/main/src/Asset/AssetPackage.php#L27) |

Maintains Composer-provided dependencies in a frontend package manifest.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Loads the frontend package manifest and injects metadata inherited from the Composer root package. | `AssetPackage` |
| [`addNewDependencies()`](#method-addNewDependencies) | Adds Composer asset dependencies and returns the names that were already installed. | `AssetPackage` |
| [`getInstalledDependencies()`](#method-getInstalledDependencies) | Returns Composer-managed dependencies currently declared in the package manifest. | `AssetPackage` |
| [`getPackage()`](#method-getPackage) | Returns the complete frontend package manifest. | `AssetPackage` |
| [`removeUnusedDependencies()`](#method-removeUnusedDependencies) | Removes Composer-managed dependencies absent from the current dependency set. | `AssetPackage` |
| [`setPackage()`](#method-setPackage) | Replaces the in-memory frontend package manifest. | `AssetPackage` |
| [`write()`](#method-write) | Writes the in-memory package manifest to its JSON file. | `AssetPackage` |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-COMPOSER_PREFIX"></span>`COMPOSER_PREFIX` | `'@composer-asset/'` |  | `AssetPackage` |
| <span id="const-SECTION_DEPENDENCIES"></span>`SECTION_DEPENDENCIES` | `'dependencies'` |  | `AssetPackage` |
| <span id="const-SECTION_DEV_DEPENDENCIES"></span>`SECTION_DEV_DEPENDENCIES` | `'devDependencies'` |  | `AssetPackage` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(Composer\Package\RootPackageInterface $rootPackage, Composer\Json\JsonFile $jsonFile, Composer\Util\Filesystem|null $fs = null)
```

Loads the frontend package manifest and injects metadata inherited from the Composer root package.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rootPackage` | `Composer\Package\RootPackageInterface` | The composer root package |
| `$jsonFile` | `Composer\Json\JsonFile` | The JSON file |
| `$fs` | `Composer\Util\Filesystem\|null` |  |

**Throws**

- `Seld\JsonLint\ParsingException`

### addNewDependencies() <span id="method-addNewDependencies"></span>

```php
public function addNewDependencies(array $dependencies): list<string>
```

Adds Composer asset dependencies and returns the names that were already installed.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$dependencies` | `array` | The dependencies |

**Returns**

`list<string>`: The existing packages.

### getInstalledDependencies() <span id="method-getInstalledDependencies"></span>

```php
public function getInstalledDependencies(): array
```

Returns Composer-managed dependencies currently declared in the package manifest.

**Returns**

`array`

### getPackage() <span id="method-getPackage"></span>

```php
public function getPackage(): array
```

Returns the complete frontend package manifest.

**Returns**

`array`

### removeUnusedDependencies() <span id="method-removeUnusedDependencies"></span>

```php
public function removeUnusedDependencies(array $dependencies): self
```

Removes Composer-managed dependencies absent from the current dependency set.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$dependencies` | `array` |  |

**Returns**

`self`

### setPackage() <span id="method-setPackage"></span>

```php
public function setPackage(array $package): self
```

Replaces the in-memory frontend package manifest.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$package` | `array` |  |

**Returns**

`self`

### write() <span id="method-write"></span>

```php
public function write(): self
```

Writes the in-memory package manifest to its JSON file.

**Returns**

`self`

**Throws**

- [`Exception`](https://www.php.net/manual/en/class.exception.php)