@systemfsoftware/api-extractor reads a TypeScript package's public API and judges the semver bump. A new tagged error on a returned Effect is a major change, not an invisible edit to a signature string.
From an unchanged api-extractor.json it writes the .api.md report, the release-trimmed .d.ts rollups, the .api.json doc model and tsdoc-metadata.json. Those outputs are compared against @microsoft/api-extractor. The same library compares two versions of the API and returns a verdict document.
npm install @systemfsoftware/api-extractor @effect/platform-nodeNode must be ^22.12.0, ^24.0.0, or >=26.0.0. Its two peers are effect@^4.1.7 and typescript@>=7.1.0-beta <8. npm and pnpm install a missing peer for you; if your project already depends on either, that copy is used.
pnpm add @systemfsoftware/api-extractor @effect/platform-node is the same install if the project already uses pnpm.
Read two versions of a package and print the verdict. Both packages need an export condition that points at TypeScript source. The default condition is @systemfsoftware/source.
import { NodeServices } from "@effect/platform-node";
import { FrontEnd, Verdict } from "@systemfsoftware/api-extractor";
import { Effect, Layer } from "effect";
const emitters = Layer.mergeAll(
FrontEnd.isolatedEmitterLayer,
FrontEnd.compilerEmitterLayer,
).pipe(
Layer.provideMerge(FrontEnd.operatingSystemFiles),
Layer.provideMerge(Layer.mergeAll(FrontEnd.declarationParserLayer, NodeServices.layer)),
);
const modelOf = (packageRoot: string) =>
FrontEnd.readPackage({ packageRoot }).pipe(
Effect.flatMap(FrontEnd.analyse),
Effect.map((analysis) => analysis.model),
);
const program = Effect.gen(function* () {
const before = yield* modelOf("before");
const after = yield* modelOf("after");
process.stdout.write(yield* Verdict.cell.run({ before, after }));
}).pipe(Effect.provide(emitters));
await Effect.runPromise(program);before and after are package roots. Each is a temporary folder whose package.json has an exports entry for "." with the @systemfsoftware/source condition pointing at ./src/mod.ts. before/src/mod.ts declares a NotFound tagged error class (an Error subclass with a _tag field) and export const loadUser = (id: string): Effect.Effect<{ readonly id: string }, NotFound>. after/src/mod.ts adds an exported Timeout tagged error class, and its loadUser returns Effect.Effect<{ readonly id: string }, NotFound | Timeout>. The document below is what the quick-start program writes for those two packages. Both took the isolated-declarations path. The engine stamp is this package's name@version.
{
"_tag": "Verdict",
"bump": "major",
"corpusVersion": "1.1.0",
"declarations": {
"after": "oxc-transform@0.160.0",
"before": "oxc-transform@0.160.0"
},
"engine": "@systemfsoftware/api-extractor@0.2.0",
"findings": [
{
"bump": "major",
"locations": [
".:loadUser/returns/E"
],
"next_action": "Declare a major bump: callers must now handle the new error, or remove it from the error channel.",
"reason_code": "E_WIDENED",
"rule_id": "e-widened-out"
},
{
"bump": "minor",
"locations": [
".:Timeout"
],
"next_action": "Declare at least a minor bump.",
"reason_code": "EXPORT_ADDED",
"rule_id": "export-added"
}
],
"schemaVersion": 1
}bump is none, patch, minor or major. Each finding names the rule, a reason code, the bump that rule requires, what to do next, and the locations in the model. A model that does not decode fails with SurfaceRejected. A corpus in which two rules match the same change fails with RuleCorpusRejected.
Rules are data. The shipped corpus is version 1.1.0: 61 rules over 33 kinds of change. The most specific matching rule wins. A change no rule covers is a major UNCLASSIFIED_CHANGE.
The corpus is corpus.v1.json. These are the Effect and Layer rows:
| Change | Reason code | Bump |
|---|---|---|
A tagged error joins the returned E channel |
E_WIDENED |
major |
A tagged error leaves the returned E channel |
E_TAG_REMOVED |
major |
The E channel of a parameter widens |
E_WIDENED_IN_INPUT |
minor |
The E channel of a parameter narrows |
E_NARROWED_IN_INPUT |
major |
The returned A channel widens |
A_WIDENED |
major |
The returned A channel narrows |
A_NARROWED |
minor |
The returned R channel widens |
R_WIDENED |
major |
The returned R channel narrows |
R_NARROWED |
minor |
A Layer stops providing a service |
LAYER_SERVICE_REMOVED |
major |
A Layer starts providing a service |
LAYER_SERVICE_ADDED |
minor |
A Layer gains a requirement |
LAYER_REQUIREMENT_ADDED |
major |
A Layer drops a requirement |
LAYER_REQUIREMENT_REMOVED |
minor |
A removed error tag is major because a caller's catchTag for that tag stops compiling. An added requirement is major because the caller must now provide it.
The model schema version is 4 (API_MODEL_SCHEMA_VERSION). The verdict document's own schemaVersion is 1. 0.1.1 shipped model schema version 2.
The command is api-extractor. With no arguments it runs in the current directory. init is the other command.
api-extractor init
api-extractor run
api-extractor run --local
api-extractor run --config ./api-extractor.jsoninit writes api-extractor.json and prints the path. If that file is already there, it writes the path to stderr and exits 1.
run takes an optional folder, then api-extractor.json in that folder. --config names another file. --local writes every artifact even when the committed report changed. Without --local, a changed report is not written: stderr gets api-extractor: the API report changed; run with --local to update it and the process exits 1.
A package with no api-extractor.json is read through its export map. Each subpath whose @systemfsoftware/source condition names a .ts file is an entry point. Pass another condition to FrontEnd.readPackage as sourceCondition when the source is not under that condition.
On a successful run --local the process prints <package name> <version>: wrote <count> artifact(s) and exits 0. Analysis messages go to stderr as <messageId>: <item>. Warnings fail the run unless --local is set; errors fail it either way.
api-extractor init in an empty directory prints Writing configuration file: and the absolute path of the new api-extractor.json, then exits 0. A second init in that directory prints <path> already exists on stderr and exits 1.
api-extractor run --local against a copy of the committed isolated-package fixture. In the copy, tsconfig.json is a copy of tsconfig.build.json, because the default project-folder lookup looks for that name. api-extractor init writes api-extractor.json, which enables the report, the doc model, the untrimmed and public rollups and TSDoc metadata. Delete its mainEntryPointFilePath line: init sets it to lib/index.d.ts, which this source-only fixture does not build, and the run stops with the "mainEntryPointFilePath" path does not exist. Without that line the entry points come from the export map. The run prints this to stdout:
Emit types with TypeScript Go
paper-lantern 1.0.0: wrote 6 artifact(s)
and this to stderr:
TypeScript Go is experimental. Some options will be unavailable.
ae-forgotten-export: archive.sealedOf
ae-missing-release-tag: shapes.draftSummary
It exits 0 and leaves five files in the copy: temp/paper-lantern.api.md, temp/paper-lantern.api.json, dist/paper-lantern.d.ts, dist/paper-lantern-public.d.ts and tsdoc-metadata.json. The report folder and the temp folder are the same path here, so the report is written twice; the six writes leave five files.
From the configuration init writes, a run produces:
| Output | Default path token |
|---|---|
| API report | <projectFolder>/temp/<unscopedPackageName>.api.md |
| Doc model | <projectFolder>/temp/<unscopedPackageName>.api.json |
| Untrimmed rollup | <projectFolder>/dist/<unscopedPackageName>.d.ts |
| Public rollup | <projectFolder>/dist/<unscopedPackageName>-public.d.ts |
| TSDoc metadata | tsdoc-metadata.json beside the types entry, or in the package root when the manifest has none |
newlineKind defaults to crlf when a config file is present, and to lf when the package has no config file. reportTempFolder receives every generated report on each run, whether or not it changed. reportFolder receives the report only with --local, and only when it changed.
Rollups are bundled, then trimmed by release tag into the untrimmed, alpha, beta and public variants whose paths are non-empty. The same pipeline is FrontEnd.extractPackage for a caller that already has the services.
Declarations are emitted two ways. A package whose exports are annotated takes oxc-transform isolated declarations. A package that is not isolated falls back to the TypeScript 7 compiler. Both routes build one model; producer.declarations records which emitter ran (oxc-transform@<version> or typescript@<version>).
The doc model keeps overloads, TSDoc links and enum member docs. The resolver reports all 19 ae-* message ids. Two ae-forgotten-export cases are exempt by shape, not by name: a heritage-only constructable helper the declaration itself emits, and a unique symbol or literal constant used only as a computed key. Every other reference that is not exported still reports.
no export resolves to a TypeScript source through its source condition
FrontEnd.readPackage found no export whose source condition names a .ts file. Pass another condition, for example FrontEnd.readPackage({ packageRoot, sourceCondition: "types" }), or add @systemfsoftware/source to the export.
<file>: <construct> is not supported
The declarations contain a construct the model cannot hold. The message names the file and the construct. The refusals are the refuse calls in declaration-graph.ts.
the compiler refused the package
The TypeScript 7 fallback ran and rejected the program. The following lines are the compiler diagnostics. typescript has to be installed for the host platform; it is a peer, not a dependency.
api-extractor: the "projectFolder" setting uses the "<lookup>" token, but no tsconfig.json was found in that folder or a parent
The config left projectFolder as <lookup>, and neither the package nor a parent directory contained tsconfig.json. The committed isolated-package fixture ships tsconfig.build.json only, and api-extractor run on that folder fails with this message until a tsconfig.json is present or projectFolder is set to a real path.
a surface or the corpus does not decode
Verdict.cell.run was given a value that is not an API model, or a corpus that is not the rule corpus. Produce models with FrontEnd.analyse, or decode them with ApiModel.decode.
api-extractor: the API report changed; run with --local to update it
run compared the new report with the committed file and refused to overwrite it. Re-run with --local when the change is intentional.
Apache-2.0. See LICENSE.