Skip to content

Commit 3fb7ae4

Browse files
authored
Merge pull request #3 from open-wc/docs/plugin-typings
docs: add typescript typings for plugin authors
2 parents f4f7d0c + 8711416 commit 3fb7ae4

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

packages/analyzer/index.d.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
}

packages/analyzer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "",
55
"license": "MIT",
66
"type": "module",
7+
"types": "index.d.ts",
78
"bin": {
89
"custom-elements-manifest": "./index.js",
910
"cem": "./index.js"

0 commit comments

Comments
 (0)