package-manager 0.0.1-preview.1

The Zena package manager's libraries: manifests, version selection, lockfiles, archives and the registry client

Readme Files Dependencies Versions

package-manager#

Client libraries for Zena packages published on AT Protocol: package manifests (zena-package.json), lockfiles (zena-lock.json), deterministic CAR source archives, dependency resolution, and registry queries. Versions and ranges are the package zena-lang:semver (packages/semver).

Usage#

import {readManifest} from 'package-manager/manifest';
import {Range} from 'zena-lang:semver';

let manifest = readManifest('{"name": "hello", "version": "1.0.0"}');
let version = manifest.version;
let matches = version != null && Range.parse('^1.0.0').includes(version);

Libraries#

  • package-manager/manifest: reading a package's zena-package.json, and rewriting its dependencies while keeping the rest of the file.
  • package-manager/workspace: a workspace's packages, read from disk: the root's manifest, the packages it lists, and the ones they depend on by path.
  • package-manager/files: which files a package publishes: its manifest's files patterns, or by default every file but tests, and always the manifest, README, and license, never hidden files, node_modules, or the lockfile.
  • package-manager/archive: source archives, the CAR files that hold a release's source. Packing is deterministic, so the same files always have the same CID, and unpacking accepts only what packing writes.
  • package-manager/records: the profile, release, retraction, and maintainers records, an organization's members record, and the private membership entries it commits to, read from the atproto data model with the checks their lexicons describe, and written back. Also the rules for package names.
  • package-manager/registry-methods: the NSIDs of the App View's XRPC methods.
  • package-manager/registry: finding packages: resolving a DID, a handle, or scope:name to a DID, a package's versions and retractions, its profile, and its releases with their proofs.
  • package-manager/resolve: version selection, from the ranges in all of a workspace's manifests to what its lockfile pins, installing as few versions of each package as the ranges allow.
  • package-manager/resolution: the packages a workspace's lockfile, zena-lock.json, pins, writing it, and what writing it changes in the pins already there (diffPins), including releases changed in place.
  • package-manager/cache: the package cache, where each source archive is unpacked into sources/<CID> for the compiler to read.
  • package-manager/fetch: fetching pinned packages into the cache. The release record's proof is checked against the account's signing key, the record and the source archive against the CIDs the lockfile pins, and the release's dependencies against the names it maps.
  • package-manager/validate: checking a package directory and its manifest before publishing.
  • package-manager/testing/fake-pds: an in-process PLC directory, DNS-over-HTTPS resolver, and PDS for package accounts, for testing code that finds and fetches packages.
2.7 KiB Raw
/**
 * Which files a package publishes in its source archive
 * (package-manifest.md, "files"): any files at all, docs, images and demos
 * among them, chosen by the patterns of its manifest's `files` list, or
 * by default every file but tests. Whatever the list says, an archive
 * always holds the manifest and the README and license files at the
 * package's root, and never hidden files, `node_modules`, or the
 * workspace's lockfile. `zena pkg publish` packs the files this allows, and a
 * host refuses an archive that holds any other.
 */

import {GlobSet} from 'zena:glob';
import {Manifest} from './manifest.zena';
import {MANIFEST} from './workspace.zena';

/** The files a package without a `files` list publishes: all but its tests. */
export let DEFAULT_FILES: Array<String> = ['**', '!**/*_test.zena', '!**/test', '!**/tests'];

/** The paths, relative to its root, a package publishes. */
export final class PublishedFiles {
  #set: GlobSet;

  /**
   * The files `patterns` choose, read as a `files` list is: the last
   * pattern that matches a path decides, a `!` excludes, and a pattern that
   * names a directory takes everything under it.
   */
  new(patterns: Array<String>) : #set = new GlobSet(expanded(patterns));

  /** The files `manifest` publishes: its `files` list, or `DEFAULT_FILES`. */
  static of(manifest: Manifest): PublishedFiles {
    return new PublishedFiles(manifest.files ?? DEFAULT_FILES);
  }

  /** Whether the file at `path`, relative to the package's root, is published. */
  includes(path: String): boolean {
    let segments = path.split('/');
    for (let segment in segments) {
      if (segment.startsWith('.') || segment == 'node_modules') {
        return false;
      }
    }
    if (path == 'zena-lock.json') {
      return false;
    }
    if (segments.length == 1 && (path == MANIFEST || isReadmeOrLicense(path))) {
      return true;
    }
    return this.#set.matches(path);
  }
}

/** Whether `name`, a file at a package's root, is its README or a license, which every archive keeps. */
function isReadmeOrLicense(name: String): boolean {
  let lower = name.asciiLowerCase();
  for (let stem in ['readme', 'license', 'licence', 'copying']) {
    if (lower == stem || lower.startsWith(`${stem}.`)) {
      return true;
    }
  }
  return false;
}

/** Each pattern, and the pattern with `/**` after it, so that one naming a directory takes all of it. */
function expanded(patterns: Array<String>): GrowableArray<String> {
  let out = new GrowableArray<String>();
  for (let pattern in patterns) {
    let trimmed = if (pattern.endsWith('/')) pattern.sliceBytes(0, pattern.length - 1) else pattern;
    out.push(trimmed);
    if (!trimmed.endsWith('/**')) {
      out.push(`${trimmed}/**`);
    }
  }
  return out;
}
  • atproto atproto.zena-lang.pkg.zena-lang.dev ~0.0.1-preview.1
  • zena-lang:semver semver.zena-lang.pkg.zena-lang.dev ~0.0.1-preview.1
VersionPublishedDependenciesApproved by
0.0.1-preview.1 2026-11-19
  • atproto atproto.zena-lang.pkg.zena-lang.dev ~0.0.1-preview.1
  • zena-lang:semver semver.zena-lang.pkg.zena-lang.dev ~0.0.1-preview.1