workspace-conformance
Conformance checks for a pnpm workspace that ESLint cannot express. Type-graph checks run on ts-morph, import-graph checks run on dependency-cruiser with rules generated from the shared layout section of @exadev/config, file-tree and cross-config checks compare two files or read git state, workflow checks read GitHub Actions files, and settings checks read the repository's settings through the GitHub API. Each check reports violations with a stable code, a message and what the violation is about: a file and, where it has one, a position, or for the settings checks the repository.
It complements the workspace architecture rules of @exadev/eslint-config, it does not replace them. Those rules run in the editor and check what package.json files declare (no-uphill-dependency and no-dependency-cycle), incrementally and one file at a time. This tool checks what the code does: the import statements that actually cross packages, whether written as a package name, a relative path or a path alias, and everything that needs two files, the type checker or git. Both read the same layout section, so one description of the workspace drives both. Naming (package-name-mirrors-path) and per-file lint stay in ESLint.
Getting started
pnpm add -D workspace-conformance '@exadev/config@^2.1.0' cosmiconfig 'typescript@^6'
@exadev/config provides withSections and layoutSection for the config file, and the tool loads its sections with it, so install the major this package depends on (^2.1.0): a different major installs a second copy, whose sections and errors are not the ones the tool reads. cosmiconfig (^9.0.0 || ^10.0.0) is a peer dependency because @exadev/config loads config files through it. typescript (^5.9.0 || ^6.0.0) is a peer dependency because dependency-cruiser needs it to parse TypeScript and supports versions below 7 (the range is in the install command because an unpinned typescript installs a newer major, which pnpm only warns about); the import checks fail with a configuration error when dependency-cruiser cannot load it. ts-morph bundles its own compiler and does not use yours. eslint (^9.0.0 || ^10.0.0) is an optional peer dependency, needed only by the eslint check, which uses the copy installed in the repository it checks. The package supports the Node lines dependency-cruiser and its own dependencies support: 22.13 and later 22, 24, and 26 and later.
Configure the checks in exadev.config.ts:
import { layoutSection, withSections } from '@exadev/config';
import { conformanceSection } from 'workspace-conformance';
export default withSections(layoutSection, conformanceSection)({
layout: {
groups: [
{ name: 'core', rank: 0 },
{ name: 'features', rank: 1, slice: { segment: 0 } },
{ name: 'product', rank: 2, slice: { segment: 0 } },
],
rankSkip: { maxDistance: 1, exemptRanks: [] },
},
conformance: {
checks: {
'import-uphill': {},
'import-rank-skip': {},
'import-cross-slice': {},
'import-cycles': {},
'instruction-symlinks': {},
'aggregate-mappers': {
contracts: ['product/*/contract/src/aggregates.ts'],
adapters: '{dir}/../../adapters/*',
mapper: '{adapter}/src/{name}.mapper.ts',
},
'command-types': { commands: ['product/*/contract/src/commands.ts'], exclude: ['Command'] },
},
},
});
Then run it:
pnpm exec workspace-conformance check
Configuration
The tool reads two sections through @exadev/config, each from exadev.config.ts under its key or from a standalone exadev.<section>.config.ts in the working directory, never both. See that package for extends, presets and how a section is found.
layout is the shared layoutSection. The import checks read it: groups (with path, rank, slice), nameRanks, defaultRank, rankSkip, isolatedGroups, dependencyFields, and where the packages are (root, packages, or the packages list of pnpm-workspace.yaml). Checks that do not read the layout need no layout section.
conformance is conformanceSection. Its checks map decides what runs: a check whose name is present with an options object runs ({} for the defaults), and false switches it off, which lets a config that extends another turn one of its checks off. A key that is not a check name, or an option a check does not have, fails when the section loads.
runChecks and the command line fail with exit status 2 when no check is enabled, so an empty section never reads as a pass.
How the layout maps to packages
Packages are the directories that the packages globs select and that hold a package.json. The root package is one when a glob selects it (.), which is how a single-package repository is described: packages: ['.'] with a group whose path is ., so import-cycles judges the files of the one package. Since every other package directory is inside the root, the root package cannot be a package beside others. Each belongs to the group whose root is the longest prefix of its directory, and takes its rank from the first matching nameRanks pattern, else its group's rank, else defaultRank. A segment slice is the path segment below the group root; a namePrefix slice is the longest slice value produced by a segment group that prefixes the package's unscoped name. These are the same rules the ESLint architecture rules apply.
The tool fails loudly, with a configuration error, on what it cannot judge: globs that select no package, a package directory no group owns, package directories nested inside one another, a rank check when some package resolves no rank, and a check that needs rankSkip, isolatedGroups or a slice when the layout has none.
Checks
workspace-conformance check --list prints the names. Violation codes are <check>/<reason> and are stable; messages may change. Paths in options are relative to the working directory and use /. Every search by glob skips node_modules, git's own data and any other checkout below the working directory (a directory with its own .git, such as a linked worktree), so a copy of the repository nested in the tree is not judged as part of it.
Import graph
The import checks generate dependency-cruiser rules from the layout in a pure function, cruise the packages' files, and read summary.violations. Every enabled import check adds its rules to a single cruise, and the findings are split back to the checks by rule name; checks whose exclude, doNotFollow and tsConfig are equal (after defaults) share a cruise, and checks that differ in any of them are cruised separately, since those options decide which files the graph contains. They never use the exit code of cruise(), which is 0 whatever it found. A rule cannot compare ranks, so the ordering is expanded into path alternations at generation time: one rule per rank, slice or group pair rather than per package pair.
All import checks take these options:
| Option |
Meaning |
exclude |
Regular expressions, as source text, for paths relative to the workspace root that are left out of the graph: neither a dependant nor a dependency. node_modules directories when omitted. Setting it replaces that default. A pattern that does not compile fails when the section loads. |
doNotFollow |
Regular expressions for paths whose files can be imported but whose own imports are not followed, so build output is a target of imports and never a dependant. dist directories when omitted. Setting it replaces that default. A pattern that does not compile fails when the section loads. |
tsConfig |
A tsconfig for path aliases and other module resolution. |
How an import is attributed to a package, and the limits of that:
- An import that dependency-cruiser resolves to a file counts against the package whose directory holds the file. A relative import resolves without an install, a path alias needs
tsConfig (paths without baseUrl resolves relative to that tsconfig, wherever the command runs), and a package name resolves through the node_modules link pnpm makes for a workspace package and the package's exports or main.
- An import of a workspace package by its name (or a subpath of it) that resolves to no file, because the workspace is not installed or the package's entry point is not built, is attributed to the package by name. An import that neither resolves nor names a workspace package, such as an alias without
tsConfig that is not a package name, is not seen, so a check can look cleaner than the workspace is; give tsConfig when aliases are used.
import-cycles follows files, so it cannot follow an import that resolves to no file. It treats packages that import each other by such names as a cycle between the packages, and finds it only when every import in the ring is of that kind; a ring that mixes such imports with imports that resolve to files is not seen until the workspace is installed and built.
- Type-only imports and dynamic
import() count, because a type dependency is still a dependency.
- An import of a package that the importer declares only in
package.json fields the layout's dependencyFields does not read (dependencies alone by default, so a devDependencies entry by default) is not judged by import-uphill, import-rank-skip, import-cross-slice or import-isolated-groups, whether it is written as the package name, a relative path or an alias. The ESLint workspace rules read the same dependencyFields and never see such a declaration, so a test that imports a package declared for tests is exempt from both, and widening dependencyFields to ['dependencies', 'devDependencies'] brings it into both. A package declared in a field that is read, in any field alongside, or not declared at all is judged, since an undeclared import is what this tool exists to catch. import-cycles does not apply this: a ring of imports between files is a cycle whatever the manifests declare, and a file-level cycle that runs through a test file is one only when another file imports that test file.
- Test and tooling files inside a package are otherwise part of the package. Use
exclude for paths that may cross layers.
- dependency-cruiser supports TypeScript below 7. With a TypeScript it cannot load, or none, every import check fails with a configuration error and exit status 2 instead of reporting a clean workspace.
| Check |
Verifies |
import-uphill |
No package imports a package of a strictly higher rank. |
import-rank-skip |
No package imports one more than rankSkip.maxDistance ranks below it, except an exempt rank. Needs rankSkip in the layout. |
import-cross-slice |
No package imports a package with a different slice. A package without a slice is in none and is never restricted. Needs a slice in the layout. |
import-isolated-groups |
No package imports a package in a group that isolatedGroups pairs with its own, in either direction. Needs isolatedGroups. |
import-cycles |
No files of the workspace packages import each other in a cycle, and no packages import each other by names that resolve to no file. Each cycle is reported once, starting from its smallest path, and two different rings over the same files are two cycles. It includes type-only cycles. |
The ESLint rules and this tool overlap deliberately on rank, rank skip, slice and isolation; ESLint gives instant feedback on declared dependencies and this tool catches the imports that bypass a declaration.
Type graph
The type-graph checks build a ts-morph program from the files their options select and what those import, with compiler options from tsConfig (default tsconfig.json; its include is not used). ts-morph bundles its own TypeScript, so it does not follow your compiler version. Imports must resolve, which means dependencies need to be installed: a schema imported from an uninstalled package has no type.
aggregate-mappers verifies that every aggregate type a contract file exports has a mapper file where a template says.
| Option |
Meaning |
contracts |
Globs of contract files. Every exported interface and type alias in them is an aggregate. |
mapper |
Path template for one aggregate's mapper. Placeholders: {name}, {dir} (the contract's directory), {file} and, with adapters, {adapter}. .. segments are resolved. |
adapters |
Optional glob template (with {dir} and {file}) for adapter directories. Each aggregate then needs a mapper in every matched adapter, and a glob that matches nothing is itself a violation. |
exclude |
Names of exported types that are not aggregates. |
tsConfig |
See above. |
Codes: aggregate-mappers/missing-mapper (reported at the aggregate's declaration), aggregate-mappers/no-adapters. Limits: it checks that a file exists, not what is in it; a type re-exported by the contract counts as an aggregate, and a type re-exported under another name (export type { Created as CreatedAlias }) counts once for each name it is exported as, each needing a mapper, so helper types and aliases need exclude