@ui5/webcomponents-tools 0.0.0-f651a470c → 0.0.0-f6676abdd

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 (70) hide show
  1. package/CHANGELOG.md +1346 -0
  2. package/README.md +3 -5
  3. package/assets-meta.js +11 -10
  4. package/components-package/cypress/support/commands.js +66 -0
  5. package/components-package/cypress/support/component-index.html +17 -0
  6. package/components-package/cypress/support/component.d.ts +22 -0
  7. package/components-package/cypress/support/component.js +46 -0
  8. package/components-package/cypress/support/cypress-ct-preact.js +11 -0
  9. package/components-package/cypress.config.js +33 -0
  10. package/components-package/eslint.js +94 -28
  11. package/components-package/nps.js +58 -47
  12. package/components-package/postcss.components.js +1 -21
  13. package/components-package/postcss.themes.js +1 -26
  14. package/components-package/vite.config.js +7 -11
  15. package/components-package/wdio.js +415 -393
  16. package/icons-collection/nps.js +9 -7
  17. package/lib/amd-to-es6/index.js +102 -0
  18. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  19. package/lib/cem/custom-elements-manifest.config.mjs +544 -0
  20. package/lib/cem/event.mjs +168 -0
  21. package/lib/cem/schema-internal.json +1413 -0
  22. package/lib/cem/schema.json +1098 -0
  23. package/lib/cem/types-internal.d.ts +808 -0
  24. package/lib/cem/types.d.ts +736 -0
  25. package/lib/cem/utils.mjs +423 -0
  26. package/lib/cem/validate.js +70 -0
  27. package/lib/create-icons/index.js +8 -6
  28. package/lib/create-illustrations/index.js +51 -30
  29. package/lib/create-new-component/{tsFileContentTemplate.js → Component.js} +15 -25
  30. package/lib/create-new-component/ComponentTemplate.js +12 -0
  31. package/lib/create-new-component/index.js +35 -73
  32. package/lib/css-processors/css-processor-components.mjs +77 -0
  33. package/lib/css-processors/css-processor-themes.mjs +74 -0
  34. package/lib/css-processors/scope-variables.mjs +49 -0
  35. package/lib/css-processors/shared.mjs +56 -0
  36. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  37. package/lib/dev-server/{dev-server.js → dev-server.mjs} +4 -4
  38. package/lib/dev-server/virtual-index-html-plugin.js +24 -20
  39. package/lib/generate-js-imports/illustrations.js +78 -64
  40. package/lib/generate-json-imports/i18n.js +45 -61
  41. package/lib/generate-json-imports/themes.js +16 -33
  42. package/lib/hbs2lit/src/compiler.js +9 -6
  43. package/lib/hbs2lit/src/litVisitor2.js +42 -17
  44. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  45. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +39 -6
  46. package/lib/hbs2ui5/index.js +23 -6
  47. package/lib/i18n/defaults.js +3 -2
  48. package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
  49. package/lib/remove-dev-mode/remove-dev-mode.mjs +37 -0
  50. package/lib/scoping/get-all-tags.js +10 -3
  51. package/lib/scoping/lint-src.js +8 -7
  52. package/lib/scoping/scope-test-pages.js +2 -1
  53. package/lib/test-runner/test-runner.js +2 -2
  54. package/package.json +25 -13
  55. package/tsconfig.json +18 -0
  56. package/types/index.d.ts +1 -0
  57. package/components-package/wdio.sync.js +0 -360
  58. package/lib/create-new-component/jsFileContentTemplate.js +0 -77
  59. package/lib/esm-abs-to-rel/index.js +0 -58
  60. package/lib/generate-custom-elements-manifest/index.js +0 -327
  61. package/lib/jsdoc/config.json +0 -29
  62. package/lib/jsdoc/configTypescript.json +0 -29
  63. package/lib/jsdoc/plugin.js +0 -2468
  64. package/lib/jsdoc/preprocess.js +0 -146
  65. package/lib/jsdoc/template/publish.js +0 -4120
  66. package/lib/postcss-css-to-esm/index.js +0 -90
  67. package/lib/postcss-css-to-json/index.js +0 -47
  68. package/lib/postcss-new-files/index.js +0 -36
  69. package/lib/postcss-p/postcss-p.mjs +0 -14
  70. package/lib/replace-global-core/index.js +0 -25
@@ -0,0 +1,544 @@
1
+ import { parse } from "comment-parser";
2
+ import processEvent from "./event.mjs";
3
+ import path from "path";
4
+ import fs from 'fs';
5
+ import {
6
+ getDeprecatedStatus,
7
+ getExperimentalStatus,
8
+ getSinceStatus,
9
+ getPrivacyStatus,
10
+ getReference,
11
+ validateJSDocComment,
12
+ findDecorator,
13
+ findAllDecorators,
14
+ hasTag,
15
+ findTag,
16
+ findAllTags,
17
+ getTypeRefs,
18
+ normalizeDescription,
19
+ formatArrays,
20
+ isClass,
21
+ normalizeTagType,
22
+ logDocumentationError,
23
+ displayDocumentationErrors,
24
+ toKebabCase
25
+ } from "./utils.mjs";
26
+ import { generateCustomData } from "cem-plugin-vs-code-custom-data-generator";
27
+ import { customElementJetBrainsPlugin } from "custom-element-jet-brains-integration";
28
+
29
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
30
+
31
+ const extractClassNodeJSDoc = node => {
32
+ const fileContent = node.getFullText();
33
+ const allJSDocsRegExp = new RegExp(`\\/\\*\\*(.|\\n)+?\\s+\\*\\/`, "gm");
34
+ let allJSDocs = [...fileContent.matchAll(allJSDocsRegExp)];
35
+ allJSDocs = allJSDocs.map(match => match[0]); // all /** ..... */ comments
36
+
37
+ // Find where the class is defined in the original file
38
+ const tsClassDefinitionRegExp = new RegExp(`^\\s*(abstract\\s*)?class [\\w\\d_]+`, "gm");
39
+ let tsClassDefinitionMatch = fileContent.match(tsClassDefinitionRegExp);
40
+ if (!tsClassDefinitionMatch) {
41
+ return; // no class defined in this .ts file
42
+ }
43
+ const tsClassDefinition = tsClassDefinitionMatch[0];
44
+ const tsClassDefinitionIndex = fileContent.indexOf(tsClassDefinition);
45
+
46
+ return allJSDocs.find(JSDoc => {
47
+ return isClass(JSDoc) && (fileContent.indexOf(JSDoc) < tsClassDefinitionIndex)
48
+ });
49
+ }
50
+
51
+ function processClass(ts, classNode, moduleDoc) {
52
+ const className = classNode?.name?.text;
53
+ const currClass = moduleDoc?.declarations?.find(declaration => declaration?.name === className);
54
+ const currClassJSdoc = extractClassNodeJSDoc(classNode);
55
+
56
+ if (!currClassJSdoc) return;
57
+
58
+ const customElementDecorator = findDecorator(classNode, "customElement");
59
+ const classParsedJsDoc = parse(currClassJSdoc, { spacing: 'preserve' })[0];
60
+
61
+ validateJSDocComment("class", classParsedJsDoc, classNode.name?.text, moduleDoc);
62
+
63
+ const decoratorArg = customElementDecorator?.expression?.arguments[0];
64
+ currClass.tagName = decoratorArg?.text || (decoratorArg?.properties.find(property => property.name.text === "tag")?.initializer?.text);
65
+ currClass.customElement = !!customElementDecorator || className === "UI5Element" || undefined;
66
+ currClass.kind = "class";
67
+ currClass.deprecated = getDeprecatedStatus(classParsedJsDoc);
68
+ currClass._ui5experimental = getExperimentalStatus(classParsedJsDoc);
69
+ currClass._ui5since = getSinceStatus(classParsedJsDoc);
70
+ currClass._ui5privacy = getPrivacyStatus(classParsedJsDoc);
71
+ currClass._ui5abstract = hasTag(classParsedJsDoc, "abstract") ? true : undefined;
72
+ currClass.description = normalizeDescription(classParsedJsDoc.description || findTag(classParsedJsDoc, "class")?.description);
73
+ currClass._ui5implements = findAllTags(classParsedJsDoc, "implements")
74
+ .map(tag => {
75
+ const correctInterfaceDescription = classNode?.heritageClauses?.some(heritageClause => {
76
+ return heritageClause?.types?.some(type => type.expression?.text === normalizeTagType(tag.type));
77
+ });
78
+
79
+ if (!correctInterfaceDescription) {
80
+ logDocumentationError(moduleDoc.path, `@interface {${tag.type}} tag is used, but the class doesn't implement the corresponding interface`)
81
+ }
82
+
83
+ return getReference(ts, normalizeTagType(tag.type), classNode, moduleDoc.path)
84
+ })
85
+ .filter(Boolean);
86
+
87
+
88
+ if (hasTag(classParsedJsDoc, "extends")) {
89
+ const superclassTag = findTag(classParsedJsDoc, "extends");
90
+ currClass.superclass = getReference(ts, superclassTag.name, classNode, moduleDoc.path);
91
+
92
+ if (classNode?.heritageClauses?.[0]?.types?.[0]?.expression?.text !== superclassTag.name) {
93
+ logDocumentationError(moduleDoc.path, `@extends ${superclassTag.name} is used, but the class doesn't extend the corresponding superclass`)
94
+ }
95
+
96
+ if (currClass.superclass?.name === "UI5Element") {
97
+ currClass.customElement = true;
98
+ }
99
+ }
100
+
101
+ if (!currClass._ui5implements.length) delete currClass._ui5implements;
102
+
103
+ // Slots
104
+
105
+ // Slots without accessort (defined in class comment)
106
+ if (hasTag(classParsedJsDoc, "slot") && currClass.slots) {
107
+ const slotTags = findAllTags(classParsedJsDoc, "slot");
108
+
109
+ currClass.slots.forEach(slot => {
110
+ const tag = slotTags.find(tag => tag.name === slot.name);
111
+
112
+ const typeRefs = (normalizeTagType(tag.type)
113
+ ?.replaceAll(/Array<|>|\[\]/g, "")
114
+ ?.split("|")
115
+ ?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path)).filter(Boolean));
116
+
117
+ slot._ui5privacy = "public";
118
+ slot._ui5type = { text: formatArrays(normalizeTagType(tag.type)) };
119
+ slot.description = normalizeDescription(tag.description)
120
+
121
+ if (typeRefs && typeRefs.length) {
122
+ slot._ui5type.references = typeRefs;
123
+ }
124
+
125
+ delete slot.type
126
+ })
127
+ }
128
+
129
+ // Events
130
+ currClass.events = findAllDecorators(classNode, ["event", "eventStrict"])
131
+ ?.map(event => processEvent(ts, event, classNode, moduleDoc));
132
+
133
+ // TODO: remove after changing Button's click to custom event.
134
+ // Currently, the Button emits a native click that doesn't need and doesn't have an event decorator,
135
+ // so we add it manually to the events array.
136
+ if (currClass.tagName === "ui5-button") {
137
+ currClass.events.push({
138
+ "name": "click",
139
+ "_ui5privacy": "public",
140
+ "type": {
141
+ "text": "Event"
142
+ },
143
+ "description": "Fired when the component is activated either with a\nmouse/tap or by using the Enter or Space key.\n\n**Note:** The event will not be fired if the `disabled`\nproperty is set to `true`.",
144
+ "_ui5Cancelable": false,
145
+ "_ui5allowPreventDefault": false,
146
+ "_ui5Bubbles": true
147
+ });
148
+ }
149
+
150
+ const filename = classNode.getSourceFile().fileName;
151
+ const sourceFile = typeProgram.getSourceFile(filename);
152
+ const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
153
+
154
+ // Slots (with accessor), methods and fields
155
+ for (let i = 0; i < (currClass.members?.length || 0); i++) {
156
+ const member = currClass.members[i];
157
+ const classNodeMember = classNode.members?.find(nodeMember => nodeMember.name?.text === member?.name && nodeMember.jsDoc?.[0]);
158
+ const classNodeMemberJSdoc = classNodeMember?.jsDoc?.[0];
159
+
160
+ if (!classNodeMember || !classNodeMemberJSdoc) continue;
161
+
162
+ const memberParsedJsDoc = parse(classNodeMemberJSdoc?.getText())[0];
163
+
164
+ member._ui5since = getSinceStatus(memberParsedJsDoc);
165
+ member.deprecated === "true" && (member.deprecated = true)
166
+
167
+ // Slots with accessors are treated like fields by the tool, so we have to convert them into slots.
168
+ if (member.kind === "field") {
169
+ const slotDecorator = findDecorator(classNodeMember, "slot");
170
+ validateJSDocComment(slotDecorator ? "slot" : (member.readonly ? "getter" : "field"), memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
171
+
172
+ const typeRefs = (getTypeRefs(ts, classNodeMember, member)
173
+ ?.map(e => getReference(ts, e, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
174
+
175
+ if (member.type?.text) {
176
+ member.type.text = formatArrays(member.type.text);
177
+ }
178
+
179
+ if (member.type && typeRefs.length) {
180
+ member.type.references = typeRefs;
181
+ }
182
+
183
+ if (slotDecorator) {
184
+ if (!currClass.slots) currClass.slots = [];
185
+
186
+ const slot = currClass.members.splice(i, 1)[0];
187
+ const defaultProperty = slotDecorator.expression?.arguments?.[0]?.properties?.find(property => property.name.text === "default");
188
+
189
+ // name of the default slot declared with decorator will be overriden so we to provide it's accessor name
190
+ if (defaultProperty && defaultProperty.initializer?.kind === ts.SyntaxKind.TrueKeyword) {
191
+ slot._ui5propertyName = slot.name;
192
+ slot.name = "default";
193
+ }
194
+
195
+ // Slots don't have type, privacy and kind, so we have do convert them and to clean unused props
196
+ member._ui5type = member.type;
197
+ member._ui5privacy = member.privacy;
198
+ delete member.type;
199
+ delete member.privacy;
200
+ delete slot.kind;
201
+
202
+ currClass.slots.push(slot);
203
+ i--;
204
+ } else {
205
+ const propertyDecorator = findDecorator(classNodeMember, "property");
206
+
207
+ if (propertyDecorator) {
208
+ member._ui5noAttribute = propertyDecorator?.expression?.arguments[0]?.properties?.find(property => property.name.text === "noAttribute")?.initializer?.kind === ts.SyntaxKind.TrueKeyword || undefined;
209
+ }
210
+
211
+ if (currClass.customElement && member.privacy === "public") {
212
+ const tsProgramMember = tsProgramClassNode.members.find(m => ts.isPropertyDeclaration(m) && m.name?.text === member.name);
213
+ const attributeValue = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramMember), tsProgramMember);
214
+
215
+ if (attributeValue === "boolean" && member.default === "true") {
216
+ logDocumentationError(moduleDoc.path, `Boolean properties must be initialzed to false. [${member.name}] property of class [${className}] is intialized to \`true\``)
217
+ }
218
+
219
+ if (!member.type) {
220
+ logDocumentationError(moduleDoc.path, `Public properties must have type. The type of [${member.name}] property is not determinated automatically. Please check it.`)
221
+ }
222
+
223
+ currClass.attributes.push({
224
+ description: member.description,
225
+ name: toKebabCase(member.name),
226
+ default: member.default,
227
+ fieldName: member.name,
228
+ type: { text: attributeValue },
229
+ deprecated: member.deprecated
230
+ })
231
+ }
232
+
233
+ if (hasTag(memberParsedJsDoc, "formProperty")) {
234
+ member._ui5formProperty = true;
235
+ }
236
+
237
+ const formEventsTag = findTag(memberParsedJsDoc, "formEvents");
238
+ if (formEventsTag) {
239
+ const tagValue = formEventsTag.description ? `${formEventsTag.name} ${formEventsTag.description}` : formEventsTag.name;
240
+ member._ui5formEvents = tagValue.trim().replaceAll(/\s+/g, ",");
241
+ }
242
+
243
+ const defaultTag = findTag(memberParsedJsDoc, "default");
244
+ if (defaultTag) {
245
+ const tagValue = defaultTag.source?.[0]?.tokens?.name || defaultTag.source?.[0]?.tokens?.description || defaultTag.source?.[0]?.tokens?.type || "";
246
+ member.default = tagValue;
247
+ }
248
+
249
+ if (member.privacy === "public" && !member.default) {
250
+ logDocumentationError(moduleDoc.path, `Missing default value for '${member.name}'.`)
251
+ }
252
+
253
+ // Getters are treated as fields so they should not have return, instead of return they should have default value defined with @default
254
+ if (member.readonly) {
255
+ if (member.privacy === "public" && !member.type) {
256
+ logDocumentationError(moduleDoc.path, `Missing return type for read-only field '${member.name}'.`)
257
+ }
258
+
259
+ delete member.return;
260
+ }
261
+ }
262
+ } else if (member.kind === "method") {
263
+ validateJSDocComment("method", memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
264
+
265
+ member.parameters?.forEach(param => {
266
+ // Treat every parameter that has respective @param tag as public
267
+ param._ui5privacy = findAllTags(memberParsedJsDoc, "param").some(tag => tag.name === param.name) ? "public" : "private";
268
+ if (param._ui5privacy === "public") {
269
+ const paramNode = classNodeMember.parameters?.find(parameter => parameter.name?.text === param.name);
270
+ let type;
271
+
272
+ if (param.optional) {
273
+ const filename = classNode.getSourceFile().fileName;
274
+
275
+ const sourceFile = typeProgram.getSourceFile(filename);
276
+ const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
277
+ const tsProgramMember = tsProgramClassNode.members.find(m => ts.isMethodDeclaration(m) && m.name?.text === member.name);
278
+ const tsProgramParameter = tsProgramMember.parameters.find(p => ts.isParameter(p) && p.name?.text === param.name);
279
+
280
+ if (tsProgramParameter) {
281
+ const typeName = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramParameter), tsProgramParameter);
282
+
283
+ if (!param.type) {
284
+ param.type = {};
285
+ param.type.text = typeName;
286
+ }
287
+
288
+ type = typeName.replaceAll(/Array<|>|\[\]/g, "")
289
+ ?.split("|");
290
+ }
291
+ }
292
+
293
+ const typeRefs = ((type || getTypeRefs(ts, (type || paramNode), param))
294
+ ?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
295
+
296
+ if (typeRefs.length) {
297
+ param.type.references = typeRefs;
298
+ }
299
+ }
300
+ });
301
+
302
+ if (member.return) {
303
+ const returnTag = findTag(memberParsedJsDoc, "returns");
304
+ member.return.description = returnTag?.description ? `${returnTag.name} ${returnTag.description}` : returnTag?.name;
305
+ member.return.type.text = formatArrays(classNodeMember?.type?.getFullText?.()?.trim());
306
+ const typeRefs = (getTypeRefs(ts, classNodeMember, member.return)
307
+ ?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
308
+
309
+ if (typeRefs.length) {
310
+ member.return.type.references = typeRefs;
311
+ }
312
+
313
+ if (member.privacy === "public" && !member.return.type.text) {
314
+ logDocumentationError(moduleDoc.path, `Missing return type for function '${member.name}'.`)
315
+ }
316
+ } else if (member.privacy === "public") {
317
+ logDocumentationError(moduleDoc.path, `Missing return type for function '${member.name}'.`)
318
+ }
319
+ }
320
+ }
321
+ }
322
+
323
+ function processInterface(ts, interfaceNode, moduleDoc) {
324
+ const interfaceJSdoc = interfaceNode?.jsDoc?.[0];
325
+ const interfaceName = interfaceNode?.name?.text;
326
+
327
+ if (!interfaceJSdoc) return;
328
+
329
+ const interfaceParsedJsDoc = parse(interfaceJSdoc?.getText(), { spacing: 'preserve' })[0];
330
+
331
+ validateJSDocComment("interface", interfaceParsedJsDoc, interfaceNode.name?.text, moduleDoc);
332
+
333
+ moduleDoc.declarations.push({
334
+ kind: "interface",
335
+ name: interfaceName,
336
+ description: normalizeDescription(interfaceParsedJsDoc?.description),
337
+ _ui5experimental: getExperimentalStatus(interfaceParsedJsDoc),
338
+ _ui5privacy: getPrivacyStatus(interfaceParsedJsDoc),
339
+ _ui5since: getSinceStatus(interfaceParsedJsDoc),
340
+ deprecated: getDeprecatedStatus(interfaceParsedJsDoc),
341
+ });
342
+ }
343
+
344
+ function processEnum(ts, enumNode, moduleDoc) {
345
+ const enumJSdoc = enumNode?.jsDoc?.[0];
346
+ const enumName = enumNode?.name?.text;
347
+
348
+ if (!enumJSdoc) return;
349
+
350
+ const enumParsedJsDoc = parse(enumJSdoc?.getText(), { spacing: 'preserve' })[0];
351
+
352
+ validateJSDocComment("enum", enumParsedJsDoc, enumNode.name?.text, moduleDoc);
353
+
354
+ const result = {
355
+ kind: "enum",
356
+ name: enumName,
357
+ description: normalizeDescription(enumJSdoc?.comment),
358
+ _ui5experimental: getExperimentalStatus(enumParsedJsDoc),
359
+ _ui5privacy: getPrivacyStatus(enumParsedJsDoc),
360
+ _ui5since: getSinceStatus(enumParsedJsDoc),
361
+ deprecated: getDeprecatedStatus(enumParsedJsDoc) || undefined,
362
+ members: (enumNode?.members || []).map(member => {
363
+ const memberJSdoc = member?.jsDoc?.[0];
364
+
365
+ if (!memberJSdoc) return;
366
+
367
+ const memberParsedJsDoc = parse(memberJSdoc?.getText())[0];
368
+
369
+ validateJSDocComment("enum", memberParsedJsDoc, member.name?.text, moduleDoc);
370
+
371
+ return {
372
+ kind: "field",
373
+ static: true,
374
+ privacy: getPrivacyStatus(memberParsedJsDoc),
375
+ _ui5since: getSinceStatus(memberParsedJsDoc),
376
+ description: memberJSdoc?.comment,
377
+ default: member.initializer?.text,
378
+ deprecated: getDeprecatedStatus(memberParsedJsDoc),
379
+ name: member.name?.text,
380
+ readonly: true,
381
+ };
382
+ }).filter(Boolean),
383
+ };
384
+
385
+ moduleDoc.declarations.push(result);
386
+ }
387
+
388
+ const processPublicAPI = object => {
389
+ if (!object) {
390
+ return true;
391
+ }
392
+ const keys = Object.keys(object);
393
+ if (!keys.includes("privacy") && !keys.includes("_ui5privacy")) {
394
+ return true;
395
+ }
396
+ for (const key of keys) {
397
+ if ((key === "privacy" && object[key] !== "public") || (key === "_ui5privacy" && object[key] !== "public")) {
398
+ return true;
399
+ } else if (typeof object[key] === "object") {
400
+ if (key === "cssParts" || key === "attributes" || key === "_ui5implements") {
401
+ continue;
402
+ }
403
+
404
+ if (Array.isArray(object[key])) {
405
+ for (let i = 0; i < object[key].length; i++) {
406
+ const shouldRemove = processPublicAPI(object[key][i]);
407
+ if (shouldRemove) {
408
+ object[key].splice(i, 1);
409
+ i--;
410
+ }
411
+ }
412
+ if (object[key].length === 0) {
413
+ delete object[key];
414
+ }
415
+ }
416
+ }
417
+ }
418
+ return false;
419
+ };
420
+
421
+ let typeChecker;
422
+ let typeProgram;
423
+
424
+ export default {
425
+ globs: ["src/!(*generated)/*.ts", "src/!(*bundle)*.ts"],
426
+ outdir: 'dist',
427
+ overrideModuleCreation: ({ ts, globs }) => {
428
+ typeProgram = ts.createProgram(globs, {
429
+ noEmitOnError: false,
430
+ allowJs: true,
431
+ experimentalDecorators: true,
432
+ target: 99,
433
+ downlevelIteration: true,
434
+ module: 99,
435
+ strictNullChecks: true,
436
+ moduleResolution: 2,
437
+ esModuleInterop: true,
438
+ noEmit: true,
439
+ pretty: true,
440
+ allowSyntheticDefaultImports: true,
441
+ allowUnreachableCode: true,
442
+ allowUnusedLabels: true,
443
+ skipLibCheck: true,
444
+ });
445
+ typeChecker = typeProgram.getTypeChecker();
446
+
447
+ return globs.map((glob) => {
448
+ const fullPath = path.resolve(process.cwd(), glob);
449
+ const source = fs.readFileSync(fullPath).toString();
450
+
451
+ return ts.createSourceFile(glob, source, ts.ScriptTarget.ES2015, true);
452
+ });
453
+ },
454
+ plugins: [
455
+ {
456
+ name: 'my-plugin',
457
+ analyzePhase({ ts, node, moduleDoc }) {
458
+ switch (true) {
459
+ case ts.isClassDeclaration(node):
460
+ processClass(ts, node, moduleDoc);
461
+ break;
462
+ case ts.isEnumDeclaration(node):
463
+ processEnum(ts, node, moduleDoc);
464
+ break;
465
+ case ts.isInterfaceDeclaration(node):
466
+ processInterface(ts, node, moduleDoc);
467
+ break;
468
+ }
469
+ },
470
+ moduleLinkPhase({ moduleDoc }) {
471
+ for (let i = 0; i < moduleDoc.declarations.length; i++) {
472
+ const shouldRemove = processPublicAPI(moduleDoc.declarations[i]) || ["function", "variable"].includes(moduleDoc.declarations[i].kind)
473
+ if (shouldRemove) {
474
+ moduleDoc.declarations.splice(i, 1);
475
+ i--;
476
+ }
477
+ }
478
+
479
+ moduleDoc.path = moduleDoc.path?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
480
+
481
+ moduleDoc.exports = moduleDoc.exports.
482
+ filter(e => !(e.kind === "custom-element-definition" && !moduleDoc.declarations?.find(d => d.name === e.name)?.tagName))
483
+
484
+ moduleDoc.exports.forEach(e => {
485
+ const classNode = moduleDoc.declarations.find(c => c.name === e.declaration.name);
486
+
487
+ if (e.declaration && e.declaration.module) {
488
+ e.declaration.module = e.declaration.module.replace(/^src/, "dist").replace(/\.ts$/, ".js");
489
+ }
490
+
491
+ if (classNode?.customElement && classNode.tagName && e.kind !== "custom-element-definition") {
492
+ moduleDoc.exports.push({
493
+ kind: "custom-element-definition",
494
+ name: classNode.tagName,
495
+ declaration: {
496
+ name: e.declaration.name,
497
+ module: e.declaration.module
498
+ }
499
+ })
500
+ }
501
+ })
502
+
503
+ const typeReferences = new Set();
504
+ const registerTypeReference = reference => typeReferences.add(JSON.stringify(reference))
505
+
506
+ moduleDoc.declarations.forEach(declaration => {
507
+ ["events", "slots", "members"].forEach(memberType => {
508
+ declaration[memberType]?.forEach(member => {
509
+ if (member.type?.references) {
510
+ member.type.references.forEach(registerTypeReference)
511
+ } else if (member._ui5type?.references) {
512
+ member._ui5type.references.forEach(registerTypeReference)
513
+ } else if (member.kind === "method") {
514
+ member.return?.type?.references?.forEach(registerTypeReference)
515
+
516
+ member.parameters?.forEach(parameter => {
517
+ parameter.type?.references?.forEach(registerTypeReference)
518
+ })
519
+ }
520
+ })
521
+ })
522
+ });
523
+
524
+ typeReferences.forEach(reference => {
525
+ reference = JSON.parse(reference);
526
+ if (reference.package === packageJSON?.name && reference.module === moduleDoc.path) {
527
+ const hasExport = moduleDoc.exports.some(e => e.declaration?.name === reference.name && e.declaration?.module === reference.module)
528
+
529
+ if (!hasExport) {
530
+ logDocumentationError(moduleDoc.path?.replace(/^dist/, "src").replace(/\.js$/, ".ts"), `Type '${reference.name}' is used to describe a public API but is not exported.`,)
531
+ }
532
+ }
533
+ })
534
+ },
535
+ packageLinkPhase({ context }) {
536
+ if (context.dev) {
537
+ displayDocumentationErrors();
538
+ }
539
+ }
540
+ },
541
+ generateCustomData({ outdir: "dist", cssFileName: null, cssPropertiesDocs: false }),
542
+ customElementJetBrainsPlugin({ outdir: "dist", cssFileName: null, cssPropertiesDocs: false })
543
+ ],
544
+ };