# Package Manager

Source: https://developers.inkdrop.app/modules/package-manager

The Package Manager in Inkdrop is responsible for the lifecycle management of packages. Available as `env.packages` on the [Environment](https://developers.inkdrop.app/modules/environment) passed to `activate(env)`.

---

## Package Lifecycle

Package lifecycle includes:

- **Loading**: Reads and parses the package's metadata and resources like keymaps, menus, stylesheets, etc.
- **Activating**: Registers the loaded resources and calls `activate()` on the package's main module.
- **Deactivating**: Unregisters resources and calls `deactivate()` on the package's main module.
- **Unloading**: Removes the package completely from the package manager.

You can enable or disable packages via the `core.disabledPackages` config settings or by using `enablePackage()` or `disablePackage()`.

---

## Package Load Completion Subscription `onDidLoadInitialPackages(callback)`

Invoke the callback when all packages have been loaded.

### Parameters

- **callback()** (function, required)

  Function to be invoked upon package load completion.

### Returns

Returns a [Disposable](https://developers.inkdrop.app/event-subscription/disposable) for unsubscribing.

---

## Initial Package Activation Subscription `onDidActivateInitialPackages(callback)`

Invoke the callback when all packages have been activated.

### Parameters

- **callback()** (function, required)

  Function to be invoked upon the activation of all packages.

### Returns

Returns a [Disposable](https://developers.inkdrop.app/event-subscription/disposable) for unsubscribing.

---

## Individual Package Activation Subscription `onDidActivatePackage(callback)`

Invoke the callback when a specific package is activated.

### Parameters

- **callback(package)** (function, required)

  Function to be invoked when a package is activated, where `package` is the [Package](https://developers.inkdrop.app/modules/package) that was activated.

### Returns

Returns a [Disposable](https://developers.inkdrop.app/event-subscription/disposable) for unsubscribing.

---

## Package Deactivation Subscription `onDidDeactivatePackage(callback)`

Invoke the callback when a package is deactivated.

### Parameters

- **callback(package)** (function, required)

  Function to be invoked when a package is deactivated, where `package` is the [Package](https://developers.inkdrop.app/modules/package) that was deactivated.

### Returns

Returns a [Disposable](https://developers.inkdrop.app/event-subscription/disposable) for unsubscribing.

---

## Package Load Subscription `onDidLoadPackage(callback)`

Invoke the callback when a package is loaded.

### Parameters

- **callback(package)** (function, required)

  Function to be invoked when a package is loaded, where `package` is the [Package](https://developers.inkdrop.app/modules/package) that was loaded.

### Returns

Returns a [Disposable](https://developers.inkdrop.app/event-subscription/disposable) for unsubscribing.

---

## Package Unload Subscription `onDidUnloadPackage(callback)`

Invoke the callback when a package is unloaded.

### Parameters

- **callback(package)** (function, required)

  Function to be invoked when a package is unloaded, where `package` is the [Package](https://developers.inkdrop.app/modules/package) that was unloaded.

### Returns

Returns a [Disposable](https://developers.inkdrop.app/event-subscription/disposable) for unsubscribing.

---

## Get IPM Path `getIpmPath()`

Get the path to the `ipm` command.

### Returns

Returns a String file path to `ipm`.

---

## Get Package Directory Paths `getPackageDirPaths()`

Get paths used for searching packages.

### Returns

Returns an Array of String directory paths.

---

## Resolve Package Path `resolvePackagePath(name)`

Resolve a package name to a disk path.

### Parameters

- **name** (string, required)

  The package name to be resolved.

### Returns

Returns a String folder path or undefined if not resolvable.

---

## Check if Package is Bundled `isBundledPackage(name)`

Determine if a package is bundled with Inkdrop.

### Parameters

- **name** (string, required)

  Name of the package to check.

### Returns

Returns a Boolean, true if bundled, otherwise false.

---

## Enable Package `enablePackage(name)`

Enable the package with the specified name.

### Parameters

- **name** (string, required)

  The name of the package to be enabled.

### Returns

Returns the [Package](https://developers.inkdrop.app/modules/package) that was enabled, or `null` if it isn't loaded.

---

## Disable Package `disablePackage(name)`

Disable the package with the specified name.

### Parameters

- **name** (string, required)

  The name of the package to be disabled.

### Returns

Returns the [Package](https://developers.inkdrop.app/modules/package) that was disabled, or `null` if it isn't loaded.

---

## Check Package Disabled Status `isPackageDisabled(name)`

Check if the package with the given name is disabled.

### Parameters

- **name** (string, required)

  The name of the package to check.

### Returns

Returns a Boolean: `true` if disabled, `false` if not.

---

## Get Active Packages List `getActivePackages()`

Retrieve an array of all the active packages.

### Returns

Returns an Array of active [Packages](https://developers.inkdrop.app/modules/package).

---

## Get Active Package `getActivePackage(name)`

Get the active package with the specified name.

### Parameters

- **name** (string, required)

  The name of the package to retrieve.

### Returns

Returns the active [Package](https://developers.inkdrop.app/modules/package) or `undefined`.

---

## Check Package Active Status `isPackageActive(name)`

Determine if the package with the specified name is active.

### Parameters

- **name** (string, required)

  The name of the package to check.

### Returns

Returns a Boolean indicating active status.

---

## Get Loaded Packages List `getLoadedPackages()`

Retrieve an array of all loaded packages.

### Returns

Returns an Array of loaded [Packages](https://developers.inkdrop.app/modules/package).

---

## Get Loaded Package `getLoadedPackage(name)`

Get the loaded package with the specified name.

### Parameters

- **name** (string, required)

  The name of the package to retrieve.

### Returns

Returns the loaded [Package](https://developers.inkdrop.app/modules/package) or `undefined`.

---

## Check Package Loaded Status `isPackageLoaded(name)`

Check if the package with the given name is loaded.

### Parameters

- **name** (string, required)

  The name of the package to check.

### Returns

Returns a Boolean indicating if the package is loaded.

---

## Get Available Package Paths `getAvailablePackagePaths()`

Retrieve an array of paths for all available packages.

### Returns

Returns an Array of Strings with all available package paths.

---

## Get Available Package Names `getAvailablePackageNames()`

Get a list of all available package names.

### Returns

Returns an Array of Strings with all available package names.

---

## Get Available Package Metadata `getAvailablePackageMetadata()`

Obtain metadata for all available packages.

### Returns

Returns an Array of Objects with metadata for all available packages.
