interface SymbolTarget { /** Source file, when there is one; a layer that owns it wins over `module`. */ file: string | null; /** Package or virtual module, used when no layer owns `file`. */ module: string | null; } type SymbolMap = Map; /** * Each file of a component name, in Nuxt's order. A name can have more than one file: Nuxt keeps a * `.client`, a `.server` and a plain file with the same name, and uses one in the browser and one * on the server. */ type ComponentMap = Map; interface SymbolTable { imports: Record; components: ComponentMap; /** * The file of each layout name, and of each named route middleware. Only the registry has them: * the generated `.d.ts` files give the names but not the files. */ layouts?: SymbolMap; middleware?: SymbolMap; } type Severity = 'off' | 'warn' | 'error'; type RuleName = 'layer-boundary' | 'layer-cycle' | 'layer-internal' | 'unresolved-reference' | 'shadowed-component' | 'shadowed-layout' | 'shadowed-middleware' | 'shadowed-page' | 'shadowed-server-route' | 'shadowed-auto-import'; type PresetName = 'layered' | 'stacked' | 'features'; /** A preset with options. `base` names the layers that the others build on, lowest first. */ interface PresetOptions { name: PresetName; base?: string[]; } /** The Nuxt auto-import context a source file runs in. */ type Context = 'app' | 'server' | 'shared'; interface Layer { name: string; root: string; srcDir: string; serverDir: string; sharedDir: string; /** The Nuxt `dir.modules` dir of the layer. Not checked: Nuxt loads its files as modules. */ modulesDir: string; /** The Nuxt `dir.public` dir of the layer. Not scanned: it holds static assets. */ publicDir: string; /** Whether the layer uses Nuxt's default `/components` dir. */ defaultComponents: boolean; /** * Whether the layer scans the default auto-import dirs only: it does not set `imports.dirs` and * does not turn `imports.scan` off. Missing means the Nuxt default. */ defaultImports?: boolean; } /** `layout` and `middleware`: a name in `definePageMeta()` or `setPageLayout()`. */ type ReferenceKind = 'auto-import' | 'component' | 'import' | 'layout' | 'middleware'; interface Reference { file: string; line: number; column: number; kind: ReferenceKind; /** Identifier, component name, import specifier, or layout or route middleware name. */ symbol: string; } interface Edge extends Reference { fromLayer: string; /** `null` when the target is outside every layer. */ to: string | null; toLayer: string | null; /** Package or virtual module name for targets outside every layer. */ external: string | null; /** `import` edges: the names the statement imports, with `default` and `*` as written. */ names?: string[]; /** * `import` edges: the places of the other imports of the same specifier in the file. The edge * stands for all of them, so a finding is one for each file and specifier, but a move must * rewrite each import. */ sites?: { line: number; column: number; }[]; } type SuggestionAction = 'move' | 'allow' | 'expose' | 'leave'; /** What a suggestion changes, in counts that `check` can confirm. */ interface SuggestionImpact { /** Boundary findings cleared. */ fixes: number; /** move: files that use the moved file. */ files?: number; /** move: explicit imports that need a new specifier. */ imports?: number; /** allow: edges added to the `allow` map. */ edges?: number; } interface Suggestion { action: SuggestionAction; message: string; /** move: the layer to move the file to, and where it lands. */ layer?: string; file?: string; /** allow: the names a scoped entry would list, when the whole layer is not needed. */ only?: string[]; /** expose: the entry to add to the `expose` list of the layer. */ expose?: string; impact: SuggestionImpact; } interface Finding { rule: RuleName; severity: Exclude; file: string; line: number; column: number; symbol: string; fromLayer: string; toLayer: string | null; /** File the symbol resolves to, when known. */ target: string | null; /** Layers `fromLayer` may use whole, for `layer-boundary` findings. */ allowed?: string[]; /** Layers `fromLayer` may use only in part, for `layer-boundary` findings. */ scoped?: ScopedAllow[]; /** What `toLayer` makes public, for `layer-internal` findings. */ exposed?: string[]; /** For unresolved-reference: true when layerscope parsed the file but could not read a part of it. */ unread?: true; message: string; /** Set on `layer-boundary` findings. */ suggestion?: Suggestion; } /** A layer that may be used only in part: names, or globs on the file path in the layer. */ interface ScopedAllow { layer: string; only: string[]; } type AllowEntry = string | ScopedAllow; interface LayerRule { /** Layers this layer may depend on. Layers missing from config are unrestricted. */ allow?: AllowEntry[]; /** What other layers may use of this layer: names or globs. Without it, all of it is public. */ expose?: string[]; /** Layer root relative to the project root; names a layer or declares it without @nuxt/kit. */ path?: string; /** The `extends` source of a remote layer (`github:org/repo`); names the layer c12 cloned from it. */ source?: string; } type TypeImports = 'check' | 'ignore'; interface LayerscopeConfig { /** Fills `allow` for layers that do not set it. */ preset?: PresetName | PresetOptions; layers?: Record; rules?: Partial>; /** Globs relative to each scanned dir. */ ignore?: string[]; /** Identifiers and component names never reported as unresolved. */ globals?: string[]; /** * `check` (default): a type-only import is a dependency like any other. `ignore`: it makes no * edge, so no rule reports it. */ typeImports?: TypeImports; /** Relative to the project root. Defaults to `.nuxt`. */ buildDir?: string; /** * Baseline file, relative to the project root. Defaults to `layerscope-baseline.json`. The * `--baseline` option and the `baseline` input of the action override it. */ baseline?: string; } /** * `registry`: `.nuxt/layerscope/registry.json`, written by the `nuxt-layerscope` Nuxt * module. `types`: the generated `.d.ts` files, used when the module is not installed. */ type ResolutionSource = 'registry' | 'types'; /** `auto` reads the registry when the Nuxt module wrote one, and the `.d.ts` files otherwise. */ type SourceOption = ResolutionSource | 'auto'; /** * A finding counts by rule, file, symbol and target layer, never by line. A `layer-cycle` finding * counts without its file. */ interface BaselineEntry { rule: RuleName; /** Relative to the project root. */ file: string; symbol: string; toLayer: string | null; /** How often the key occurs; defaults to 1. */ count?: number; } interface BaselineResult { file: string; /** Findings present in the baseline, left out of `findings`. */ suppressed: Finding[]; /** Entries that no longer occur and can be removed with `--update-baseline`. */ removable: BaselineEntry[]; } interface UnreadFile { file: string; /** Short reason, for the `unused` report: `Could not parse file`, `import() with a dynamic path`. */ reason: string; } /** What the registry recorded of the scans of Nuxt and Nitro. The move suggestions read it. */ interface ScannedDirs { /** Each dir that Nuxt or Nitro scans for auto-imports, with the files that the scan matched. */ importDirs: { dir: string; files: string[]; }[]; /** Each component that Nuxt found, the shadowed ones too. */ components: { name: string; file: string; }[]; } interface AnalyzeResult { rootDir: string; /** * The dirs and the components of the registry. Missing without the registry: the move * suggestions then read only the default dirs of Nuxt. When the module could not read the dirs, * `importDirs` is empty and the components are still there. */ scanned?: ScannedDirs; /** Layers whose `allow` the preset gave, because the config gave them none. */ presetLayers?: string[]; /** The project options as the config set them, before a preset adds its own `layers`. */ declaredConfig?: Partial; /** The registry file that the `nuxt.config` options were read from, when there is one. */ recordedFile?: string; /** The config that applied: `layerscope.config.*` or the `layerscope` key of `nuxt.config`. */ config: LayerscopeConfig; source: ResolutionSource; /** File the symbols were read from. */ sourceFile: string; layers: Layer[]; files: string[]; edges: Edge[]; findings: Finding[]; /** Things the user should know about the run, such as rules that could not run. */ notes: string[]; /** * Every auto-import and component Nuxt registered, by context. With the registry, also the * layouts and the named route middleware. */ symbols: SymbolTable; /** * Files rendering a component chosen at runtime (``, ``, * `resolveComponent(x)` or `resolveDynamicComponent(x)`). */ dynamicComponentFiles: string[]; /** * Files of global components: Vue can render one by a name chosen at runtime. With the `.d.ts` * files, only the components in a `components/global/` dir or with a `.global` suffix. */ globalComponentFiles: string[]; /** The project uses Nuxt Content, which can render any component by its name from a content file. */ nuxtContent: boolean; /** * The edges of files that the rules do not check, but that can use a symbol: `nuxt.config.*`, * local modules, files of extra auto-import dirs and the project files that they import. Only * `unused` reads them. Empty when the run is limited to some files. */ extraEdges: Edge[]; /** * The uses in type positions (`typeof x`, and `import type` when `typeImports` is `'ignore'`). * Only `findUnused` reads them. */ typeEdges: Edge[]; /** Files with code that layerscope cannot read: their uses are missing from `edges`. */ unreadFiles: UnreadFile[]; /** Set when a baseline was applied; `findings` then holds only the new ones. */ baseline?: BaselineResult; } declare function defineConfig(config: LayerscopeConfig): LayerscopeConfig; export { SuggestionAction as C, SymbolTable as D, UnreadFile as E, Suggestion as S, TypeImports as T, RuleName as _, BaselineResult as a, Severity as b, Finding as c, LayerscopeConfig as d, PresetName as f, ResolutionSource as g, ReferenceKind as h, BaselineEntry as i, Layer as l, Reference as m, AllowEntry as n, Context as o, PresetOptions as p, AnalyzeResult as r, Edge as s, defineConfig as t, LayerRule as u, ScannedDirs as v, SuggestionImpact as w, SourceOption as x, ScopedAllow as y };