@cosyte/process
v0.1.11
Published
The shared per-repo process scripts for @cosyte/* repos: one `cosyte-process` bin behind build, test, lint, typecheck, format and check.
Maintainers
Readme
@cosyte/process
Five script bodies you never edit again, and the tool versions behind them.
The shared per-repo process scripts for @cosyte/* repos: one cosyte-process bin behind build, test, lint, typecheck, format and check.
Why this exists
Every parser repo hand-maintains the same five package.json scripts, plus a handful of variants,
plus the tool versions behind them. Sharing the CONFIG files still leaves the invocations copied, so
a repo can be on the shared ESLint config and a two-year-old ESLint, and the difference is invisible
until a rule behaves differently in one repository.
The nearest alternative is a shared config package plus hand-written scripts, which is where this
estate already was. @cosyte/process is the single source of truth for all of it: a consumer's
script body becomes cosyte-process <verb> and never changes again, and a shared change to what a
verb does, or to which version of a tool runs it, arrives as a version bump of this package and
pnpm install.
Status
@cosyte/process is on the Cosyte 0.1.x line: the public API is settled and bump types follow ordinary semver.
Still moving: the verb set itself (which verbs exist, and what each one invokes) and the override file's schema. Both are consumer-visible in a way a version bump can break, because a changed invocation runs different tooling over the same source. The five delegating script bodies are the part designed never to move.
Install
pnpm add -D @cosyte/processThe tools the verbs run (tsup, vitest and its @vitest/coverage-v8 provider, eslint, prettier,
typescript) are dependencies of this package, and every verb runs this package's copy. A wired
consumer declares one of them directly only when its own code imports it, pinned to the exact
version this package pins.
vitest is the usual case. Test files import describe, it and expect from vitest, and
cosyte-process typecheck needs those types to resolve from the consumer, so a consumer with tests
keeps vitest as a devDependency pinned exactly to the version this package pins, which in this
release is:
pnpm add -D --save-exact [email protected]cosyte-process test still runs this package's vitest, never the consumer's, and
cosyte-process check fails a direct vitest at any other specifier, a caret range included,
because it would type-check against one vitest and run another. Node >=22.22.2. ESM only.
Usage
Five scripts, each body exactly the delegation:
{
"scripts": {
"build": "cosyte-process build",
"test": "cosyte-process test",
"lint": "cosyte-process lint",
"typecheck": "cosyte-process typecheck",
"format": "cosyte-process format"
}
}Four reserved variant script names exist. Carry any subset of them, including none; each one you do carry has exactly this body:
{
"scripts": {
"test:watch": "cosyte-process test --watch",
"test:coverage": "cosyte-process test --coverage",
"lint:fix": "cosyte-process lint --fix",
"format:check": "cosyte-process format --check"
}
}Script bodies are never edited per repo. If a repo needs something different, that is what the override file below is for.
Two further invocations are not verbs: they are canonical script bodies a repo used to keep its own copy of, reached through the bin it already has.
cosyte-process sync-version [file] # write package.json's version into the exported VERSION constant
cosyte-process pack-docs [outputdir] # build docs-content.tar.gz and source.tar.gzWire either one where the script it replaces was wired:
{
"scripts": {
"sync-version": "cosyte-process sync-version",
"docs:artifacts": "cosyte-process pack-docs"
}
}Neither is graded by cosyte-process check, and neither is an overridable verb: the override file
takes no globs or flags for either. pack-docs has one option of its own in that file,
sourceFiles, under a pack-docs key (see cosyte-process pack-docs).
Carrying no script for either one is conforming, exactly as before they existed.
Entry points
| entry point | what it is |
| ----------------------- | -------------------------------------------------------------------------------- |
| cosyte-process | the bin, which is how a wired repo consumes this package |
| cosyte-docs-reference | the API reference generator for docs-content/api/, a second bin |
| @cosyte/process | the same contract programmatically: the baseline, the verbs and the wiring check |
The bin is the product; the module entry point exists so that the wiring check, the tests and any future tooling read the contract from one place instead of restating it:
import { BASELINE, expectedScriptBody, toArgv, VERBS } from "@cosyte/process";
toArgv(BASELINE.typecheck); // => ["tsc", "--noEmit"]
expectedScriptBody("build"); // => "cosyte-process build"
VERBS.includes("check"); // => trueNothing on that entry point has side effects, so importing it never runs a tool. It also publishes the canonical trigger surface of the two security-workflow callers as data, plus the grader that compares a caller's text against it (see the API section below).
Overrides
Repo-specific deviation lives in one file, cosyte-process.config.json, at the repo root:
{
"lint": { "globs": ["src/**/*.ts", "bin/**/*.ts"] },
"test": { "flags": ["--reporter=dot"] }
}The rules, in full:
- Top-level keys are verb names, among
build,test,lint,typecheck,format, pluspack-docsfor that entry point's own option (below).checkis never overridable. - Each verb's value is an object with optional
globsand optionalflags, each an array of strings. Thepack-docsvalue is an object with optionalsourceFiles, an array of non-empty strings. globsreplaces that verb's baseline glob tokens;flagsreplaces its baseline flag tokens. An absent key keeps the baseline tokens.- The tool name and the core tokens are never added, removed, replaced or reordered. A
testflags override of["--coverage"]yieldsvitest run --coverage, nevervitest --coverage. - No other keys at either level.
Any violation makes every verb exit non-zero, naming the file and the first violation, rather than silently running something else.
One common reason to reach for this: the baseline format globs name src/, test/, scripts/ and
the repo root. prettier fails on a pattern that matches nothing, so a repo with no scripts/
directory overrides format's globs rather than creating an empty directory. (lint carries
--no-error-on-unmatched-pattern and needs no such care.)
PHI and safety
This package runs your build, test, lint, typecheck and format tools. It processes no patient data itself: it does not read your source as data, and it neither logs, retains nor transmits anything of its own.
What it does do is spawn tools whose output goes to your terminal and to your CI log, so anything a test or a compiler prints is printed by the underlying tool, unchanged and unfiltered by this package. That is the consumer's surface to keep clean: a test that prints patient data prints it into CI, whichever runner invoked it.
API
What each verb runs
Absent an override, each verb executes exactly this in the invoking repo's working directory, and exits with the tool's own exit code:
| verb | invocation |
| ----------- | -------------------------------------------------------------------------------------------------------- |
| build | tsup |
| test | vitest run |
| lint | eslint --max-warnings=0 --no-error-on-unmatched-pattern "src/**/*.ts" "scripts/**/*.ts" "test/**/*.ts" |
| typecheck | tsc --noEmit |
| format | prettier --write "src/**/*.{ts,md}" "test/**/*.ts" "scripts/**/*.{ts,mjs}" "*.{json,md,yml}" |
| check | nothing: it verifies this repo's own wiring (see below) |
Your tool config files stay yours. tsup.config.ts, eslint.config.js, vitest.config.ts,
tsconfig.json and the prettier field in your package.json live in your repo and are what these
invocations pick up. What this package owns is which tool runs, at which version, with which
arguments.
The token partition
Every invocation splits into four parts, and the split is what the modifiers and the override file are defined against:
| verb | tool | core tokens | flag tokens | glob tokens |
| ----------- | ---------- | ----------- | ---------------------------------------------------- | ------------------ |
| build | tsup | | | |
| test | vitest | run | | |
| lint | eslint | | --max-warnings=0 --no-error-on-unmatched-pattern | the three patterns |
| typecheck | tsc | --noEmit | | |
| format | prettier | --write | | the four patterns |
An invocation is always emitted in that order: tool, core, flags, globs. Core tokens are the mode-selecting ones, and they survive everything.
Modifiers
Exactly four exist, at most one per invocation:
| invocation | effect |
| -------------------------------- | ------------------------------------------------ |
| cosyte-process test --watch | replaces the core token run with watch |
| cosyte-process test --coverage | appends --coverage after the flag tokens |
| cosyte-process lint --fix | appends --fix after the flag tokens |
| cosyte-process format --check | replaces the core token --write with --check |
A modifier composes over the effective invocation: the baseline as your override file has already
adjusted it. With a globs override on lint, lint --fix fixes your globs, not the baseline ones.
cosyte-process check
Run it in CI. It exits 0 when this repo's process wiring conforms:
- the five verb scripts are present and delegate exactly as above,
- every reserved variant script that is present delegates exactly as above (absent ones are fine),
cosyte-process.config.jsonis absent or valid,- a direct
vitest, indevDependenciesordependencies, is absent or exactly the version this package pins.
Otherwise it exits non-zero and names each violation. That scope, the five scripts, any present
reserved variants, the override file and a direct vitest, is exactly what "process wiring" means
here; nothing else in your package.json is graded.
{
"scripts": {
"check:process": "cosyte-process check"
}
}cosyte-process sync-version
Writes the invoking package's package.json version into the exported VERSION constant in
src/index.ts, or in the file named as its one argument, relative to the package root
(cosyte-process sync-version src/core/version.ts) for a package whose constant lives elsewhere.
The behavior is five numbered conditions, and the numbers are part of the surface:
every refusal names the condition it failed, and this is the text it names.
- The manifest's
versionis read. Missing, not a string, or empty is a refusal. - Exactly one declaration of the form
export const VERSION: string = "<value>";, anchored at column 0, is found anywhere in that file; the value runs to the first quote, so a line carrying anything after the declaration is not one. Zero matches is a refusal naming the rename; two or more is a refusal naming the ambiguity, because a declaration sitting inside a comment must not be rewritten ahead of the real one. A further declaration form may be added beside this one; this one is never narrowed. - The manifest string is spliced in literally. A version carrying
$&,$1or a backtick sequence is written character for character and is never interpreted as a replacement pattern. - The run is idempotent. A tree already at that version is not written to at all, and the run reports that it was already there.
- The exit vocabulary is closed:
0for a write and for an already-synced tree,1for every refusal under conditions 1 and 2.
It takes at most one argument, the source file, and no option. A file named absolute or reaching
outside the package through .. is refused before anything is read. Its reports and its diagnostics go to stderr and stdout stays empty; a
diagnostic names the file, the condition and the action available, and never echoes what it read: two
competing declarations are reported by line number.
A failure the five conditions do not describe, a source file that cannot be written to for instance,
is a refusal in that same shape rather than a crash: the path, the entry point, what the system
reported in structural terms (open failed with EACCES), the action available, and exit 1.
cosyte-process pack-docs
Builds two tarballs into an output directory, named by the first positional argument and defaulting
to dist-artifacts:
| archive | carries, at the tarball root |
| --------------------- | ------------------------------------------ |
| docs-content.tar.gz | the contents of docs-content/ |
| source.tar.gz | src/, package.json and tsconfig.json |
It fails fast. docs-content/intro.md, docs-content/sidebars.json, src/, package.json and
tsconfig.json are all checked, and both archives are built in memory, before the output directory
is created, so a run that refuses leaves nothing behind for a release job to pick up: exit 1, every
missing input named on stderr, no directory and no archive. A path the tarball format cannot carry
refuses the same way and names the member. Members are written in a stable order, with no directory
entries, so two runs over the same tree produce the same archive. Any other failure, an output path
that is already a file for instance, is a refusal in the same shape rather than a crash: the path,
the entry point, what the system reported in structural terms, and the action available.
Further files in source.tar.gz
sourceFiles, under pack-docs in cosyte-process.config.json, names further files to carry in
source.tar.gz, such as a dependency inventory an earlier release step wrote:
{
"pack-docs": { "sourceFiles": ["dist-artifacts/dependency-inventory.cdx.json"] }
}- Each path is relative to the package root, and each file lands at the tarball root under its file
name: the entry above becomes
dependency-inventory.cdx.jsonbesidepackage.json. - Each path is checked before anything is written, and the run refuses, naming the path, when it:
- does not exist;
- is absolute, or leaves the package root (
../inventory.json); - ends in a path separator (
build/inventory.json/), rather than be read as the file before it; - resolves outside the package root through a symlink, the file itself or a directory on the way;
- is not a regular file;
- would carry a name the archive already has:
src,package.json,tsconfig.json, or the file name of an earlier entry. Names are compared without regard to letter case, sobuild/Package.jsonis refused too: a case-insensitive filesystem would extract one over the other.
- A symlink that stays inside the package is followed, and the archive carries the file it points to under the link's name.
docs-content.tar.gzis never changed by the option.- Absent, or an empty list,
source.tar.gzis byte for byte what it was before the option existed.
A malformed option (not an array, or an entry that is not a non-empty string) refuses the run
naming the file, as it refuses every verb. pack-docs reads cosyte-process.config.json whenever
the file exists, so a file that is not valid JSON, or that breaks the schema anywhere, exits 1 under
pack-docs too, which ignored the file before the option existed.
cosyte-docs-reference
Generates the package's API reference from its TSDoc comments into docs-content/api/, the reference
the docs-content standard asks for (decision record 0006 in cosyte/config), and reports every export
with no TSDoc summary and every heading written in a TSDoc comment:
cosyte-docs-reference # write docs-content/api/
cosyte-docs-reference --check # write nothing; fail when the committed pages differIt runs TypeDoc and typedoc-plugin-markdown, dependencies of this package, over each entry point the
package's exports names: . is src/index.ts, and ./name is src/name/index.ts or src/name.ts.
It writes one page per module, with no source lines, so a page changes only when the public surface or
its comments do, and every page compiles as MDX. An export counts as documented when it, or one of its
signatures, has a TSDoc summary; members of an export are not checked. No tag hides an export: one
tagged @internal, @hidden or @ignore is in the pages and is checked like any other, so a symbol
is either documented or not exported. A comment holds no markdown heading (a line such as
## Notes, outside code), on an export or anywhere inside one: the page prints the comment as it is,
so the heading would sit in the page's outline among the generated ones and shift their anchors.
Write it as a bold line or a sentence instead. It runs where a repository overrides minimatch to 11:
TypeDoc 0.28 calls a minimatch method that version made private, and the generator gives TypeDoc's
copy of minimatch that method back before TypeDoc runs. Exit 0 clean, 1 a stale page, an undocumented
export or a heading in a comment (each named, with its kind and file), 2 the input could not be
read (no package.json, tsconfig.json or docs-content/, an export with no source, or TypeDoc
could not convert it).
The security-workflow trigger surface
A GitHub Actions workflow only runs when the file is in that repository's own .github/workflows/
directory, so each repo keeps its own codeql.yml and scorecard.yml. What is shared is what those
files have to SAY, published here as data with a grader over it:
import { gradeWorkflowText, SECURITY_WORKFLOW_SURFACES } from "@cosyte/process";
SECURITY_WORKFLOW_SURFACES["scorecard.yml"].schedule; // => ["27 3 * * 2"]
SECURITY_WORKFLOW_SURFACES["scorecard.yml"].pullRequest; // => null
gradeWorkflowText("name: Scorecard\n", SECURITY_WORKFLOW_SURFACES["scorecard.yml"]).length > 0; // => truegradeWorkflowText(text, surface) returns one finding per differing element, each naming the file
and the element; an empty array is a pass. A caller's uses names the shared workflow at any
published reference, by commit or by its workflows-YYYY-MM-DD-<12 hex> name
(PUBLISHED_WORKFLOWS_REFERENCE), since references move and every caller moves with them; @main
is refused. gradeWorkflowFile(path, surface) grades the file at a
path, and gradeSecurityWorkflows(repoRoot) grades both callers of a repository.
A pass means every element of the surface was found and was equal. That the file exists is not one of
the elements: a caller whose schedule: has been deleted is a file that exists and a scan that no
longer runs. scorecard.yml carrying no pull_request trigger is an element in the same way as
codeql.yml carrying one, so the two files are not interchangeable.
Updating
A shared-process change reaches a wired consumer as a dependency version bump plus pnpm install.
There is no other consumer-side edit for the five verbs: not to a script body, not to a tool version,
not to a config file. If a change to this package would require one, that is a bug in the change.
The one exception is a direct vitest kept for types: when a bump moves this package's vitest, the
consumer moves its pin to match, and cosyte-process check names the version until it does.
Compatibility
Node >=22.22.2 and pnpm 10.0.0 are the floor. Node 22.22.2 is the oldest the shipped tools run
on: tsup 9 needs 22.18, and eslint-plugin-jsdoc 65, which @cosyte/eslint-config brings, needs
22.22.2. The package is tested against exactly that floor, installed from a packed tarball into a
fixture outside this workspace.
Contributing
Questions, bug reports and proposals go to the issue tracker. Pull requests are welcome, in cosyte/config, where this package lives.
A change has to clear the required verify job, and a change to a verb's invocation or to the
override schema needs a changeset saying what moved: it changes what runs in every wired consumer.
License
MIT, copyright Cosyte LLC. See LICENSE.
