seams library
A source-level engine for package-boundary audits ("seams").
A repository states its boundaries as rules — which entry point may reach which package, which package may depend on which, where a name may be declared — and checks them against the source on every run, so a boundary is a check with an exit code rather than a sentence in a design document. This library is the engine those rules are written in; the rules themselves are the repository's.
- Reading source: directiveUris, stripDartComments, dartCodeWithoutComments, topLevelDeclarations, callArgumentsFrom.
- The import graph: importClosureOf, siblingImportClosureOf, externalImportsOf, reachableNamesOf, packageImportsUnder, exportedDeclarationsOf.
- The package graph: Pubspec, packagesIn, prefixedPackagesIn, resolvedPackagesOf, dependencyReach, declaredTypeNamesUnder.
- Rules: EntryPointRule with auditEntryPointRules; upwardPathDerivations for tests that count their way to a root.
- Running: SeamViolation, SeamAudit, runSeamAudits, resolveRepositoryRoot, resolveWorkspaceRoot.
Every check reads files; nothing here parses with the analyzer or runs a process, so an audit over a large repository runs in seconds.
Classes
- EntryPointRule
- What a single entry point may not reach.
- PublicDeclaration
- One public top-level declaration in an entry point's export namespace.
- Pubspec
-
A parsed
pubspec.yaml: the package name plus every declared dependency, across all three blocks. - SeamViolation
- One boundary crossing, named by the seam it belongs to.
- UpwardDerivation
- One place a source derives a directory by climbing.
Properties
- directiveLinePattern → RegExp
-
An
importorexportdirective on one line; group 1 is its URI.final
Functions
-
auditEntryPointRules(
String root, List< EntryPointRule> rules, {required String seam}) → List<SeamViolation> -
Checks every rule in
rulesagainst the packages underroot, reporting each crossing underseam. -
callArgumentsFrom(
String source, int open) → String -
The text between the parenthesis that ends at
openand its match. -
dartCodeWithoutComments(
String source) → String -
sourcewith its comments removed and everything else — string literals included — kept, newlines and all. -
declaredTypeNamesUnder(
String directory) → Set< String> -
The type names (
class,mixin,enum,extension,typedef) declared at the start of a line in any.dartfile underdirectory. -
dependencyReach(
Pubspec root, {required bool isBanned(String package), Map< String, Pubspec?> ? pubspecs}) → ({Map<String, List< reached, Set<String> >String> unresolved}) -
The packages
isBannedmatches thatrootreaches — each with the dependency chain that reaches it — and the hosted dependencies the walk could not follow becauserootwas never resolved. -
directiveUris(
String source) → Iterable< String> -
Every
import/exportURI insource, directives only. -
exportedDeclarationsOf(
String entryPoint) → Map< String, PublicDeclaration> -
The public declarations
entryPointexports, keyed by name: its own, its parts', and those of every file it re-exports within its package, withshow/hideapplied. -
externalImportsOf(
String entryPoint) → Set< String> -
The union of importClosureOf — what
entryPointlinks, in one set. -
importClosureOf(
String entryPoint) → Map< String, Set< String> > -
The import closure of
entryPointwithin its own package: every file reached, mapped to thedart:andpackage:URIs it directly names. -
packageImportsUnder(
String directory) → Map< String, List< String> > -
Every
package:import appearing anywhere underdirectory, mapped to the files that carry it. -
packageOf(
String uri) → String -
The package name of a
package:URI (package:kdbx/kdbx.dart→kdbx). -
packagesIn(
String root) → List< Pubspec> -
Every package directory directly under
rootthat carries apubspec.yaml. -
prefixedPackagesIn(
String workspaceRoot, String prefix, {int maxDepth = 3}) → List< Pubspec> -
Every package whose directory is named
prefix*underworkspaceRoot, searched tomaxDepthso a moved repository is found without walking the whole workspace. -
reachableNamesOf(
String entryPoint) → Set< String> -
What
entryPointlinks, named the way a rule names it: a package name forpackage:URIs, the bare library fordart:ones (dart:io). -
resolvedPackagesOf(
String packageDir) → Map< String, String> ? -
Package name → its root directory in the graph
pub getresolved for the package atpackageDir, read from.dart_tool/package_config.json. Null when the package has not been resolved. -
resolveRepositoryRoot(
String from) → String -
The repository: the nearest ancestor of
fromholding atom_repository.yaml. -
resolveWorkspaceRoot(
String from) → String -
The workspace: the nearest ancestor of
fromholding a.tom_metadatadirectory, which is what makes it the workspace. -
runSeamAudits(
{required List< SeamAudit> audits, required String repositoryRoot, required String workspaceRoot, required String holds, bool quiet = false, StringSink? out, StringSink? err}) → int -
Runs
auditsin order againstrepositoryRootandworkspaceRootand prints one line per audit toout—ok <label>, orFAIL <label>with each violation under it — thenholdswhen nothing crossed a boundary. Withquiet, passing audits and the roots are not printed. -
siblingImportClosureOf(
String entryPoint, String root, {required String followPrefix}) → Map< String, Set< String> > -
The import closure of
entryPointacross sibling packages: every file reached, mapped to the URIs it names that the walk did not follow. -
stripDartComments(
String source) → String -
sourcewith comments removed and line breaks preserved. -
topLevelDeclarations(
String source) → List< ({String kind, String name})> -
The top-level declarations of
source, public and private, in order. -
upwardPathDerivations(
String source) → List< UpwardDerivation> -
Every place
sourcederives a real directory by climbing a fixed number of levels.