Docs Packages
@procedures/lib
npm install @procedures/lib
client-lib gives the procedures that manage the packages of the monorepo.
| Procedure | Function |
|---|---|
lib.scan | Find the packages of the workspace, with their dependencies on other workspace packages |
lib.new | Make a package from the template |
lib.audit | Compare each package with the template |
lib.rename | Rename a package in each file of the workspace |
lib.graph | Give the dependency graph of the workspace packages, with its cycles |
lib.importCycles | Give the import cycles of a tree of TypeScript sources |
ecosystem.procedures | List the procedures of the packages |
Until October 2026, client-lib also had lib.install, lib.pull and lib.refresh, for one repository per package. The monorepo does not need them, and they are gone (DECISIONS-2026-10.md).
In version 0.3.0 and before, client-lib also had two runners of programs:
dag.traversemoved toclient-dag(@procedures/dag), with the same name. It gets the packages fromlib.scanof this package. Thus a host registers the two modules.core.catchis removed. It did the same asclient.tryCatchof@procedures/client. Useclient.tryCatch.
Use#
import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/lib/register"; // registers its procedures
import "@procedures/fs/register"; // lib.* reads and writes files through fs.*
const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const { packages, warnings } = await client.exec(["lib", "scan"], {});
const audit = await client.exec(["lib", "audit"], {});
The root of client-lib does not register client-fs. Without fs.*, lib.scan gives no packages and a warning for each, and lib.new and lib.rename fail. mark and the bundles load client-fs.
From the command line:
node packages/mark/dist/cli.js lib scan
node packages/mark/dist/cli.js lib new my-package
node packages/mark/dist/cli.js lib audit
node packages/mark/dist/cli.js lib rename @procedures/old-name @procedures/new-name --dry-run
The workspace root#
Each procedure takes an optional rootPath. Without it, the root is the pnpm workspace that contains client-lib. With it, the folder must contain pnpm-workspace.yaml. Before, lib.new started a script from any folder that rootPath named (deep dive DATA-18).
lib.scan#
Input: rootPath. The output has packages, a record by package name, and warnings. Each package gives name, repoPath, mark1russell7Deps (its dependencies in the ecosystem scopes @procedures/ and @mark1russell7/), currentBranch and gitRemote.
lib.new#
Input: name (without the scope), preset (default lib), rootPath and dryRun.
The procedure makes packages/<name>. It starts cue-config init and cue-config generate, and it writes src/index.ts, src/register.ts and src/types.ts. It also sets the client.procedures field and adds a workspace:* dependency on client. Then start pnpm install and pnpm build. cue-config needs the CUE binary.
The new package joins the fixed group of @procedures/client in .changeset/config.json, and it gets the version of that group. The packages of a fixed group share one version, and the package check fails on two versions. A release can change the version of the group before the merge of the new package. So before the merge, merge main and set the version again.
The output gives success, packageName, packagePath, created, operations and errors.
lib.audit#
Input: rootPath and fix. For each package, the output gives the files and the folders of the template that are missing, and the problems of its pnpm configuration. With fix: true, the procedure makes the missing folders, and the missing files that have a default content.
The output also has flagNotices: the procedure flags whose short form is also a global flag of mark. After the command path, the flag of the procedure wins (deep dive CLI-7).
The output also has procedureIssues. It has one issue of the kind missing-effects for each procedure without metadata.effects. A host with a capability refuses such a procedure. procedure new writes no effects, so the author writes them.
- The issues are warnings. They do not change
success, so the audit step of CI does not fail for them. - The audit examines the procedures of the registry of the host. It does not import the code of a package.
markloads its registry from the built./moduleentry of each package. Thus startpnpm buildbefore the audit. The audit does not examine a package without a build.
lib.rename#
Input: oldName, newName, rootPath and dryRun. The procedure changes the package name, the dependencies, the imports and the dynamic imports in the workspace. The output lists each change and gives a summary.
lib.graph#
Input: rootPath. The procedure reads the package.json of each folder in packages/ through fs.readdir and fs.read.json. It changes nothing.
nodeshas one item for each package:name,folder,versionandprivate.edgeshas one item for each dependency with aworkspace:specifier:from,to,kindandspec. The kinds aredependencies,devDependencies,peerDependenciesandoptionalDependencies.cycleslists each cycle as the names of its packages. A package that depends on itself is also a cycle.acyclicis true when the list is empty.levelsis the build order of a graph without a cycle. The packages of level 0 depend on no workspace package. Each package of a level depends only on packages of lower levels.warningslists the folders that the procedure cannot read, and eachworkspace:dependency on a name that is not in the workspace.
node packages/mark/dist/cli.js lib graph
lib.importCycles#
The import cycles of the TypeScript sources under a folder. The default mode counts the cycles that exist at runtime: TypeScript's import elision drops an import of types only, as the build drops it.
| Mode | The edges |
|---|---|
runtime (the default) | The imports after the elision, and the injection tokens of the decorators in diDecorators |
declared | Each import that the source does not declare type-only (import type) |
raw | Each import statement |
node packages/mark/dist/cli.js lib importCycles packages/web/src
- For Angular, give
diDecoratorsthe value ofANGULAR_DI_DECORATORS. The class of such a decorator keeps the types of its constructor parameters at runtime. - The default
excludeleaves outnode_modules, the declarations and the tests. limitskeeps a call small:maxFiles(default 20000) refuses a folder with more files before a read, andmaxFileBytes(default 1 MiB) skips a larger file. The result lists each skipped file inskipped.- The defaults are the ceiling. A caller can give lower limits, and the input refuses a higher value.
- An abort of the call stops the reads and the analysis.
importCycles(sources, options)andimportGraph(sources, options)take the sources as text, for a caller that reads its own files.findCycleskeeps its own stack, so a long chain of imports does not overflow the call stack.
ecosystem.procedures#
Input: rootPath, namespace and includeMetadata. The output lists the procedures of the packages that have a client.procedures field.
Related packages#
client-dag: the graph algorithms oflib.graph, and the proceduredag.traverse, which useslib.scan.client-procedure:procedure.new, the scaffold of a procedure.mark: the CLI that starts these procedures.