Rule 55 - Project: Workspace packages
Where a workspace package lives, what it exposes, and how code on either side of it imports.
Rules
55.1. A workspace package MUST live in its own kebab-case directory under packages/, and its package.json MUST name it semetrika-{directory}.
The root package.json lists packages/* as its workspaces and depends on each package by name at the version the package declares, so Yarn links node_modules/semetrika-{directory} to the package directory.
55.2. A package's package.json MUST set "type": "module" and an exports map. The map is the package's only public surface: a module it doesn't list stays private, and Node refuses to resolve it by package name.
{"name": "semetrika-spec","type": "module","exports": {".": "./src/index.js","./signatures": "./src/signatures.js"}}
55.3. Code outside a package MUST import it by package name, through an entry point its exports map lists. A relative path into the package directory skips the map, so it reaches private modules and breaks as soon as the package moves a file.
// Correct.import { componentSpec } from 'semetrika-spec';// Wrong.import { componentSpec } from '../../packages/spec/src/component-spec.js';
55.4. Code inside a package MUST NOT import a file outside the package directory. A package imports its own files by relative path, and Node built-ins, its dependencies and its own entry points by name.
// Correct - a module under packages/spec/src/.import { defineFields } from './internal/define.js';// Wrong - the package now depends on the project that uses it.import { Capability } from '../../../spec/spec.js';
55.5. A package's tests MUST sit where the Rule 42.1 sibling lookup finds them: beside the module they cover (packages/spec/src/facets.test.js), or in a tests/ tree that mirrors the source tree (packages/cli/tests/src/lib/argv.test.js covers packages/cli/src/lib/argv.js). Their fixtures build what the tests need from the package itself, so the tests pass without the project that uses the package. A package covered by 55.6 is the exception, because the project is what its tests are about.
55.6. A package whose subject is the project hosting it - one that lints the tree, reads its registry, or produces its artifacts - MAY read the project's own modules, and MUST do so by resolving them against the root it is pointed at, from a single module that names every such read. A read whose path a command computes at run time (a component's {name}.spec.js, the token registries a bundle assembles) goes through that module's loader, bound to the root the command was handed, rather than through an import of its own.
The prohibition in 55.4 is unchanged: no relative path leaves the package. What the seam adds is direction. A tooling package binds to the tree it is given rather than to the one it sits in, which is what lets its runners take a root option and report on a fixture directory instead of the repository. A second module reaching for the project directly would leave that binding untraceable.
packages/cli/src/lib/project.js is the CLI's seam. It resolves spec/spec.js and the icon sprite builder against ROOT and re-exports what the rules and commands read.
// Correct - resolved against the root the package was pointed at.const spec = await import(pathToFileURL(resolve(ROOT, 'spec/spec.js')).href);// Wrong - a relative path out of the package, whatever it reaches for.import { Capability } from '../../../../spec/spec.js';
55.3, 55.4, 55.6 by yarn cli 55 (findPathImportsIntoPackages, findImportsLeavingPackage, findSeamBypasses in packages/cli/src/rules/55.js). 55.1, 55.2, 55.5 are review only. See enforcement.md.