↓ Skip to main content

ts-apt, an APT Library for TypeScript

·2 mins
Andrew Walsh
Author
Andrew Walsh
Coder with a passion for most all things technological.
ts-apt logo
Note

This post may become out of date. See the project’s README for the latest.

I released ts-apt, a TypeScript library for APT package operations on Debian-based Linux systems. It works with the standard APT binaries and with apt-fast.

I pulled it out of my cache-apt-pkgs-action rewrite. The APT code had grown into the hardest part of that action, so it made sense to give it its own tests and release cycle.

Features
#

  • Package operations: install, remove, upgrade and search packages, and read package metadata and installed file lists.
  • apt-fast when available: it falls back to apt-get automatically when apt-fast isn’t installed.
  • Pluggable command runners: commands run through a small interface, so you can swap in your own.
  • Typed errors: separate errors for validation, availability and command failures.
  • Locking: mutating operations take a lock, and read-only ones can run in parallel.

Quick Start
#

It needs Node.js 24 or newer and a Linux environment with APT tooling.

npm install ts-apt
import { createPackageManager } from "ts-apt";

const manager = await createPackageManager(false);

const searchResults = await manager.search(["vim", "python"]);
const installed = await manager.listInstalled();

console.log(searchResults.length, installed.length);
Note

Mutating operations need sudo. If the running user doesn’t have it, those calls fail.

Testing
#

Unit tests run on their own. The integration tests run against real APT tooling, so they are slower:

npm run test:unit
npm run test:integration

Links#

Parsing of the apt output uses js-internet-message, which avoids brittle string handling. Bugs and requests go in the repo’s issues.

Related


comments powered by Disqus