TypeScript Package Manager Library & CLI
raw JSON →ts-pkgx is a TypeScript-first library and command-line interface (CLI) designed for managing software packages across different environments. It provides a programmatic API that allows developers to integrate package management functionalities directly into their applications, abstracting away the specifics of underlying package managers. Concurrently, it offers a robust CLI for direct system-level operations, similar in scope to universal package managers like Homebrew or the package handling capabilities within modern runtimes like Bun. The current stable version is 0.4.154. It exhibits a highly rapid release cadence, with numerous patch versions (e.g., v0.4.144 through v0.4.154) often released in close succession, though recent updates frequently state 'No significant changes.' This suggests an active but perhaps automated development and release workflow. Its primary differentiation lies in offering a cohesive TypeScript-friendly library interface alongside a powerful command-line tool, enabling both application-embedded and standalone package lifecycle management.
Common errors
error Error: EACCES: permission denied, unlink '/usr/local/bin/some-package' ↓
sudo (e.g., sudo npx ts-pkgx install <package>) or ensure the executing user/process has write access to the target directories. error TypeError: Cannot read properties of undefined (reading 'installPackage') ↓
tsconfig.json targets ES2020 or higher with module: 'NodeNext' or 'ESNext', and use import { installPackage } from 'ts-pkgx';. error Package '<package-name>' not found in known registries/providers. ↓
Warnings
gotcha ts-pkgx operates on system-level packages, not necessarily npm dependencies. Ensure you understand which package manager (e.g., Homebrew, apt, etc.) it might be interacting with under the hood for your specific OS and environment. ↓
breaking While recent releases show 'No significant changes', the rapid patch version increments (e.g., 0.4.144 to 0.4.154 in quick succession) suggest an active development lifecycle where minor breaking changes or API shifts could occur without a major version bump. Always review changelogs. ↓
gotcha Permissions are critical for system-level package management. Running ts-pkgx commands or library functions that modify the system (install, uninstall) might require elevated privileges (e.g., `sudo` on Linux/macOS) which can lead to errors if not handled correctly. ↓
Install
npm install ts-pkgx yarn add ts-pkgx pnpm add ts-pkgx Imports
- installPackage wrong
const { installPackage } = require('ts-pkgx');correctimport { installPackage } from 'ts-pkgx'; - uninstallPackage wrong
import uninstallPackage from 'ts-pkgx';correctimport { uninstallPackage } from 'ts-pkgx'; - listPackages wrong
import { listPackages as getPackages } from 'ts-pkgx/dist/index';correctimport { listPackages } from 'ts-pkgx';
Quickstart
import { installPackage, uninstallPackage, listPackages, getPackageDetails } from 'ts-pkgx';
async function managePackages() {
console.log('--- Installing a package (example: 'pkg-utils') ---');
try {
const installResult = await installPackage('pkg-utils');
console.log(`Installation successful: ${installResult.packageName} version ${installResult.version}`);
} catch (error) {
console.error('Installation failed:', error instanceof Error ? error.message : String(error));
}
console.log('\n--- Listing all installed packages ---');
const allPackages = await listPackages();
console.log('Installed packages:', allPackages.map(p => `${p.name}@${p.version}`).join(', '));
console.log('\n--- Getting details for a specific package ---');
const pkgDetails = await getPackageDetails('pkg-utils');
if (pkgDetails) {
console.log(`Details for pkg-utils: Path=${pkgDetails.path}, Description=${pkgDetails.description}`);
} else {
console.log('pkg-utils not found or details unavailable.');
}
console.log('\n--- Uninstalling the package ---');
try {
const uninstallResult = await uninstallPackage('pkg-utils');
console.log(`Uninstallation successful: ${uninstallResult.packageName}`);
} catch (error) {
console.error('Uninstallation failed:', error instanceof Error ? error.message : String(error));
}
}
managePackages();
// To use the CLI, assuming ts-pkgx is globally installed or available via npx:
// npx ts-pkgx install pkg-utils
// npx ts-pkgx list
// npx ts-pkgx info pkg-utils
// npx ts-pkgx uninstall pkg-utils