@elenajs/plugin-cem-tag 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +25 -0
  3. package/src/index.js +54 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ariel Salminen https://arielsalminen.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@elenajs/plugin-cem-tag",
3
+ "version": "0.0.2",
4
+ "description": "CEM analyzer plugin that copies custom JSDoc tags into the manifest.",
5
+ "author": "Elena <hi@elenajs.com>",
6
+ "homepage": "https://elenajs.com/",
7
+ "license": "MIT",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "type": "module",
12
+ "exports": {
13
+ ".": "./src/index.js"
14
+ },
15
+ "files": [
16
+ "src"
17
+ ],
18
+ "engines": {
19
+ "node": ">= 22"
20
+ },
21
+ "peerDependencies": {
22
+ "@custom-elements-manifest/analyzer": ">=0.10.0"
23
+ },
24
+ "gitHead": "0dc35402bc75dbe3bb71732f970548ca73e3cd1b"
25
+ }
package/src/index.js ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Returns the CEM class declaration and resolved tag name for a class node,
3
+ * or `undefined` if the node is not a registered custom element.
4
+ *
5
+ * @param {Partial<import("@custom-elements-manifest/analyzer").JavaScriptModule>} moduleDoc
6
+ * @param {import("typescript").ClassDeclaration} node
7
+ * @returns {{ class: import("@custom-elements-manifest/analyzer").Declaration; tagName: string } | undefined}
8
+ */
9
+ function getElenaElementDetails(moduleDoc, node) {
10
+ const declaration = moduleDoc.declarations?.find(d => d.name === node.name?.getText());
11
+ if (!declaration) {
12
+ return undefined;
13
+ }
14
+
15
+ const customElement = moduleDoc.exports?.find(
16
+ e => e.kind === "js" && e.declaration.name === declaration.name
17
+ );
18
+
19
+ if (!customElement) {
20
+ return undefined;
21
+ }
22
+
23
+ return { class: declaration, tagName: customElement.name };
24
+ }
25
+
26
+ /**
27
+ * CEM analyzer plugin that reads a non-standard JSDoc tag from each custom element class
28
+ * and writes its value onto the CEM class declaration under the same key.
29
+ *
30
+ * Used for Elena-specific tags like `@status` and `@displayName`.
31
+ *
32
+ * @see https://custom-elements-manifest.open-wc.org/analyzer/plugins/authoring/#example-plugin
33
+ * @param {string} tagName - The JSDoc tag name to extract (e.g. `"status"`, `"displayName"`).
34
+ * @returns {import("@custom-elements-manifest/analyzer").Plugin}
35
+ */
36
+ export function elenaTagPlugin(tagName) {
37
+ return {
38
+ name: `${tagName}-tag`,
39
+
40
+ analyzePhase({ ts, node, moduleDoc }) {
41
+ if (!ts.isClassDeclaration(node)) {
42
+ return;
43
+ }
44
+
45
+ const details = getElenaElementDetails(moduleDoc, node);
46
+ if (!details) {
47
+ return;
48
+ }
49
+
50
+ const [tag] = ts.getAllJSDocTags(node, t => t.tagName.getText() === tagName);
51
+ details.class[tagName] = tag && ts.getTextOfJSDocComment(tag.comment);
52
+ },
53
+ };
54
+ }