You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also write custom plugins to extend the functionality to fit what your project needs. You can extract custom JSDoc tags for example, or implement support for a new Web Component library.
387
396
388
-
> You can use the [online playground](https://custom-elements-manifest.netlify.app/) for quickly prototyping plugin ideas, right in the browser
397
+
> ✨ **TIP:**You can use the [online playground](https://custom-elements-manifest.netlify.app/) for quickly prototyping plugin ideas, right in the browser
389
398
390
-
A plugin is a function that returns an object. There are several hooks you can opt in to:
399
+
A plugin is a function that returns an object. You can read about plugins in more detail in the [authoring plugins documentation](docs/plugins.md). There are several hooks you can opt in to:
391
400
392
401
-**collectPhase**: First passthrough through the AST of all modules in a project, before continuing to the `analyzePhase`. Runs for each module, and gives access to a Context object that you can use for sharing data between phases, and gives access to the AST nodes of your source code. This is useful for collecting information you may need access to in a later phase.
393
402
-**analyzePhase**: Runs for each module, and gives access to the current Module's moduleDoc, and gives access to the AST nodes of your source code. This is generally used for AST stuff.
394
403
-**moduleLinkPhase**: Runs after a module is done analyzing, all information about your module should now be available. You can use this hook to stitch pieces of information together.
395
404
-**packageLinkPhase**: Runs after all modules are done analyzing, and after post-processing. All information should now be available and linked together.
396
405
397
-
> **TIP:** When writing custom plugins, [ASTExplorer](https://astexplorer.net/#/gist/f99a9fba2c21e015d0a8590d291523e5/cce02565e487b584c943d317241991f19b105f94) is your friend 🙂
406
+
> ✨ **TIP:** When writing custom plugins, [ASTExplorer](https://astexplorer.net/#/gist/f99a9fba2c21e015d0a8590d291523e5/cce02565e487b584c943d317241991f19b105f94) is your friend 🙂
398
407
399
-
For a reference implementation of a plugin, you can take a look at the [Stencil plugin](/plugins/stencil.js), here's an example of a simpler plugin, that adds a custom JSDoc tag to a members doc:
400
-
401
-
Example source code:
402
-
```js
403
-
404
-
exportclassMyElementextendsHTMLElement {
405
-
/**
406
-
* @foo Some custom information!
407
-
*/
408
-
message =''
409
-
}
410
-
```
408
+
To get started developing custom plugins, take a look at the [cem-plugin-template](https://github.com/open-wc/cem-plugin-template) repository to quickly get you up and running. Also take a look at the [authoring plugins documentation](docs/plugins.md).
411
409
412
410
`custom-elements-manifest.config.mjs`:
413
411
```js
414
412
exportdefault {
415
413
plugins: [
416
414
{
415
+
// Make sure to always give your plugins a name, this helps when debugging
416
+
name:'my-plugin',
417
417
// Runs for all modules in a project, before continuing to the `analyzePhase`
418
418
collectPhase({ts, node, context}){},
419
419
// Runs for each module
420
-
analyzePhase({ts, node, moduleDoc, context}){
421
-
// You can use this phase to access a module's AST nodes and mutate the custom-elements-manifest
> ✨ **TIP:** Make sure to check out the [cem-plugin-template](https://github.com/open-wc/cem-plugin-template) repository if you're interested in authoring custom plugins, and check the [authoring plugins documentation](docs/plugins.md) for more information.
478
431
479
432
## How it works
480
433
@@ -499,78 +452,35 @@ During the package link phase, we'll have all the information we need about a pa
499
452
- Finding a CustomElement's tagname by finding its `customElements.define()` call, if present
500
453
- Applying inheritance to classes (adding inherited members/attributes/events etc)
501
454
502
-
### Can I bring my own instance of TS?
503
-
504
-
No! Or well, you can. But that might break things. TypeScript doesn't follow semver, which means that there may be breaking changes in between minor or even patch versions of TypeScript. This means that if you use a different version of TypeScript than the analyzer's version of TypeScript, things will almost definitely break. As a convenience, plugin functions get passed the analyzer's version of TS to ensure there are no version incompatibilities, and everything works as expected.
505
-
506
-
## Overriding sourceFile creation
507
-
508
-
By default, `@custom-elements-manifest/analyzer` does _not_ compile any code with TS. It just uses the TS compiler API to create an AST of your source code. This means that there is no `typeChecker` available in plugins.
509
-
510
-
If you _do_ want to use the `typeChecker`, you can override the creation of modules in your `custom-elements-manifest.config.js`:
Because typescript doesn't follow semver, and may do breaking changes on minor or patch versions, typescript is bundled with the analyzer to avoid any typescript version mismatches.
0 commit comments