@r_masseater/kestrion
v0.1.1
Published
Ports the Node.js package ecosystem to Effect: the package.json Schema and its helpers, and Effect wrappers over the official npm, pnpm and Node.js readers.
Maintainers
Readme
@r_masseater/kestrion
Ports the Node.js package ecosystem to Effect: the package.json Schema and its helpers, and Effect wrappers over the official npm, pnpm and Node.js readers.
It does not parse anything itself. npm's @npmcli/package-json reads and writes package.json, the @pnpm/* packages read pnpm's files, and node:module finds installed packages. kestrion turns their results into Effect values, their failures into tagged errors and a missing file into Option.
It requires Node.js 26 or later. effect is a peer dependency. Each upstream package is an optional peer dependency of the entry that uses it, so you install only the readers you call.
vp add @r_masseater/kestrion effect| Entry | Upstream | Install with it |
| ---------------------------- | ---------------------- | ----------------------------------------------- |
| @r_masseater/kestrion | none | nothing |
| @r_masseater/kestrion/npm | @npmcli/package-json | @npmcli/package-json |
| @r_masseater/kestrion/pnpm | @pnpm/* readers | the @pnpm/* package of each function you call |
| @r_masseater/kestrion/node | node:module | nothing |
Describe a package.json
The main entry holds PackageJsonSchema, its type PackageJson, and the helpers that read its fields. Every field is optional, so any manifest decodes and your code states which fields it needs. VersionedPackageJsonSchema also requires name and version.
import { binEntriesOf, exportEntriesOf, namesIn, optionalPeerNames } from "@r_masseater/kestrion";namesIn(manifest, sections)lists the names declared in the dependency sections you pick.runtimeDependencyNamestakesdependencies,peerDependenciesandoptionalDependencies.optionalPeerNameslists the peers marked optional inpeerDependenciesMeta.exportEntriesOfturnsexportsinto[subpath, target]pairs, andtargetsInlists every file a target names.importSpecifierOfjoins a package name and a subpath.binEntriesOfturnsbininto[command, file]pairs. A stringbintakes the unscoped package name as the command, as npm does.
Read and write with npm
import { decodePackageJson, readPackageJson, updatePackageJson } from "@r_masseater/kestrion/npm";
import { Effect } from "effect";
const name = readPackageJson("libs/a").pipe(Effect.map((manifest) => manifest.name));
const added = updatePackageJson("libs/a", { optionalDependencies: { b: "1.0.0" } });decodePackageJson(text)parses text you already hold and returnsOption.parsePackageJson(text)does the same and fails withPackageJsonUnreadable.readPackageJson(directory)andreadVersionedPackageJson(directory)load the file with@npmcli/package-json.updatePackageJsonmerges fields into the file and keeps its indentation and line endings.writePackageJsoncreates a new file.
Read pnpm
import { lockedGraph, readWorkspaceManifest } from "@r_masseater/kestrion/pnpm";readWorkspaceManifest(root)readspnpm-workspace.yaml, andupdateWorkspaceManifest(root, fields)writes fields back.findWorkspaceProjects(root, patterns)lists the projects the patterns match.readWantedLockfile(root)readspnpm-lock.yaml.lockedPackageIdsandlockedGraphread its package ids and dependency edges.depPathsOfandparseDependencyPathread dependency paths.
Each call fails with PnpmUnreadable, which carries the root and the reason.
Find an installed package
import { findPackageJson } from "@r_masseater/kestrion/node";
const file = findPackageJson("effect", import.meta.url);findPackageJson resolves a package from the module you pass, as import would, and returns the path of its package.json. It works even when the package does not export ./package.json.
Agent skills
The package ships agent skills in skills/. Add permissions: { "@r_masseater/kestrion": { skills: true } } to pnpm-workspace.yaml and vp install links them into the skill directories of your agents.
