# NativeInstaller

> Installs the frontend dependencies of a package.json into a flat directory (node_modules by default) without a Node.js package manager.

[API reference](/docs/api/index.md) › [Foxy](/docs/extensions/foxy/reference/index.md) › [Native](/docs/extensions/foxy/reference/native/index.md) › NativeInstaller

| final readonly class | `Foxy\Native\NativeInstaller` |
| --- | --- |
| Implements | [`NativeInstallerInterface`](/docs/extensions/foxy/reference/native/nativeinstallerinterface/index.md) |
| Source | [`src/Native/NativeInstaller.php`](https://github.com/php-forge/foxy/blob/main/src/Native/NativeInstaller.php#L44) |

Installs the frontend dependencies of a `package.json` into a flat directory (`node_modules` by default) without a
Node.js package manager.

Registry packages are resolved (or read from a fresh `foxy.lock`), downloaded, and extracted into
`<install directory>/.foxy-tmp` before being moved into place; `file:` packages are copied from their local
directory. Top-level entries of the install directory outside the install set are removed, except dot-entries such
as `.bin`. A registry package already in place with its recorded lock entry is kept; see [`InstalledState`](/docs/extensions/foxy/reference/native/installedstate/index.md).

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates the native package installer. | `NativeInstaller` |
| [`install()`](#method-install) | Installs the dependencies declared by the manifest, reading or rewriting the lock file. | `NativeInstaller` |

## Method details

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

```php
public function __construct(Composer\IO\IOInterface $io, Composer\Util\Filesystem $fs, Foxy\Native\NpmRegistryInterface $registry, Foxy\Native\DependencyResolver $resolver, Foxy\Native\TarballExtractor $extractor)
```

Creates the native package installer.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$io` | `Composer\IO\IOInterface` | Output that receives one line per changed package, and per kept package at verbose level. |
| `$fs` | `Composer\Util\Filesystem` | Filesystem used to copy, move, and remove package directories. |
| `$registry` | [`NpmRegistryInterface`](/docs/extensions/foxy/reference/native/npmregistryinterface/index.md) | Registry that provides the tarballs. |
| `$resolver` | [`DependencyResolver`](/docs/extensions/foxy/reference/native/dependencyresolver/index.md) | Resolver of the registry requirements. |
| `$extractor` | [`TarballExtractor`](/docs/extensions/foxy/reference/native/tarballextractor/index.md) | Extractor of the downloaded tarballs. |

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

```php
public function install(string $manifestPath, string $lockPath, string $installDirectory, bool $update): void
```

Installs the dependencies declared by the manifest, reading or rewriting the lock file.

A missing manifest declares no dependency. An optional `file:` package whose `package.json` is missing is skipped
with a warning. The `dependencies`, `devDependencies`, and `optionalDependencies` maps
are merged, an optional entry overriding a mandatory one of the same name as npm does; an unsatisfiable optional
entry is skipped with a warning. The lock file is reused when it is fresh (same requirements, same
local package versions) and `$update` is `false`; otherwise the requirements are resolved again and the lock
file is written before any package is installed, so a download failure leaves a usable lock file.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$manifestPath` | `string` | Path of the root `package.json`. |
| `$lockPath` | `string` | Path of the `foxy.lock` file. |
| `$installDirectory` | `string` | Path of the directory to populate (`node_modules` by default). |
| `$update` | `bool` | Whether to resolve again even when the lock file is fresh. |

**Throws**

- [`Foxy\Exception\RuntimeException`](/docs/extensions/foxy/reference/exception/runtimeexception/index.md): if a manifest is invalid, a mandatory local package is missing, a local package overlaps the install directory, a requirement cannot be resolved or downloaded, the lock file is malformed, a local package cannot be copied, or an existing package directory cannot be removed.