# AbstractAssetManager

> Runs an external frontend package manager and validates its executable version.

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

| abstract class | `Foxy\Asset\AbstractAssetManager` |
| --- | --- |
| Extends | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| Implements | [`AssetManagerInterface`](/docs/extensions/foxy/reference/asset/assetmanagerinterface/index.md) |
| Source | [`src/Asset/AbstractAssetManager.php`](https://github.com/php-forge/foxy/blob/main/src/Asset/AbstractAssetManager.php#L26) |

5 subclasses:

- [`BunManager`](/docs/extensions/foxy/reference/asset/bunmanager/index.md)
- [`DenoManager`](/docs/extensions/foxy/reference/asset/denomanager/index.md)
- [`NpmManager`](/docs/extensions/foxy/reference/asset/npmmanager/index.md)
- [`PnpmManager`](/docs/extensions/foxy/reference/asset/pnpmmanager/index.md)
- [`YarnManager`](/docs/extensions/foxy/reference/asset/yarnmanager/index.md)

Runs an external frontend package manager and validates its executable version.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-config"></span>[`$config`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#property-config) protected constructor | [`Foxy\Config\Config`](/docs/extensions/foxy/reference/config/config/index.md) | Foxy configuration. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="property-executor"></span>`$executor` protected constructor | `Composer\Util\ProcessExecutor` | Process executor used to invoke the manager. | `AbstractAssetManager` |
| <span id="property-fs"></span>[`$fs`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#property-fs) protected constructor | `Composer\Util\Filesystem` | Filesystem used to resolve and update manifest paths. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="property-io"></span>[`$io`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#property-io) protected constructor | `Composer\IO\IOInterface` | Composer output used for progress messages. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="property-updatable"></span>[`$updatable`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#property-updatable) protected | `bool` | Whether an existing frontend installation may be updated. Default: `true`. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="property-versionConverter"></span>`$versionConverter` protected constructor | [`Foxy\Converter\VersionConverterInterface`](/docs/extensions/foxy/reference/converter/versionconverterinterface/index.md)`\|null` | Converter for manager version output. Default: `null`. | `AbstractAssetManager` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a manager that executes frontend commands for the configured asset manifest. | `AbstractAssetManager` |
| <span id="method-addDependencies"></span>[`addDependencies()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-addDependencies) | Merges Composer asset dependencies into the frontend package manifest. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| [`audit()`](#method-audit) | Runs the manager audit command against the current lock file. | `AbstractAssetManager` |
| <span id="method-getAuditParser"></span>[`getAuditParser()`](/docs/extensions/foxy/reference/asset/assetmanagerinterface/index.md#method-getAuditParser) abstract | Returns the parser of this manager's audit report. | [`AssetManagerInterface`](/docs/extensions/foxy/reference/asset/assetmanagerinterface/index.md) |
| <span id="method-getLockPackageName"></span>[`getLockPackageName()`](/docs/extensions/foxy/reference/asset/assetmanagerinterface/index.md#method-getLockPackageName) abstract | Get the filename of the lock file. | [`AssetManagerInterface`](/docs/extensions/foxy/reference/asset/assetmanagerinterface/index.md) |
| <span id="method-getName"></span>[`getName()`](/docs/extensions/foxy/reference/asset/assetmanagerinterface/index.md#method-getName) abstract | Get the name of asset manager. | [`AssetManagerInterface`](/docs/extensions/foxy/reference/asset/assetmanagerinterface/index.md) |
| <span id="method-getPackageJsonPath"></span>[`getPackageJsonPath()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-getPackageJsonPath) | Returns the frontend package manifest path. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="method-getPackageName"></span>[`getPackageName()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-getPackageName) | Returns the frontend package manifest filename. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="method-getVersionConstraint"></span>[`getVersionConstraint()`](/docs/extensions/foxy/reference/asset/assetmanagerinterface/index.md#method-getVersionConstraint) abstract | Get the supported version constraint of the asset manager. | [`AssetManagerInterface`](/docs/extensions/foxy/reference/asset/assetmanagerinterface/index.md) |
| <span id="method-hasLockFile"></span>[`hasLockFile()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-hasLockFile) | Returns whether the manager lock file exists. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| [`isAvailable()`](#method-isAvailable) | Returns whether the manager executable reports a detectable version. | `AbstractAssetManager` |
| <span id="method-isInstalled"></span>[`isInstalled()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-isInstalled) | Returns whether both the dependency directory and package manifest exist. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="method-isUpdatable"></span>[`isUpdatable()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-isUpdatable) | Returns whether an existing frontend installation may be updated. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| [`run()`](#method-run) | Installs or updates frontend dependencies according to the manager state and configuration. | `AbstractAssetManager` |
| <span id="method-setUpdatable"></span>[`setUpdatable()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-setUpdatable) | Enables or disables updates of an existing frontend installation. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| [`validate()`](#method-validate) | Validates the installed manager version against Foxy's supported and configured constraints. | `AbstractAssetManager` |
| <span id="method-actionWhenComposerDependenciesAreAlreadyInstalled"></span>[`actionWhenComposerDependenciesAreAlreadyInstalled()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-actionWhenComposerDependenciesAreAlreadyInstalled) protected | Handles dependencies already present in the frontend installation. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="method-actionWhenComposerDependenciesAreMerged"></span>[`actionWhenComposerDependenciesAreMerged()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-actionWhenComposerDependenciesAreMerged) protected | Runs after the Composer asset dependencies are merged and before the asset package is written. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| [`buildCommand()`](#method-buildCommand) protected | Returns the manager command run by the configured or default binary, followed by the `manager-options` and `manager-{action}-options` values. | `AbstractAssetManager` |
| [`buildUnconfiguredCommand()`](#method-buildUnconfiguredCommand) protected | Returns the manager command run by the configured or default binary, without the install and update options. | `AbstractAssetManager` |
| [`getAuditCommand()`](#method-getAuditCommand) protected abstract | Get the command to audit the asset dependencies. | `AbstractAssetManager` |
| [`getAuditEnvironment()`](#method-getAuditEnvironment) protected | Get environment overrides required for a complete audit. | `AbstractAssetManager` |
| [`getDefaultBinary()`](#method-getDefaultBinary) protected | Returns the executable used when `manager-bin` is not configured; defaults to the manager name. | `AbstractAssetManager` |
| [`getInstallCommand()`](#method-getInstallCommand) protected | Returns the command that installs the asset dependencies, followed by the `manager-options` and `manager-install-options` values. | `AbstractAssetManager` |
| <span id="method-getLockFilePath"></span>[`getLockFilePath()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-getLockFilePath) protected | Returns the manager lock-file path under the root package directory. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="method-getManagerConfig"></span>[`getManagerConfig()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-getManagerConfig) protected | Returns the configuration scoped to this manager, so `manager-*` map entries resolve to its own value. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="method-getManagerWorkingDirectory"></span>[`getManagerWorkingDirectory()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-getManagerWorkingDirectory) protected | Returns the configured manager working directory, or `null` to use the process default. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="method-getNodeModulesPath"></span>[`getNodeModulesPath()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-getNodeModulesPath) protected | Returns the `node_modules` path under the root package directory. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="method-getRootPackageDir"></span>[`getRootPackageDir()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-getRootPackageDir) protected | Returns the resolved root package directory. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| <span id="method-getRootPackagePath"></span>[`getRootPackagePath()`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#method-getRootPackagePath) protected | Resolves a path under the root package directory. | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |
| [`getUpdateCommand()`](#method-getUpdateCommand) protected | Returns the command that updates the asset dependencies, followed by the `manager-options` and `manager-update-options` values. | `AbstractAssetManager` |
| [`getVersion()`](#method-getVersion) protected | Returns the normalized manager version, or `null` when it cannot be detected. | `AbstractAssetManager` |
| [`getVersionCommand()`](#method-getVersionCommand) protected | Returns the command that prints the manager version, without the install and update options. | `AbstractAssetManager` |
| [`normalizeVersionOutput()`](#method-normalizeVersionOutput) protected | Normalizes the trimmed output of the version command before it is converted. | `AbstractAssetManager` |
| [`validateAuditConfiguration()`](#method-validateAuditConfiguration) protected | Validate manager configuration that can change the audit scope. | `AbstractAssetManager` |
| [`withManagerTimeout()`](#method-withManagerTimeout) protected final | Runs the callback with the process timeout set to the `manager-timeout` option and restores the previous timeout afterward, even when the callback throws. | `AbstractAssetManager` |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-NODE_MODULES_PATH"></span>[`NODE_MODULES_PATH`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md#const-NODE_MODULES_PATH) | `'./node_modules'` |  | [`AbstractManifestAssetManager`](/docs/extensions/foxy/reference/asset/abstractmanifestassetmanager/index.md) |

## Method details

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

```php
public function __construct(Composer\IO\IOInterface $io, Foxy\Config\Config $config, Composer\Util\ProcessExecutor $executor, Composer\Util\Filesystem $fs, Foxy\Converter\VersionConverterInterface|null $versionConverter = null)
```

Creates a manager that executes frontend commands for the configured asset manifest.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$io` | `Composer\IO\IOInterface` | Composer output used for progress messages. |
| `$config` | [`Foxy\Config\Config`](/docs/extensions/foxy/reference/config/config/index.md) | Foxy configuration. |
| `$executor` | `Composer\Util\ProcessExecutor` | Process executor used to invoke the manager. |
| `$fs` | `Composer\Util\Filesystem` | Filesystem used by manifest handling. |
| `$versionConverter` | [`Foxy\Converter\VersionConverterInterface`](/docs/extensions/foxy/reference/converter/versionconverterinterface/index.md)`\|null` | Converter for manager version output. |

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

```php
public function audit(bool $noDev): Foxy\Audit\AuditProcessResult
```

Runs the manager audit command against the current lock file.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$noDev` | `bool` |  |

**Returns**

[`Foxy\Audit\AuditProcessResult`](/docs/extensions/foxy/reference/audit/auditprocessresult/index.md)

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

```php
public function isAvailable(): bool
```

Returns whether the manager executable reports a detectable version.

**Returns**

`bool`

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

```php
public function run(): int
```

Installs or updates frontend dependencies according to the manager state and configuration.

**Returns**

`int`

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

```php
public function validate(): void
```

Validates the installed manager version against Foxy's supported and configured constraints.

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

```php
protected function buildCommand(string $action, array|string $command): string
```

Returns the manager command run by the configured or default binary, followed by the `manager-options` and
`manager-{action}-options` values.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | `string` | The action whose `manager-{action}-options` value is appended. |
| `$command` | `array\|string` | The command arguments, joined with spaces. |

**Returns**

`string`

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

```php
protected function buildUnconfiguredCommand(array|string $command): string
```

Returns the manager command run by the configured or default binary, without the install and update options.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$command` | `array\|string` | The command arguments, joined with spaces. |

**Returns**

`string`

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

```php
abstract protected function getAuditCommand(bool $noDev): string
```

Get the command to audit the asset dependencies.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$noDev` | `bool` |  |

**Returns**

`string`

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

```php
protected function getAuditEnvironment(): array<string, string>
```

Get environment overrides required for a complete audit.

**Returns**

`array<string, string>`

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

```php
protected function getDefaultBinary(): string
```

Returns the executable used when `manager-bin` is not configured; defaults to the manager name.

**Returns**

`string`

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

```php
protected function getInstallCommand(): string
```

Returns the command that installs the asset dependencies, followed by the `manager-options` and
`manager-install-options` values.

**Returns**

`string`

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

```php
protected function getUpdateCommand(): string
```

Returns the command that updates the asset dependencies, followed by the `manager-options` and
`manager-update-options` values.

**Returns**

`string`

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

```php
protected function getVersion(): string|null
```

Returns the normalized manager version, or `null` when it cannot be detected.

**Returns**

`string|null`

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

```php
protected function getVersionCommand(): string
```

Returns the command that prints the manager version, without the install and update options.

**Returns**

`string`

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

```php
protected function normalizeVersionOutput(string $output): string
```

Normalizes the trimmed output of the version command before it is converted.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$output` | `string` |  |

**Returns**

`string`

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

```php
protected function validateAuditConfiguration(bool $noDev): void
```

Validate manager configuration that can change the audit scope.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$noDev` | `bool` |  |

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

```php
final protected function withManagerTimeout(callable(): Foxy\Asset\T $callback): Foxy\Asset\T
```

Runs the callback with the process timeout set to the `manager-timeout` option and restores the previous timeout
afterward, even when the callback throws.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$callback` | `callable(): Foxy\Asset\T` | The operation to run under the manager timeout. |

**Returns**

`Foxy\Asset\T`: The callback result.