@ui5/webcomponents-tools 0.0.0-07460127d → 0.0.0-093de5dd1
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.
- package/CHANGELOG.md +2440 -1
- package/LICENSE.txt +201 -0
- package/README.md +7 -10
- package/assets-meta.js +154 -0
- package/bin/dev.js +13 -1
- package/bin/ui5nps.js +274 -0
- package/components-package/eslint.js +66 -2
- package/components-package/nps.js +147 -48
- package/components-package/postcss.components.js +1 -21
- package/components-package/postcss.themes.js +1 -23
- package/components-package/vite.config.js +9 -0
- package/components-package/wdio.js +161 -73
- package/icons-collection/nps.js +80 -28
- package/lib/amd-to-es6/index.js +107 -0
- package/lib/amd-to-es6/no-remaining-require.js +33 -0
- package/lib/cem/cem.js +12 -0
- package/lib/cem/custom-elements-manifest.config.mjs +546 -0
- package/lib/cem/event.mjs +168 -0
- package/lib/cem/merge.mjs +220 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/cli.js +128 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/package.json +59 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/browser-entrypoint.js +23 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/create.js +117 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/arrow-function.js +26 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/class-jsdoc.js +157 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/classes.js +20 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createArrowFunction.js +17 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createAttribute.js +24 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClass.js +301 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClassField.js +26 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createFunctionLike.js +73 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createMixin.js +33 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createVariable.js +22 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/handlers.js +338 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/custom-elements-define-calls.js +90 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/exports.js +156 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/function-like.js +24 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/mixins.js +29 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/reexported-wrapped-mixin-exports.js +84 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/variables.js +34 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/collect-phase/collect-imports.js +101 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst/catalyst.js +11 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst/controller.js +34 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst-major-2/catalyst.js +11 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst-major-2/controller.js +34 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/decorators/attr.js +53 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/decorators/custom-element-decorator.js +36 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/fast/fast.js +7 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js +13 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/member-denylist.js +21 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/method-denylist.js +20 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/property-decorator.js +94 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/static-properties.js +121 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/utils.js +66 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/stencil/stencil.js +129 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/index.js +80 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/cleanup-classes.js +25 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/field-denylist.js +22 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/method-denylist.js +25 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/apply-inheritance.js +78 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/is-custom-element.js +34 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/link-class-to-tagname.js +27 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/remove-unexported-declarations.js +23 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/resolve-initializers.js +52 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/ast-helpers.js +186 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/cli-helpers.js +164 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/exports.js +44 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/find-external-manifests.js +67 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/imports.js +25 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/index.js +71 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/jsdoc.js +19 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/manifest-helpers.js +194 -0
- package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/mixins.js +112 -0
- package/lib/cem/schema-internal.json +1422 -0
- package/lib/cem/schema.json +1098 -0
- package/lib/cem/types-internal.d.ts +808 -0
- package/lib/cem/types.d.ts +736 -0
- package/lib/cem/utils.mjs +423 -0
- package/lib/cem/validate.js +76 -0
- package/lib/chokidar/chokidar.js +28 -0
- package/lib/copy-and-watch/index.js +153 -0
- package/lib/copy-list/index.js +34 -0
- package/lib/create-icons/index.js +131 -54
- package/lib/create-illustrations/index.js +204 -0
- package/lib/create-new-component/Component.js +74 -0
- package/lib/create-new-component/ComponentTemplate.js +12 -0
- package/lib/create-new-component/index.js +66 -93
- package/lib/css-processors/css-processor-components.mjs +92 -0
- package/lib/css-processors/css-processor-themes.mjs +102 -0
- package/lib/css-processors/scope-variables.mjs +49 -0
- package/lib/css-processors/shared.mjs +46 -0
- package/lib/dev-server/custom-hot-update-plugin.js +39 -0
- package/lib/dev-server/dev-server.mjs +78 -0
- package/lib/dev-server/virtual-index-html-plugin.js +56 -0
- package/lib/eslint/eslint.js +44 -0
- package/lib/generate-js-imports/illustrations.js +85 -0
- package/lib/generate-json-imports/i18n.js +91 -47
- package/lib/generate-json-imports/themes.js +63 -19
- package/lib/hbs2lit/index.js +2 -4
- package/lib/hbs2lit/src/compiler.js +30 -9
- package/lib/hbs2lit/src/includesReplacer.js +23 -17
- package/lib/hbs2lit/src/litVisitor2.js +125 -26
- package/lib/hbs2lit/src/svgProcessor.js +12 -5
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +40 -7
- package/lib/hbs2ui5/index.js +69 -30
- package/lib/i18n/defaults.js +79 -46
- package/lib/i18n/toJSON.js +54 -16
- package/lib/icons-hash/icons-hash.mjs +149 -0
- package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
- package/lib/remove-dev-mode/remove-dev-mode.mjs +51 -0
- package/lib/rimraf/rimraf.js +31 -0
- package/lib/scoping/get-all-tags.js +44 -0
- package/lib/scoping/lint-src.js +32 -0
- package/lib/scoping/missing-dependencies.js +65 -0
- package/lib/scoping/report-tags-usage.js +28 -0
- package/lib/scoping/scope-test-pages.js +41 -0
- package/lib/test-runner/test-runner.js +79 -0
- package/lib/vite-bundler/vite-bundler.mjs +35 -0
- package/package.json +64 -60
- package/tsconfig.json +18 -0
- package/bin/init-ui5-package.js +0 -3
- package/components-package/rollup.js +0 -134
- package/components-package/serve.json +0 -3
- package/lib/documentation/index.js +0 -143
- package/lib/documentation/templates/api-component-since.js +0 -3
- package/lib/documentation/templates/api-css-variables-section.js +0 -24
- package/lib/documentation/templates/api-events-section.js +0 -35
- package/lib/documentation/templates/api-methods-section.js +0 -26
- package/lib/documentation/templates/api-properties-section.js +0 -40
- package/lib/documentation/templates/api-slots-section.js +0 -28
- package/lib/documentation/templates/template.js +0 -38
- package/lib/init-package/index.js +0 -119
- package/lib/init-package/resources/.eslintignore +0 -3
- package/lib/init-package/resources/bundle.es5.js +0 -25
- package/lib/init-package/resources/bundle.esm.js +0 -34
- package/lib/init-package/resources/config/.eslintrc.js +0 -1
- package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
- package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
- package/lib/init-package/resources/config/rollup.config.js +0 -1
- package/lib/init-package/resources/config/wdio.conf.js +0 -1
- package/lib/init-package/resources/package-scripts.js +0 -11
- package/lib/init-package/resources/src/Assets.js +0 -6
- package/lib/init-package/resources/src/Demo.hbs +0 -1
- package/lib/init-package/resources/src/Demo.js +0 -56
- package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
- package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
- package/lib/init-package/resources/src/themes/Demo.css +0 -11
- package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
- package/lib/init-package/resources/test/pages/index.html +0 -51
- package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
- package/lib/jsdoc/config.json +0 -29
- package/lib/jsdoc/plugin.js +0 -2407
- package/lib/jsdoc/template/publish.js +0 -4092
- package/lib/postcss-css-to-esm/index.js +0 -33
- package/lib/postcss-css-to-json/index.js +0 -20
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { parse } from "comment-parser";
|
|
2
|
+
import {
|
|
3
|
+
getPrivacyStatus,
|
|
4
|
+
getDeprecatedStatus,
|
|
5
|
+
getSinceStatus,
|
|
6
|
+
getType,
|
|
7
|
+
getTypeRefs,
|
|
8
|
+
validateJSDocComment,
|
|
9
|
+
hasTag,
|
|
10
|
+
findTag,
|
|
11
|
+
findAllTags,
|
|
12
|
+
getReference,
|
|
13
|
+
normalizeDescription,
|
|
14
|
+
normalizeTagType,
|
|
15
|
+
logDocumentationError
|
|
16
|
+
} from "./utils.mjs";
|
|
17
|
+
|
|
18
|
+
const jsDocRegExp = /\/\*\*(.|\n)+?\s+\*\//;
|
|
19
|
+
const ASTFalseKeywordCode = 94;
|
|
20
|
+
|
|
21
|
+
const getParams = (ts, eventDetails, commentParams, classNode, moduleDoc) => {
|
|
22
|
+
return commentParams?.map(commentParam => {
|
|
23
|
+
const { typeName, name } = getType(normalizeTagType(commentParam?.type));
|
|
24
|
+
let type;
|
|
25
|
+
|
|
26
|
+
if (typeName) {
|
|
27
|
+
type = { text: typeName };
|
|
28
|
+
|
|
29
|
+
let typeRefs = name?.split("|")
|
|
30
|
+
?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path))
|
|
31
|
+
.filter(Boolean);
|
|
32
|
+
|
|
33
|
+
if (typeRefs?.length) {
|
|
34
|
+
type.references = typeRefs;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
type,
|
|
40
|
+
name: commentParam?.name,
|
|
41
|
+
_ui5privacy: "public",
|
|
42
|
+
description: normalizeDescription(commentParam?.description),
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function processEvent(ts, event, classNode, moduleDoc) {
|
|
48
|
+
const name = event?.expression?.arguments?.[0]?.text;
|
|
49
|
+
const result = {
|
|
50
|
+
name,
|
|
51
|
+
_ui5privacy: "private",
|
|
52
|
+
type: { text: "CustomEvent" }
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const comment = event.getFullText?.().match(jsDocRegExp)?.[0];
|
|
56
|
+
|
|
57
|
+
if (!comment) {
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const eventParsedComment = parse(comment, { spacing: 'preserve' })[0];
|
|
62
|
+
|
|
63
|
+
validateJSDocComment("event", eventParsedComment, name, moduleDoc);
|
|
64
|
+
|
|
65
|
+
const deprecatedTag = findTag(eventParsedComment, "deprecated");
|
|
66
|
+
const privacy = findTag(eventParsedComment, ["public", "private", "protected"])?.tag || "private";
|
|
67
|
+
const sinceTag = findTag(eventParsedComment, "since");
|
|
68
|
+
const commentParams = findAllTags(eventParsedComment, "param");
|
|
69
|
+
const description = normalizeDescription(eventParsedComment?.description);
|
|
70
|
+
const native = hasTag(eventParsedComment, "native");
|
|
71
|
+
const eventArgs = event?.expression?.arguments;
|
|
72
|
+
let eventBubbles;
|
|
73
|
+
let eventCancelable;
|
|
74
|
+
let eventDetails;
|
|
75
|
+
|
|
76
|
+
eventArgs && eventArgs.forEach(arg => {
|
|
77
|
+
arg.properties?.forEach(prop => {
|
|
78
|
+
if (prop.name?.text === "bubbles") {
|
|
79
|
+
eventBubbles = prop.initializer.kind === ASTFalseKeywordCode ? false : true;
|
|
80
|
+
} else if (prop.name?.text === "cancelable") {
|
|
81
|
+
eventCancelable = prop.initializer.kind === ASTFalseKeywordCode ? false : true;
|
|
82
|
+
} else if (prop.name?.text === "detail") {
|
|
83
|
+
eventDetails = prop.initializer?.properties;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
result.description = description;
|
|
89
|
+
result._ui5Cancelable = eventCancelable !== undefined ? eventCancelable : false;
|
|
90
|
+
result._ui5allowPreventDefault = result._ui5Cancelable;
|
|
91
|
+
result._ui5Bubbles = eventBubbles !== undefined ? eventBubbles : false;
|
|
92
|
+
|
|
93
|
+
if (native) {
|
|
94
|
+
result.type = { text: "Event" };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (privacy) {
|
|
98
|
+
result._ui5privacy = privacy;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (deprecatedTag?.name) {
|
|
102
|
+
result.deprecated = deprecatedTag.description
|
|
103
|
+
? `${deprecatedTag.name} ${deprecatedTag.description}`
|
|
104
|
+
: deprecatedTag.name;
|
|
105
|
+
} else if (deprecatedTag) {
|
|
106
|
+
result.deprecated = true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (sinceTag?.name) {
|
|
110
|
+
result._ui5since = sinceTag?.description
|
|
111
|
+
? `${sinceTag.name} ${sinceTag.description}`
|
|
112
|
+
: sinceTag.name;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const eventDetailType = classNode.members?.find(member => {
|
|
116
|
+
return ts.isPropertyDeclaration(member) && member.name.text === "eventDetails"
|
|
117
|
+
})?.type;
|
|
118
|
+
const eventDetailRef = eventDetailType?.members?.find(member => member.name.text === name) || eventDetailType?.types?.[eventDetailType?.types?.length - 1]?.members?.find(member => member.name.text === name);
|
|
119
|
+
const hasGeneric = !!event?.expression?.typeArguments
|
|
120
|
+
|
|
121
|
+
if (commentParams.length) {
|
|
122
|
+
if (eventDetailRef && hasGeneric) {
|
|
123
|
+
logDocumentationError(moduleDoc.path, `Event details for event '${name}' has to be defined either with generic or with eventDetails.`)
|
|
124
|
+
} else if (eventDetails) {
|
|
125
|
+
if (hasGeneric) {
|
|
126
|
+
const typesText = event?.expression?.typeArguments.map(type => type.typeName?.text).filter(Boolean).join(" | ");
|
|
127
|
+
const typeRefs = (getTypeRefs(ts, event.expression)
|
|
128
|
+
?.map(e => getReference(ts, e, event, moduleDoc.path)).filter(Boolean)) || [];
|
|
129
|
+
|
|
130
|
+
result.type = { text: `CustomEvent<${typesText}>` };
|
|
131
|
+
|
|
132
|
+
if (typeRefs.length) {
|
|
133
|
+
result.type.references = typeRefs;
|
|
134
|
+
}
|
|
135
|
+
} else if (eventDetailRef) {
|
|
136
|
+
const typesText = eventDetailRef?.type?.typeName?.text;
|
|
137
|
+
const typeRefs = (getTypeRefs(ts, eventDetailRef)
|
|
138
|
+
?.map(e => getReference(ts, e, event, moduleDoc.path)).filter(Boolean)) || [];
|
|
139
|
+
|
|
140
|
+
result.type = { text: `CustomEvent<${typesText}>` };
|
|
141
|
+
|
|
142
|
+
if (typeRefs.length) {
|
|
143
|
+
result.type.references = typeRefs;
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
logDocumentationError(moduleDoc.path, `Event details for event '${name}' must be described using generics. Add type via generics to the decorator: @event<TypeForDetails>("${name}", {details}).`)
|
|
147
|
+
}
|
|
148
|
+
} else if (eventDetailRef) {
|
|
149
|
+
const typesText = eventDetailRef?.type?.typeName?.text;
|
|
150
|
+
const typeRefs = (getTypeRefs(ts, eventDetailRef)
|
|
151
|
+
?.map(e => getReference(ts, e, event, moduleDoc.path)).filter(Boolean)) || [];
|
|
152
|
+
|
|
153
|
+
result.type = { text: `CustomEvent<${typesText}>` };
|
|
154
|
+
|
|
155
|
+
if (typeRefs.length) {
|
|
156
|
+
result.type.references = typeRefs;
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
logDocumentationError(moduleDoc.path, `Event details for event '${name}' must be described.`)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
result._ui5parameters = getParams(ts, eventDetails, commentParams, classNode, moduleDoc);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export default processEvent;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { pathToFileURL } from "url";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import { readFile, writeFile } from "fs/promises";
|
|
5
|
+
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
|
|
8
|
+
const UI5_BASE_CLASS = "UI5Element";
|
|
9
|
+
|
|
10
|
+
const main = async (argv) => {
|
|
11
|
+
let customElementsPath = null;
|
|
12
|
+
const CACHED_CEMS = new Map();
|
|
13
|
+
const DECLARATION_PACKAGE = new WeakMap();
|
|
14
|
+
const DECLARATION_MODULE = new WeakMap();
|
|
15
|
+
|
|
16
|
+
function removeInheritedFrom(obj) {
|
|
17
|
+
if (obj === null || typeof obj !== 'object') {
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (Array.isArray(obj)) {
|
|
22
|
+
return obj.map(item => removeInheritedFrom(item));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const result = {};
|
|
26
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
27
|
+
if (key === 'inheritedFrom') {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
result[key] = removeInheritedFrom(value);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function readPackageJson(filePath) {
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(await readFile(filePath, "utf-8"));
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw new Error(`Failed to read package.json at ${filePath}: ${error.message}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function loadPackageJson(depName) {
|
|
44
|
+
try {
|
|
45
|
+
// First try the standard require method (works when exports includes package.json)
|
|
46
|
+
const pkg = require(`${depName}/package.json`);
|
|
47
|
+
const pkgPath = require.resolve(`${depName}/package.json`);
|
|
48
|
+
return { path: path.dirname(pkgPath), pkg };
|
|
49
|
+
} catch (e) {
|
|
50
|
+
// If that fails, resolve the package path and read package.json directly
|
|
51
|
+
try {
|
|
52
|
+
const packagePath = require.resolve(depName);
|
|
53
|
+
let currentDir = path.dirname(packagePath);
|
|
54
|
+
|
|
55
|
+
// Navigate up to find package.json (the resolved path might be deep in dist/ or similar)
|
|
56
|
+
while (currentDir !== path.parse(currentDir).root) {
|
|
57
|
+
try {
|
|
58
|
+
const pkgPath = path.join(currentDir, 'package.json');
|
|
59
|
+
const content = await readFile(pkgPath, 'utf-8');
|
|
60
|
+
const pkg = JSON.parse(content);
|
|
61
|
+
|
|
62
|
+
// Verify this is the correct package.json by checking the name
|
|
63
|
+
if (pkg.name === depName) {
|
|
64
|
+
return { path: currentDir, pkg };
|
|
65
|
+
}
|
|
66
|
+
} catch {
|
|
67
|
+
// Continue searching up the directory tree
|
|
68
|
+
}
|
|
69
|
+
currentDir = path.dirname(currentDir);
|
|
70
|
+
}
|
|
71
|
+
} catch (resolveError) {
|
|
72
|
+
// console.warn(`Could not resolve ${depName}:`, resolveError.message);
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function collectThirdPartyCem() {
|
|
79
|
+
const packageJSONPath = path.resolve(process.cwd(), "package.json");
|
|
80
|
+
const packageJSON = await readPackageJson(packageJSONPath);
|
|
81
|
+
|
|
82
|
+
const dependencyKeys = Object.keys(packageJSON).filter(key => key.toLowerCase().includes("dependencies"));
|
|
83
|
+
const dependencies = dependencyKeys.flatMap(key => Object.keys(packageJSON[key]));
|
|
84
|
+
|
|
85
|
+
const thirdPartCEM = (await Promise.all(dependencies.map(async dep => {
|
|
86
|
+
const result = await loadPackageJson(dep);
|
|
87
|
+
if (!result?.pkg?.customElements) return null;
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
path: result.path,
|
|
91
|
+
name: dep,
|
|
92
|
+
cem: result.pkg.customElements
|
|
93
|
+
};
|
|
94
|
+
}))).filter(Boolean);
|
|
95
|
+
|
|
96
|
+
await Promise.all(thirdPartCEM.map(async dep => {
|
|
97
|
+
const cemPath = path.resolve(dep.path, dep.cem);
|
|
98
|
+
try {
|
|
99
|
+
const cemContent = JSON.parse(await readFile(cemPath, "utf-8"));
|
|
100
|
+
CACHED_CEMS.set(dep.name, cemContent);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.warn(`Failed to read CEM for ${dep.name} from ${cemPath}: ${error.message}`);
|
|
103
|
+
}
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function readCurrentCEM() {
|
|
108
|
+
const packageJSONPath = path.resolve(process.cwd(), "package.json");
|
|
109
|
+
const packageJSON = await readPackageJson(packageJSONPath);
|
|
110
|
+
|
|
111
|
+
if (!packageJSON?.customElements) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
customElementsPath = packageJSON.customElements;
|
|
116
|
+
const cemPath = path.resolve(process.cwd(), customElementsPath);
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const cemContent = JSON.parse(await readFile(cemPath, "utf-8"));
|
|
120
|
+
CACHED_CEMS.set(packageJSON.name, cemContent);
|
|
121
|
+
return cemContent;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
throw new Error(`Failed to read CEM from ${cemPath}: ${error.message}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function resolveReference(ref) {
|
|
128
|
+
const pkg = CACHED_CEMS.get(ref.package);
|
|
129
|
+
|
|
130
|
+
if (!pkg) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const mod = (pkg.modules || []).find(m => m.path === ref.module);
|
|
135
|
+
|
|
136
|
+
if (!mod) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const declaration = (mod.declarations || []).find(d => d.name === ref.name);
|
|
141
|
+
|
|
142
|
+
if (!declaration) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
DECLARATION_PACKAGE.set(declaration, ref.package);
|
|
147
|
+
DECLARATION_MODULE.set(declaration, ref.module);
|
|
148
|
+
|
|
149
|
+
return resolveDeclaration(declaration);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function resolveDeclaration(declaration) {
|
|
153
|
+
if (!declaration.superclass || declaration.superclass.name === UI5_BASE_CLASS) {
|
|
154
|
+
return [declaration];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const superclassDeclarations = await resolveReference(declaration.superclass);
|
|
158
|
+
return [declaration, superclassDeclarations].flat().filter(Boolean);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const merge = async () => {
|
|
162
|
+
const currentCEM = await readCurrentCEM();
|
|
163
|
+
if (!currentCEM) {
|
|
164
|
+
throw new Error("No custom elements manifest found in current project");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
await collectThirdPartyCem();
|
|
168
|
+
|
|
169
|
+
const modules = currentCEM.modules || [];
|
|
170
|
+
|
|
171
|
+
for (const mod of modules) {
|
|
172
|
+
const declarations = (mod.declarations || []).filter(d => d.kind === "class");
|
|
173
|
+
|
|
174
|
+
for (const declaration of declarations) {
|
|
175
|
+
const declarationHierarchy = await resolveDeclaration(declaration);
|
|
176
|
+
const allKeys = declarationHierarchy.flatMap(dec => Object.keys(dec));
|
|
177
|
+
const uniqueKeys = [...new Set(allKeys)];
|
|
178
|
+
const arrayKeys = uniqueKeys
|
|
179
|
+
.filter(key => !key.startsWith("_ui5"))
|
|
180
|
+
.filter(key => declarationHierarchy.some(dec => Array.isArray(dec[key])));
|
|
181
|
+
|
|
182
|
+
for (const key of arrayKeys) {
|
|
183
|
+
const allItems = declarationHierarchy.flatMap(dec => dec[key] || []);
|
|
184
|
+
|
|
185
|
+
// Remove duplicates based on name property
|
|
186
|
+
const seen = new Set();
|
|
187
|
+
declaration[key] = allItems.filter(item => {
|
|
188
|
+
if (!item.name) return true;
|
|
189
|
+
if (seen.has(item.name)) return false;
|
|
190
|
+
seen.add(item.name);
|
|
191
|
+
return true;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const cleanedCEM = removeInheritedFrom(currentCEM);
|
|
198
|
+
const outputPath = path.resolve(process.cwd(), customElementsPath);
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
await writeFile(outputPath, JSON.stringify(cleanedCEM, null, 2), "utf-8");
|
|
202
|
+
console.log(`Successfully merged CEM to ${outputPath}`);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
throw new Error(`Failed to write merged CEM to ${outputPath}: ${error.message}`);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
await merge();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const filePath = process.argv[1];
|
|
212
|
+
const fileUrl = pathToFileURL(filePath).href;
|
|
213
|
+
|
|
214
|
+
if (import.meta.url === fileUrl) {
|
|
215
|
+
main(process.argv)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export default {
|
|
219
|
+
_ui5mainFn: main
|
|
220
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
// Patch: Custom patch to not merge child parent privacy/type
|
|
6
|
+
// https://github.com/open-wc/custom-elements-manifest/pull/300
|
|
7
|
+
import { globby } from 'globby';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import commandLineArgs from 'command-line-args';
|
|
10
|
+
import chokidar from 'chokidar';
|
|
11
|
+
import debounce from 'debounce';
|
|
12
|
+
|
|
13
|
+
import { create } from './src/create.js';
|
|
14
|
+
import {
|
|
15
|
+
getUserConfig,
|
|
16
|
+
getCliConfig,
|
|
17
|
+
addFrameworkPlugins,
|
|
18
|
+
addCustomElementsPropertyToPackageJson,
|
|
19
|
+
mergeGlobsAndExcludes,
|
|
20
|
+
timestamp,
|
|
21
|
+
DEFAULTS,
|
|
22
|
+
MENU,
|
|
23
|
+
} from './src/utils/cli-helpers.js';
|
|
24
|
+
import { findExternalManifests } from './src/utils/find-external-manifests.js';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {{argv:string[]; cwd: string; noWrite:boolean}} [opts]
|
|
28
|
+
*/
|
|
29
|
+
export async function cli({ argv = process.argv, cwd = process.cwd(), noWrite } = {}) {
|
|
30
|
+
const mainDefinitions = [{ name: 'command', defaultOption: true }];
|
|
31
|
+
const mainOptions = commandLineArgs(mainDefinitions, { stopAtFirstUnknown: true, argv });
|
|
32
|
+
const cliArgs = mainOptions._unknown || [];
|
|
33
|
+
|
|
34
|
+
if (mainOptions.command === 'analyze') {
|
|
35
|
+
const { config: configPath, ...cliConfig } = getCliConfig(cliArgs);
|
|
36
|
+
const userConfig = await getUserConfig(configPath, cwd);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Merged config options
|
|
40
|
+
* Command line options override userConfig options
|
|
41
|
+
*/
|
|
42
|
+
const mergedOptions = { ...DEFAULTS, ...userConfig, ...cliConfig };
|
|
43
|
+
const merged = mergeGlobsAndExcludes(DEFAULTS, userConfig, cliConfig);
|
|
44
|
+
async function run() {
|
|
45
|
+
const globs = await globby(merged, { cwd });
|
|
46
|
+
const modules = userConfig?.overrideModuleCreation
|
|
47
|
+
? userConfig.overrideModuleCreation({ ts, globs })
|
|
48
|
+
: globs.map((glob) => {
|
|
49
|
+
const fullPath = path.resolve(cwd, glob);
|
|
50
|
+
const source = fs.readFileSync(fullPath).toString();
|
|
51
|
+
|
|
52
|
+
return ts.createSourceFile(glob, source, ts.ScriptTarget.ES2015, true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
let thirdPartyCEMs = [];
|
|
56
|
+
if (mergedOptions?.dependencies) {
|
|
57
|
+
try {
|
|
58
|
+
const fullPathGlobs = globs.map(glob => path.resolve(cwd, glob));
|
|
59
|
+
thirdPartyCEMs = await findExternalManifests(fullPathGlobs, {basePath: cwd});
|
|
60
|
+
} catch (e) {
|
|
61
|
+
if (mergedOptions.dev) console.log(`Failed to add third party CEMs. \n\n${e.stack}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let plugins = await addFrameworkPlugins(mergedOptions);
|
|
66
|
+
plugins = [...plugins, ...(userConfig?.plugins || [])];
|
|
67
|
+
|
|
68
|
+
const context = { dev: mergedOptions.dev, thirdPartyCEMs };
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Create the manifest
|
|
72
|
+
*/
|
|
73
|
+
const customElementsManifest = create({modules, plugins, context});
|
|
74
|
+
|
|
75
|
+
if (mergedOptions.dev) {
|
|
76
|
+
console.log(JSON.stringify(customElementsManifest, null, 2));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if(!noWrite) {
|
|
80
|
+
const outdir = path.join(cwd, mergedOptions.outdir);
|
|
81
|
+
if (!fs.existsSync(outdir)) {
|
|
82
|
+
fs.mkdirSync(outdir, { recursive: true });
|
|
83
|
+
}
|
|
84
|
+
fs.writeFileSync(
|
|
85
|
+
path.join(outdir, 'custom-elements.json'),
|
|
86
|
+
`${JSON.stringify(customElementsManifest, null, 2)}\n`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!mergedOptions.quiet) {
|
|
91
|
+
console.log(`[${timestamp()}] @custom-elements-manifest/analyzer: Created new manifest.`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return customElementsManifest;
|
|
95
|
+
}
|
|
96
|
+
/** The manifest that will be returned for programmatic calls of cli */
|
|
97
|
+
const manifest = await run();
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Watch mode
|
|
101
|
+
*/
|
|
102
|
+
if (mergedOptions.watch) {
|
|
103
|
+
const fileWatcher = chokidar.watch(merged);
|
|
104
|
+
|
|
105
|
+
const onChange = debounce(run, 100);
|
|
106
|
+
|
|
107
|
+
fileWatcher.addListener('add', onChange);
|
|
108
|
+
fileWatcher.addListener('change', onChange);
|
|
109
|
+
fileWatcher.addListener('unlink', onChange);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
if (mergedOptions.packagejson) {
|
|
114
|
+
addCustomElementsPropertyToPackageJson(mergedOptions.outdir);
|
|
115
|
+
}
|
|
116
|
+
} catch {
|
|
117
|
+
console.log(
|
|
118
|
+
`Could not add 'customElements' property to ${cwd}${
|
|
119
|
+
path.sep
|
|
120
|
+
}package.json. \nAdding this property helps tooling locate your Custom Elements Manifest. Please consider adding it yourself, or file an issue if you think this is a bug.\nhttps://www.github.com/open-wc/custom-elements-manifest`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return manifest;
|
|
125
|
+
} else {
|
|
126
|
+
console.log(MENU);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@custom-elements-manifest/analyzer",
|
|
3
|
+
"version": "0.10.10",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"custom-elements-manifest": "./cem.js",
|
|
10
|
+
"cem": "./cem.js"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/open-wc/custom-elements-manifest.git",
|
|
15
|
+
"directory": "packages/analyzer"
|
|
16
|
+
},
|
|
17
|
+
"author": "open-wc",
|
|
18
|
+
"homepage": "https://github.com/open-wc/custom-elements-manifest",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/open-wc/custom-elements-manifest"
|
|
21
|
+
},
|
|
22
|
+
"main": "index.js",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"prepublishOnly": "npm test && npm run build:browser",
|
|
25
|
+
"start": "nodemon --ignore './custom-elements.json' cem.js analyze --dev --fast",
|
|
26
|
+
"test": "asdgf",
|
|
27
|
+
"build:browser": "esbuild src/browser-entrypoint.js --bundle --format=esm --outfile=browser/index.js",
|
|
28
|
+
"test:watch": "watchexec -w src -w test npm test",
|
|
29
|
+
"update-fixtures": "node scripts/update-version.js --version 1.0.0"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"custom-elements",
|
|
33
|
+
"custom-elements-json",
|
|
34
|
+
"custom-elements-manifest",
|
|
35
|
+
"customelements",
|
|
36
|
+
"webcomponents",
|
|
37
|
+
"customelementsjson",
|
|
38
|
+
"customelementsmanifest"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@custom-elements-manifest/find-dependencies": "^0.0.6",
|
|
42
|
+
"@github/catalyst": "^1.6.0",
|
|
43
|
+
"@web/config-loader": "0.1.3",
|
|
44
|
+
"chokidar": "3.5.2",
|
|
45
|
+
"command-line-args": "5.1.2",
|
|
46
|
+
"comment-parser": "1.2.4",
|
|
47
|
+
"custom-elements-manifest": "1.0.0",
|
|
48
|
+
"debounce": "1.2.1",
|
|
49
|
+
"globby": "11.0.4",
|
|
50
|
+
"typescript": "~5.4.2"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {},
|
|
53
|
+
"contributors": [
|
|
54
|
+
"Pascal Schilp <pascalschilp@gmail.com>",
|
|
55
|
+
"Benny Powers <web@bennypowers.com>",
|
|
56
|
+
"Matias Huhta <huhta.matias@gmail.com>"
|
|
57
|
+
],
|
|
58
|
+
"customElements": "custom-elements.json"
|
|
59
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is the entrypoint for rollup to correctly bundle the analyzer for the browser.
|
|
3
|
+
* Do not use directly, but import from ./browser/index.js
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import ts from 'typescript';
|
|
7
|
+
|
|
8
|
+
import { create } from './create.js';
|
|
9
|
+
import { catalystPlugin } from './features/framework-plugins/catalyst/catalyst.js';
|
|
10
|
+
import { catalystPlugin2 } from './features/framework-plugins/catalyst-major-2/catalyst.js';
|
|
11
|
+
import { stencilPlugin } from './features/framework-plugins/stencil/stencil.js';
|
|
12
|
+
import { litPlugin } from './features/framework-plugins/lit/lit.js';
|
|
13
|
+
import { fastPlugin } from './features/framework-plugins/fast/fast.js';
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
ts,
|
|
17
|
+
create,
|
|
18
|
+
catalystPlugin,
|
|
19
|
+
catalystPlugin2,
|
|
20
|
+
stencilPlugin,
|
|
21
|
+
litPlugin,
|
|
22
|
+
fastPlugin
|
|
23
|
+
};
|