import fs from 'fs-extra'; import type { Node, Program, SourceFile } from 'typescript'; import { resolveConfigPaths, resolvePath, resolveRelativePath, } from '../utils/resolve.js'; import { ComponentMeta, HeritageMeta } from './ComponentMeta.js'; export type PluginFs = typeof fs & { resolvePath: typeof resolvePath; resolveRelativePath: typeof resolveRelativePath; resolveConfigPaths: typeof resolveConfigPaths; }; export interface Plugin { name: string; init?(program: Program): Promise; discover?(sourceFile: SourceFile): Promise; build?(node: ComponentRootNodeType): Promise; postbuild?( components: ComponentMeta[], sourceFiles: SourceFile[], ): Promise; link?( component: ComponentMeta, heritage: HeritageMeta, ): Promise; postlink?( components: ComponentMeta[], sourceFiles: SourceFile[], ): Promise; transform?(components: ComponentMeta[], fs: PluginFs): Promise; destroy?(): Promise; } export type PluginBuilder< ConfigType = unknown, ComponentRootNodeType extends Node = Node, > = (config?: ConfigType) => Plugin;