Skip to main content

Package Management

Anemos uses JavaScript package management ecosystem to handle dependencies. Package management is handled by the anemos package commands. We will now explore how to manage dependencies in your Anemos project, including adding, updating, and removing dependencies, as well as the built-in type declarations that Anemos provides.

Anemos Type Declarations

When you create a new Anemos project, a package.json file is created in the project directory. This file initially contains a dev dependency to the Anemos type declarations, which are generated by Anemos itself.

These type declarations are placed in the .anemos/types directory within your project and are automatically updated whenever you run commands like:

  • anemos build
  • anemos package install
  • anemos package add
  • anemos package update
  • anemos package remove
  • anemos package link
  • anemos package unlink

If you need to manually regenerate the type declarations, you can run:

anemos declarations .anemos/types

Adding Dependencies

ES Module Support

Anemos uses Sobek as the JavaScript runtime. Sobek itself supports ES modules, but it doesn't offer an easy integration. Therefore, Anemos currently only supports CommonJS modules.

This may change in the future, but for now, you can only use CommonJS modules in your Anemos project.

You can add JavaScript libraries to your Anemos project using the anemos package add command. In this example, we will add the @ohayocorp/anemos-hello-world library, which generates manifests for a hello world application. To install it, run the following command:

anemos package add @ohayocorp/anemos-hello-world

This command adds the @ohayocorp/anemos-hello-world library as a dependency to your project, updating the package.json and bun.lock files accordingly.

Using the Dependency

Now, let's integrate the newly added library into our project. Update the main script file according to the highlighted changes:

index.ts
import * as anemos from "@ohayocorp/anemos";
import { Component } from "./component";
import * as helloWorld from "@ohayocorp/anemos-hello-world";

const builder = new anemos.Builder("1.31", anemos.KubernetesDistribution.Minikube, anemos.EnvironmentType.Development);

helloWorld.add(builder, {
name: "example-hello-world",
replicaCount: 2,
});

builder.addComponent(new Component({
image: "nginx:1.27",
replicas: 3,
}));

builder.build();

Now, this library will contribute to the manifest generation process. To see the manifests it generates, rebuild the project:

anemos build --tsc . dist/index.js

This command should generate a bunch of manifests in the output folder, under the example-hello-world directory which we specified as the name of the application.

Other Package Commands

Anemos provides wrappers for other common package management tasks:

  • anemos package run: Runs a script defined in package.json.
  • anemos package install: Installs all dependencies from package.json.
  • anemos package add <pkg...>: Adds specified dependencies.
  • anemos package update [pkg...]: Updates specified (or all) dependencies.
  • anemos package remove <pkg...>: Removes specified dependencies.
  • anemos package pack: Packs the project into a tarball.
  • anemos package publish: Publishes the package to a registry.
  • anemos package login: Logs in to a registry.
  • anemos package config: Sets NPM configuration options.
  • anemos package link [path]: Links a local package.
  • anemos package unlink: Unlinks a local package.