|
| 1 | +import * as TS from 'typescript' |
| 2 | +import { Module, Package } from 'custom-elements-manifest/schema'; |
| 3 | + |
| 4 | +/** Plugin execution context. Pass arbitrary data here. */ |
| 5 | +export type Context = Record<string, unknown>; |
| 6 | + |
| 7 | +export interface CollectPhaseParams { |
| 8 | + /** |
| 9 | + * TypeScript API |
| 10 | + */ |
| 11 | + ts: TS; |
| 12 | + |
| 13 | + /** |
| 14 | + * The current TypeScript AST Node |
| 15 | + */ |
| 16 | + node: TS.Node; |
| 17 | + |
| 18 | + /** |
| 19 | + * Plugin execution context. Pass arbitrary data here. |
| 20 | + */ |
| 21 | + context: Context; |
| 22 | +} |
| 23 | + |
| 24 | +export interface AnalyzePhaseParams { |
| 25 | + /** |
| 26 | + * TypeScript API |
| 27 | + */ |
| 28 | + ts: TS; |
| 29 | + |
| 30 | + /** |
| 31 | + * The current TypeScript AST Node |
| 32 | + */ |
| 33 | + node: TS.Node; |
| 34 | + |
| 35 | + /** |
| 36 | + * The current state of the current module's manifest |
| 37 | + */ |
| 38 | + moduleDoc: Partial<Module>; |
| 39 | + |
| 40 | + /** |
| 41 | + * Plugin execution context. Pass arbitrary data here. |
| 42 | + */ |
| 43 | + context: Context; |
| 44 | +} |
| 45 | + |
| 46 | +export interface ModuleLinkPhaseParams { |
| 47 | + /** |
| 48 | + * The completed moduleDoc, i.e. the output of the analyze phase |
| 49 | + */ |
| 50 | + moduleDoc: Module; |
| 51 | + |
| 52 | + /** |
| 53 | + * Plugin execution context. Pass arbitrary data here. |
| 54 | + */ |
| 55 | + context: Context; |
| 56 | +} |
| 57 | + |
| 58 | +export interface PackageLinkPhaseParams { |
| 59 | + /** |
| 60 | + * The completed manifest, i.e. the output of the analyze phase |
| 61 | + */ |
| 62 | + customElementsManifest: Package; |
| 63 | + |
| 64 | + /** |
| 65 | + * Plugin execution context. Pass arbitrary data here. |
| 66 | + */ |
| 67 | + context: Context; |
| 68 | +} |
| 69 | + |
| 70 | +/** |
| 71 | + * A Custom Elements Manifest Analyzer plugin |
| 72 | + */ |
| 73 | +export interface Plugin { |
| 74 | + /** |
| 75 | + * @summary Plugin hook that runs in the collect phase. |
| 76 | + * |
| 77 | + * Runs for all modules in a project, before continuing to the `analyzePhase` |
| 78 | + */ |
| 79 | + collectPhase(params: CollectPhaseParams): void; |
| 80 | + |
| 81 | + /** |
| 82 | + * @summary Plugin hook that runs in the analyze phase. |
| 83 | + * |
| 84 | + * Runs for each AST node in each module. |
| 85 | + * You can use this phase to access a module's AST nodes and mutate the manifest. |
| 86 | + */ |
| 87 | + analyzePhase(params: AnalyzePhaseParams): void; |
| 88 | + |
| 89 | + /** |
| 90 | + * @summary Plugin hook that runs in the module-link phase. |
| 91 | + * |
| 92 | + * Post-processing hook that runs for each module, after analyzing. |
| 93 | + * All information about your module should now be available. |
| 94 | + */ |
| 95 | + moduleLinkPhase(params: ModuleLinkPhaseParams): void; |
| 96 | + |
| 97 | + /** |
| 98 | + * @summary Plugin hook that runs in the package-link phase. |
| 99 | + * |
| 100 | + * Runs once per package, after modules have been parsed and after per-module post-processing |
| 101 | + */ |
| 102 | + packageLinkPhase(params: PackageLinkPhaseParams): void; |
| 103 | +} |
0 commit comments