@ui5/webcomponents-tools 0.0.0-f651a470c → 0.0.0-f79db712b
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 +405 -0
- package/README.md +2 -1
- package/assets-meta.js +16 -7
- package/components-package/eslint.js +2 -0
- package/components-package/nps.js +37 -30
- package/components-package/postcss.components.js +1 -21
- package/components-package/postcss.themes.js +1 -26
- package/components-package/wdio.js +15 -3
- package/components-package/wdio.sync.js +9 -1
- package/icons-collection/nps.js +8 -6
- package/lib/cem/custom-elements-manifest.config.mjs +499 -0
- package/lib/cem/event.mjs +135 -0
- package/lib/cem/schema-internal.json +1354 -0
- package/lib/cem/schema.json +1098 -0
- package/lib/cem/types-internal.d.ts +801 -0
- package/lib/cem/types.d.ts +736 -0
- package/lib/cem/utils.mjs +354 -0
- package/lib/cem/validate.js +67 -0
- package/lib/create-illustrations/index.js +32 -28
- package/lib/create-new-component/index.js +28 -58
- package/lib/create-new-component/jsFileContentTemplate.js +0 -4
- package/lib/create-new-component/tsFileContentTemplate.js +2 -15
- package/lib/css-processors/css-processor-components.mjs +77 -0
- package/lib/css-processors/css-processor-themes.mjs +79 -0
- package/lib/css-processors/scope-variables.mjs +46 -0
- package/lib/{postcss-css-to-esm/index.js → css-processors/shared.mjs} +36 -50
- package/lib/dev-server/custom-hot-update-plugin.js +39 -0
- package/lib/esm-abs-to-rel/index.js +4 -1
- package/lib/generate-custom-elements-manifest/index.js +1 -1
- package/lib/generate-js-imports/illustrations.js +78 -64
- package/lib/generate-json-imports/i18n.js +10 -5
- package/lib/generate-json-imports/themes.js +10 -5
- package/lib/hbs2lit/src/compiler.js +9 -6
- package/lib/hbs2lit/src/litVisitor2.js +42 -17
- package/lib/hbs2lit/src/svgProcessor.js +12 -5
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
- package/lib/hbs2ui5/index.js +21 -4
- package/lib/jsdoc/preprocess.js +1 -1
- package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
- package/lib/scoping/get-all-tags.js +1 -1
- package/lib/scoping/scope-test-pages.js +2 -1
- package/lib/test-runner/test-runner.js +2 -2
- package/package.json +10 -9
- package/lib/postcss-css-to-json/index.js +0 -47
- package/lib/postcss-new-files/index.js +0 -36
- package/lib/postcss-p/postcss-p.mjs +0 -14
@@ -1,26 +1 @@
|
|
1
|
-
|
2
|
-
const combineSelectors = require('../lib/postcss-combine-duplicated-selectors/index.js');
|
3
|
-
const postcssCSStoJSON = require('../lib/postcss-css-to-json/index.js');
|
4
|
-
const postcssCSStoESM = require('../lib/postcss-css-to-esm/index.js');
|
5
|
-
const cssnano = require('cssnano');
|
6
|
-
const fs = require("fs");
|
7
|
-
|
8
|
-
const packageName = JSON.parse(fs.readFileSync("./package.json")).name;
|
9
|
-
|
10
|
-
module.exports = {
|
11
|
-
plugins: [
|
12
|
-
postcssImport(),
|
13
|
-
combineSelectors({
|
14
|
-
removeDuplicatedProperties: true
|
15
|
-
}),
|
16
|
-
cssnano({
|
17
|
-
preset: [
|
18
|
-
'default', {
|
19
|
-
mergeLonghand: false, // https://github.com/cssnano/cssnano/issues/675
|
20
|
-
},
|
21
|
-
]
|
22
|
-
},),
|
23
|
-
postcssCSStoJSON({ toReplace: 'src', packageName }),
|
24
|
-
postcssCSStoESM({ toReplace: 'src', packageName }),
|
25
|
-
]
|
26
|
-
};
|
1
|
+
module.exports = {};
|
@@ -1,3 +1,5 @@
|
|
1
|
+
const dns = require("node:dns");
|
2
|
+
|
1
3
|
exports.config = {
|
2
4
|
//
|
3
5
|
// ====================
|
@@ -56,7 +58,15 @@ exports.config = {
|
|
56
58
|
'goog:chromeOptions': {
|
57
59
|
// to run chrome headless the following flags are required
|
58
60
|
// (see https://developers.google.com/web/updates/2017/04/headless-chrome)
|
59
|
-
args: [
|
61
|
+
args: [
|
62
|
+
'--headless',
|
63
|
+
'--start-maximized',
|
64
|
+
'--no-sandbox',
|
65
|
+
'--disable-gpu',
|
66
|
+
'--disable-infobars',
|
67
|
+
'--disable-extensions',
|
68
|
+
'--disable-dev-shm-usage',
|
69
|
+
],
|
60
70
|
// args: ['--disable-gpu'],
|
61
71
|
}
|
62
72
|
}],
|
@@ -99,8 +109,7 @@ exports.config = {
|
|
99
109
|
// Services take over a specific job you don't want to take care of. They enhance
|
100
110
|
// your test setup with almost no effort. Unlike plugins, they don't add new
|
101
111
|
// commands. Instead, they hook themselves up into the test process.
|
102
|
-
services: ['chromedriver', '
|
103
|
-
['static-server', {
|
112
|
+
services: ['chromedriver', ['static-server', {
|
104
113
|
folders: [
|
105
114
|
{ mount: '/', path: './dist' },
|
106
115
|
],
|
@@ -153,6 +162,9 @@ exports.config = {
|
|
153
162
|
*/
|
154
163
|
// beforeSession: function (config, capabilities, specs) {
|
155
164
|
// },
|
165
|
+
beforeSession: () => {
|
166
|
+
dns.setDefaultResultOrder('ipv4first');
|
167
|
+
},
|
156
168
|
/**
|
157
169
|
* Gets executed before test execution begins. At this point you can access to all global
|
158
170
|
* variables like `browser`. It is the perfect place to define custom commands.
|
@@ -56,7 +56,15 @@ exports.config = {
|
|
56
56
|
'goog:chromeOptions': {
|
57
57
|
// to run chrome headless the following flags are required
|
58
58
|
// (see https://developers.google.com/web/updates/2017/04/headless-chrome)
|
59
|
-
args: [
|
59
|
+
args: [
|
60
|
+
'--headless',
|
61
|
+
'--start-maximized',
|
62
|
+
'--no-sandbox',
|
63
|
+
'--disable-gpu',
|
64
|
+
'--disable-infobars',
|
65
|
+
'--disable-extensions',
|
66
|
+
'--disable-dev-shm-usage',
|
67
|
+
],
|
60
68
|
// args: ['--disable-gpu'],
|
61
69
|
}
|
62
70
|
}],
|
package/icons-collection/nps.js
CHANGED
@@ -21,7 +21,7 @@ const copyIconAssetsCommand = (options) => {
|
|
21
21
|
return {
|
22
22
|
default: "nps copy.json-imports copy.icon-collection",
|
23
23
|
"json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
|
24
|
-
"icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json"
|
24
|
+
"icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" src/generated/assets/`,
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
@@ -32,7 +32,7 @@ const copyIconAssetsCommand = (options) => {
|
|
32
32
|
|
33
33
|
options.versions.forEach((v) => {
|
34
34
|
command.default += ` copy.icon-collection${v}`;
|
35
|
-
command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json"
|
35
|
+
command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" src/generated/assets/${v}/`;
|
36
36
|
});
|
37
37
|
|
38
38
|
return command;
|
@@ -41,22 +41,24 @@ const copyIconAssetsCommand = (options) => {
|
|
41
41
|
const getScripts = (options) => {
|
42
42
|
const createJSImportsCmd = createIconImportsCommand(options);
|
43
43
|
const copyAssetsCmd = copyIconAssetsCommand(options);
|
44
|
-
const tsCommand = options.typescript ? "tsc" : "";
|
44
|
+
const tsCommand = options.typescript ? "tsc --build" : "";
|
45
45
|
const tsCrossEnv = options.typescript ? "cross-env UI5_TS=true" : "";
|
46
46
|
|
47
47
|
const scripts = {
|
48
48
|
clean: "rimraf dist && rimraf src/generated",
|
49
49
|
copy: copyAssetsCmd,
|
50
|
+
generate: `${tsCrossEnv} nps clean copy build.i18n build.icons build.jsonImports copyjson`,
|
51
|
+
copyjson: "copy-and-watch \"src/generated/**/*.json\" dist/generated/",
|
50
52
|
build: {
|
51
53
|
default: `${tsCrossEnv} nps clean copy build.i18n typescript build.icons build.jsonImports`,
|
52
54
|
i18n: {
|
53
55
|
default: "nps build.i18n.defaultsjs build.i18n.json",
|
54
56
|
defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
|
55
|
-
json: `mkdirp
|
57
|
+
json: `mkdirp src/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n src/generated/assets/i18n`,
|
56
58
|
},
|
57
59
|
jsonImports: {
|
58
|
-
default: "mkdirp
|
59
|
-
i18n: `node "${LIB}/generate-json-imports/i18n.js"
|
60
|
+
default: "mkdirp src/generated/json-imports && nps build.jsonImports.i18n",
|
61
|
+
i18n: `node "${LIB}/generate-json-imports/i18n.js" src/generated/assets/i18n src/generated/json-imports`,
|
60
62
|
},
|
61
63
|
icons: createJSImportsCmd,
|
62
64
|
},
|
@@ -0,0 +1,499 @@
|
|
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
|
+
getSinceStatus,
|
8
|
+
getPrivacyStatus,
|
9
|
+
getReference,
|
10
|
+
validateJSDocComment,
|
11
|
+
findDecorator,
|
12
|
+
findAllDecorators,
|
13
|
+
hasTag,
|
14
|
+
findTag,
|
15
|
+
findAllTags,
|
16
|
+
getJSDocErrors,
|
17
|
+
getTypeRefs,
|
18
|
+
normalizeDescription,
|
19
|
+
formatArrays,
|
20
|
+
isClass,
|
21
|
+
normalizeTagType
|
22
|
+
} from "./utils.mjs";
|
23
|
+
|
24
|
+
const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
|
25
|
+
|
26
|
+
const extractClassNodeJSDoc = node => {
|
27
|
+
const fileContent = node.getFullText();
|
28
|
+
const allJSDocsRegExp = new RegExp(`\\/\\*\\*(.|\\n)+?\\s+\\*\\/`, "gm");
|
29
|
+
let allJSDocs = [...fileContent.matchAll(allJSDocsRegExp)];
|
30
|
+
allJSDocs = allJSDocs.map(match => match[0]); // all /** ..... */ comments
|
31
|
+
|
32
|
+
// Find where the class is defined in the original file
|
33
|
+
const tsClassDefinitionRegExp = new RegExp(`^\\s*(abstract\\s*)?class [\\w\\d_]+`, "gm");
|
34
|
+
let tsClassDefinitionMatch = fileContent.match(tsClassDefinitionRegExp);
|
35
|
+
if (!tsClassDefinitionMatch) {
|
36
|
+
return; // no class defined in this .ts file
|
37
|
+
}
|
38
|
+
const tsClassDefinition = tsClassDefinitionMatch[0];
|
39
|
+
const tsClassDefinitionIndex = fileContent.indexOf(tsClassDefinition);
|
40
|
+
|
41
|
+
return allJSDocs.find(JSDoc => {
|
42
|
+
return isClass(JSDoc) && (fileContent.indexOf(JSDoc) < tsClassDefinitionIndex)
|
43
|
+
});
|
44
|
+
}
|
45
|
+
|
46
|
+
function processClass(ts, classNode, moduleDoc) {
|
47
|
+
const className = classNode?.name?.text;
|
48
|
+
const currClass = moduleDoc?.declarations?.find(declaration => declaration?.name === className);
|
49
|
+
const currClassJSdoc = extractClassNodeJSDoc(classNode);
|
50
|
+
|
51
|
+
if (!currClassJSdoc) return;
|
52
|
+
|
53
|
+
const customElementDecorator = findDecorator(classNode, "customElement");
|
54
|
+
const classParsedJsDoc = parse(currClassJSdoc, { spacing: 'preserve' })[0];
|
55
|
+
|
56
|
+
validateJSDocComment("class", classParsedJsDoc, classNode.name?.text, moduleDoc);
|
57
|
+
|
58
|
+
const decoratorArg = customElementDecorator?.expression?.arguments[0];
|
59
|
+
currClass.tagName = decoratorArg?.text || (decoratorArg?.properties.find(property => property.name.text === "tag")?.initializer?.text);
|
60
|
+
currClass.customElement = !!customElementDecorator || className === "UI5Element" || undefined;
|
61
|
+
currClass.kind = "class";
|
62
|
+
currClass.deprecated = getDeprecatedStatus(classParsedJsDoc);
|
63
|
+
currClass._ui5since = getSinceStatus(classParsedJsDoc);
|
64
|
+
currClass._ui5privacy = getPrivacyStatus(classParsedJsDoc);
|
65
|
+
currClass._ui5abstract = hasTag(classParsedJsDoc, "abstract") ? true : undefined;
|
66
|
+
currClass.description = normalizeDescription(classParsedJsDoc.description || findTag(classParsedJsDoc, "class")?.description);
|
67
|
+
currClass._ui5implements = findAllTags(classParsedJsDoc, "implements")
|
68
|
+
.map(tag => getReference(ts, normalizeTagType(tag.type), classNode, moduleDoc.path))
|
69
|
+
.filter(Boolean);
|
70
|
+
|
71
|
+
|
72
|
+
if (hasTag(classParsedJsDoc, "extends")) {
|
73
|
+
const superclassTag = findTag(classParsedJsDoc, "extends");
|
74
|
+
currClass.superclass = getReference(ts, superclassTag.name, classNode, moduleDoc.path);
|
75
|
+
|
76
|
+
if (currClass.superclass?.name === "UI5Element") {
|
77
|
+
currClass.customElement = true;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
if (!currClass._ui5implements.length) delete currClass._ui5implements;
|
82
|
+
|
83
|
+
// Slots
|
84
|
+
|
85
|
+
// Slots without accessort (defined in class comment)
|
86
|
+
if (hasTag(classParsedJsDoc, "slot") && currClass.slots) {
|
87
|
+
const slotTags = findAllTags(classParsedJsDoc, "slot");
|
88
|
+
|
89
|
+
currClass.slots.forEach(slot => {
|
90
|
+
const tag = slotTags.find(tag => tag.name === slot.name);
|
91
|
+
|
92
|
+
const typeRefs = (normalizeTagType(tag.type)
|
93
|
+
?.replaceAll(/Array<|>|\[\]/g, "")
|
94
|
+
?.split("|")
|
95
|
+
?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path)).filter(Boolean));
|
96
|
+
|
97
|
+
slot._ui5privacy = "public";
|
98
|
+
slot._ui5type = { text: formatArrays(normalizeTagType(tag.type)) };
|
99
|
+
slot.description = normalizeDescription(tag.description)
|
100
|
+
|
101
|
+
if (typeRefs && typeRefs.length) {
|
102
|
+
slot._ui5type.references = typeRefs;
|
103
|
+
}
|
104
|
+
|
105
|
+
delete slot.type
|
106
|
+
})
|
107
|
+
}
|
108
|
+
|
109
|
+
// Events
|
110
|
+
currClass.events = findAllDecorators(classNode, "event")
|
111
|
+
?.map(event => processEvent(ts, event, classNode, moduleDoc));
|
112
|
+
|
113
|
+
// Slots (with accessor), methods and fields
|
114
|
+
for (let i = 0; i < (currClass.members?.length || 0); i++) {
|
115
|
+
const member = currClass.members[i];
|
116
|
+
const classNodeMember = classNode.members?.find(nodeMember => nodeMember.name?.text === member?.name && nodeMember.jsDoc?.[0]);
|
117
|
+
const classNodeMemberJSdoc = classNodeMember?.jsDoc?.[0];
|
118
|
+
|
119
|
+
if (!classNodeMember || !classNodeMemberJSdoc) continue;
|
120
|
+
|
121
|
+
const memberParsedJsDoc = parse(classNodeMemberJSdoc?.getText())[0];
|
122
|
+
|
123
|
+
member._ui5since = getSinceStatus(memberParsedJsDoc);
|
124
|
+
member.deprecated === "true" && (member.deprecated = true)
|
125
|
+
|
126
|
+
// Slots with accessors are treated like fields by the tool, so we have to convert them into slots.
|
127
|
+
if (member.kind === "field") {
|
128
|
+
const slotDecorator = findDecorator(classNodeMember, "slot");
|
129
|
+
validateJSDocComment(slotDecorator ? "slot" : (member.readonly ? "getter" : "field"), memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
|
130
|
+
|
131
|
+
const typeRefs = (getTypeRefs(ts, classNodeMember, member)
|
132
|
+
?.map(e => getReference(ts, e, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
|
133
|
+
|
134
|
+
if (member.type?.text) {
|
135
|
+
member.type.text = formatArrays(member.type.text);
|
136
|
+
}
|
137
|
+
|
138
|
+
if (member.type && typeRefs.length) {
|
139
|
+
member.type.references = typeRefs;
|
140
|
+
}
|
141
|
+
|
142
|
+
if (slotDecorator) {
|
143
|
+
if (!currClass.slots) currClass.slots = [];
|
144
|
+
|
145
|
+
const slot = currClass.members.splice(i, 1)[0];
|
146
|
+
const defaultProperty = slotDecorator.expression?.arguments?.[0]?.properties?.find(property => property.name.text === "default");
|
147
|
+
|
148
|
+
// name of the default slot declared with decorator will be overriden so we to provide it's accessor name
|
149
|
+
if (defaultProperty && defaultProperty.initializer?.kind === ts.SyntaxKind.TrueKeyword) {
|
150
|
+
slot._ui5propertyName = slot.name;
|
151
|
+
slot.name = "default";
|
152
|
+
}
|
153
|
+
|
154
|
+
// Slots don't have type, privacy and kind, so we have do convert them and to clean unused props
|
155
|
+
member._ui5type = member.type;
|
156
|
+
member._ui5privacy = member.privacy;
|
157
|
+
delete member.type;
|
158
|
+
delete member.privacy;
|
159
|
+
delete slot.kind;
|
160
|
+
|
161
|
+
currClass.slots.push(slot);
|
162
|
+
i--;
|
163
|
+
} else {
|
164
|
+
const propertyDecorator = findDecorator(classNodeMember, "property");
|
165
|
+
|
166
|
+
if (propertyDecorator) {
|
167
|
+
member._ui5validator = propertyDecorator?.expression?.arguments[0]?.properties?.find(property => ["validator", "type"].includes(property.name.text))?.initializer?.text || "String";
|
168
|
+
}
|
169
|
+
|
170
|
+
if (hasTag(memberParsedJsDoc, "formProperty")) {
|
171
|
+
member._ui5formProperty = true;
|
172
|
+
}
|
173
|
+
|
174
|
+
const formEventsTag = findTag(memberParsedJsDoc, "formEvents");
|
175
|
+
if (formEventsTag) {
|
176
|
+
const tagValue = formEventsTag.description ? `${formEventsTag.name} ${formEventsTag.description}` : formEventsTag.name;
|
177
|
+
member._ui5formEvents = tagValue.trim().replaceAll(/\s+/g, ",");
|
178
|
+
}
|
179
|
+
|
180
|
+
const defaultTag = findTag(memberParsedJsDoc, "default");
|
181
|
+
if (defaultTag) {
|
182
|
+
const tagValue = defaultTag.source?.[0]?.tokens?.name || defaultTag.source?.[0]?.tokens?.description || defaultTag.source?.[0]?.tokens?.type || "";
|
183
|
+
member.default = tagValue;
|
184
|
+
}
|
185
|
+
|
186
|
+
if (member.privacy === "public") {
|
187
|
+
const JSDocErrors = getJSDocErrors();
|
188
|
+
|
189
|
+
if (!member.default) {
|
190
|
+
JSDocErrors.push(
|
191
|
+
`=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Default value is missing`
|
192
|
+
);
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
// Getters are treated as fields so they should not have return, instead of return they should have default value defined with @default
|
197
|
+
if (member.readonly) {
|
198
|
+
if (member.privacy === "public" && !member.type) {
|
199
|
+
const JSDocErrors = getJSDocErrors();
|
200
|
+
|
201
|
+
JSDocErrors.push(
|
202
|
+
`=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Missing return type`
|
203
|
+
);
|
204
|
+
}
|
205
|
+
|
206
|
+
delete member.return;
|
207
|
+
}
|
208
|
+
}
|
209
|
+
} else if (member.kind === "method") {
|
210
|
+
validateJSDocComment("method", memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
|
211
|
+
|
212
|
+
member.parameters?.forEach(param => {
|
213
|
+
// Treat every parameter that has respective @param tag as public
|
214
|
+
param._ui5privacy = findAllTags(memberParsedJsDoc, "param").some(tag => tag.name === param.name) ? "public" : "private";
|
215
|
+
if (param._ui5privacy === "public") {
|
216
|
+
const paramNode = classNodeMember.parameters?.find(parameter => parameter.name?.text === param.name);
|
217
|
+
let type;
|
218
|
+
|
219
|
+
if (param.optional) {
|
220
|
+
const filename = classNode.getSourceFile().fileName;
|
221
|
+
|
222
|
+
const sourceFile = typeProgram.getSourceFile(filename);
|
223
|
+
const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
|
224
|
+
const tsProgramMember = tsProgramClassNode.members.find(m => ts.isMethodDeclaration(m) && m.name?.text === member.name);
|
225
|
+
const tsProgramParameter = tsProgramMember.parameters.find(p => ts.isParameter(p) && p.name?.text === param.name);
|
226
|
+
|
227
|
+
if (tsProgramParameter) {
|
228
|
+
const typeName = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramParameter), tsProgramParameter);
|
229
|
+
|
230
|
+
if (!param.type) {
|
231
|
+
param.type = {};
|
232
|
+
param.type.text = typeName;
|
233
|
+
}
|
234
|
+
|
235
|
+
type = typeName.replaceAll(/Array<|>|\[\]/g, "")
|
236
|
+
?.split("|");
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
const typeRefs = ((type || getTypeRefs(ts, (type || paramNode), param))
|
241
|
+
?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
|
242
|
+
|
243
|
+
if (typeRefs.length) {
|
244
|
+
param.type.references = typeRefs;
|
245
|
+
}
|
246
|
+
}
|
247
|
+
});
|
248
|
+
|
249
|
+
if (member.return) {
|
250
|
+
const returnTag = findTag(memberParsedJsDoc, "returns");
|
251
|
+
member.return.description = returnTag?.description ? `${returnTag.name} ${returnTag.description}` : returnTag?.name;
|
252
|
+
member.return.type.text = classNodeMember?.type?.getFullText?.()?.trim();
|
253
|
+
const typeRefs = (getTypeRefs(ts, classNodeMember, member.return)
|
254
|
+
?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
|
255
|
+
|
256
|
+
if (typeRefs.length) {
|
257
|
+
member.return.type.references = typeRefs;
|
258
|
+
}
|
259
|
+
}
|
260
|
+
|
261
|
+
if (member.privacy === "public" && !member.return) {
|
262
|
+
const JSDocErrors = getJSDocErrors();
|
263
|
+
|
264
|
+
JSDocErrors.push(
|
265
|
+
`=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Missing return type`
|
266
|
+
);
|
267
|
+
}
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}
|
271
|
+
|
272
|
+
function processInterface(ts, interfaceNode, moduleDoc) {
|
273
|
+
const interfaceJSdoc = interfaceNode?.jsDoc?.[0];
|
274
|
+
const interfaceName = interfaceNode?.name?.text;
|
275
|
+
|
276
|
+
if (!interfaceJSdoc) return;
|
277
|
+
|
278
|
+
const interfaceParsedJsDoc = parse(interfaceJSdoc?.getText(), { spacing: 'preserve' })[0];
|
279
|
+
|
280
|
+
validateJSDocComment("interface", interfaceParsedJsDoc, interfaceNode.name?.text, moduleDoc);
|
281
|
+
|
282
|
+
moduleDoc.declarations.push({
|
283
|
+
kind: "interface",
|
284
|
+
name: interfaceName,
|
285
|
+
description: normalizeDescription(interfaceParsedJsDoc?.description),
|
286
|
+
_ui5privacy: getPrivacyStatus(interfaceParsedJsDoc),
|
287
|
+
_ui5since: getSinceStatus(interfaceParsedJsDoc),
|
288
|
+
deprecated: getDeprecatedStatus(interfaceParsedJsDoc),
|
289
|
+
});
|
290
|
+
}
|
291
|
+
|
292
|
+
function processEnum(ts, enumNode, moduleDoc) {
|
293
|
+
const enumJSdoc = enumNode?.jsDoc?.[0];
|
294
|
+
const enumName = enumNode?.name?.text;
|
295
|
+
|
296
|
+
if (!enumJSdoc) return;
|
297
|
+
|
298
|
+
const enumParsedJsDoc = parse(enumJSdoc?.getText(), { spacing: 'preserve' })[0];
|
299
|
+
|
300
|
+
validateJSDocComment("enum", enumParsedJsDoc, enumNode.name?.text, moduleDoc);
|
301
|
+
|
302
|
+
const result = {
|
303
|
+
kind: "enum",
|
304
|
+
name: enumName,
|
305
|
+
description: normalizeDescription(enumJSdoc?.comment),
|
306
|
+
_ui5privacy: getPrivacyStatus(enumParsedJsDoc),
|
307
|
+
_ui5since: getSinceStatus(enumParsedJsDoc),
|
308
|
+
deprecated: getDeprecatedStatus(enumParsedJsDoc) || undefined,
|
309
|
+
members: (enumNode?.members || []).map(member => {
|
310
|
+
const memberJSdoc = member?.jsDoc?.[0];
|
311
|
+
|
312
|
+
if (!memberJSdoc) return;
|
313
|
+
|
314
|
+
const memberParsedJsDoc = parse(memberJSdoc?.getText())[0];
|
315
|
+
|
316
|
+
validateJSDocComment("enum", memberParsedJsDoc, member.name?.text, moduleDoc);
|
317
|
+
|
318
|
+
return {
|
319
|
+
kind: "field",
|
320
|
+
static: true,
|
321
|
+
privacy: getPrivacyStatus(memberParsedJsDoc),
|
322
|
+
_ui5since: getSinceStatus(memberParsedJsDoc),
|
323
|
+
description: memberJSdoc?.comment,
|
324
|
+
default: member.initializer?.text,
|
325
|
+
deprecated: getDeprecatedStatus(memberParsedJsDoc),
|
326
|
+
name: member.name?.text,
|
327
|
+
readonly: true,
|
328
|
+
};
|
329
|
+
}).filter(Boolean),
|
330
|
+
};
|
331
|
+
|
332
|
+
moduleDoc.declarations.push(result);
|
333
|
+
}
|
334
|
+
|
335
|
+
const processPublicAPI = object => {
|
336
|
+
if (!object) {
|
337
|
+
return true;
|
338
|
+
}
|
339
|
+
const keys = Object.keys(object);
|
340
|
+
if (!keys.includes("privacy") && !keys.includes("_ui5privacy")) {
|
341
|
+
return true;
|
342
|
+
}
|
343
|
+
for (const key of keys) {
|
344
|
+
if ((key === "privacy" && object[key] !== "public") || (key === "_ui5privacy" && object[key] !== "public")) {
|
345
|
+
return true;
|
346
|
+
} else if (typeof object[key] === "object") {
|
347
|
+
if (key === "cssParts" || key === "_ui5implements") {
|
348
|
+
continue;
|
349
|
+
}
|
350
|
+
|
351
|
+
if (Array.isArray(object[key])) {
|
352
|
+
for (let i = 0; i < object[key].length; i++) {
|
353
|
+
const shouldRemove = processPublicAPI(object[key][i]);
|
354
|
+
if (shouldRemove) {
|
355
|
+
object[key].splice(i, 1);
|
356
|
+
i--;
|
357
|
+
}
|
358
|
+
}
|
359
|
+
if (object[key].length === 0) {
|
360
|
+
delete object[key];
|
361
|
+
}
|
362
|
+
}
|
363
|
+
}
|
364
|
+
}
|
365
|
+
return false;
|
366
|
+
};
|
367
|
+
|
368
|
+
let typeChecker;
|
369
|
+
let typeProgram;
|
370
|
+
|
371
|
+
export default {
|
372
|
+
globs: ["src/!(*generated)/*.ts", "src/!(*bundle)*.ts"],
|
373
|
+
outdir: 'dist',
|
374
|
+
overrideModuleCreation: ({ ts, globs }) => {
|
375
|
+
typeProgram = ts.createProgram(globs, {
|
376
|
+
noEmitOnError: false,
|
377
|
+
allowJs: true,
|
378
|
+
experimentalDecorators: true,
|
379
|
+
target: 99,
|
380
|
+
downlevelIteration: true,
|
381
|
+
module: 99,
|
382
|
+
strictNullChecks: true,
|
383
|
+
moduleResolution: 2,
|
384
|
+
esModuleInterop: true,
|
385
|
+
noEmit: true,
|
386
|
+
pretty: true,
|
387
|
+
allowSyntheticDefaultImports: true,
|
388
|
+
allowUnreachableCode: true,
|
389
|
+
allowUnusedLabels: true,
|
390
|
+
skipLibCheck: true,
|
391
|
+
});
|
392
|
+
typeChecker = typeProgram.getTypeChecker();
|
393
|
+
|
394
|
+
return globs.map((glob) => {
|
395
|
+
const fullPath = path.resolve(process.cwd(), glob);
|
396
|
+
const source = fs.readFileSync(fullPath).toString();
|
397
|
+
|
398
|
+
return ts.createSourceFile(glob, source, ts.ScriptTarget.ES2015, true);
|
399
|
+
});
|
400
|
+
},
|
401
|
+
plugins: [
|
402
|
+
{
|
403
|
+
name: 'my-plugin',
|
404
|
+
analyzePhase({ ts, node, moduleDoc }) {
|
405
|
+
switch (true) {
|
406
|
+
case ts.isClassDeclaration(node):
|
407
|
+
processClass(ts, node, moduleDoc);
|
408
|
+
break;
|
409
|
+
case ts.isEnumDeclaration(node):
|
410
|
+
processEnum(ts, node, moduleDoc);
|
411
|
+
break;
|
412
|
+
case ts.isInterfaceDeclaration(node):
|
413
|
+
processInterface(ts, node, moduleDoc);
|
414
|
+
break;
|
415
|
+
}
|
416
|
+
},
|
417
|
+
moduleLinkPhase({ moduleDoc }) {
|
418
|
+
for (let i = 0; i < moduleDoc.declarations.length; i++) {
|
419
|
+
const shouldRemove = processPublicAPI(moduleDoc.declarations[i]) || ["function", "variable"].includes(moduleDoc.declarations[i].kind)
|
420
|
+
if (shouldRemove) {
|
421
|
+
moduleDoc.declarations.splice(i, 1);
|
422
|
+
i--;
|
423
|
+
}
|
424
|
+
}
|
425
|
+
|
426
|
+
moduleDoc.path = moduleDoc.path?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
|
427
|
+
|
428
|
+
if (moduleDoc.exports) {
|
429
|
+
moduleDoc.exports = moduleDoc.exports.
|
430
|
+
filter(e => !(e.kind === "custom-element-definition" && !moduleDoc.declarations?.find(d => d.name === e.name)?.tagName))
|
431
|
+
|
432
|
+
moduleDoc.exports?.forEach(e => {
|
433
|
+
const classNode = moduleDoc.declarations.find(c => c.name === e.declaration.name);
|
434
|
+
|
435
|
+
if (e.declaration && e.declaration.module) {
|
436
|
+
e.declaration.module = e.declaration.module.replace(/^src/, "dist").replace(/\.ts$/, ".js");
|
437
|
+
}
|
438
|
+
|
439
|
+
if (classNode?.customElement && classNode.tagName && e.kind !== "custom-element-definition") {
|
440
|
+
moduleDoc.exports.push({
|
441
|
+
kind: "custom-element-definition",
|
442
|
+
name: classNode.tagName,
|
443
|
+
declaration: {
|
444
|
+
name: e.declaration.name,
|
445
|
+
module: e.declaration.module
|
446
|
+
}
|
447
|
+
})
|
448
|
+
}
|
449
|
+
})
|
450
|
+
}
|
451
|
+
|
452
|
+
const typeReferences = new Set();
|
453
|
+
const registerTypeReference = reference => typeReferences.add(JSON.stringify(reference))
|
454
|
+
|
455
|
+
moduleDoc.declarations.forEach(declaration => {
|
456
|
+
["events", "slots", "members"].forEach(memberType => {
|
457
|
+
declaration[memberType]?.forEach(member => {
|
458
|
+
if (member.type?.references) {
|
459
|
+
member.type.references.forEach(registerTypeReference)
|
460
|
+
} else if (member._ui5type?.references) {
|
461
|
+
member._ui5type.references.forEach(registerTypeReference)
|
462
|
+
} else if (member.kind === "method") {
|
463
|
+
member.return?.type?.references?.forEach(registerTypeReference)
|
464
|
+
|
465
|
+
member.parameters?.forEach(parameter => {
|
466
|
+
parameter.type?.references?.forEach(registerTypeReference)
|
467
|
+
})
|
468
|
+
}
|
469
|
+
})
|
470
|
+
})
|
471
|
+
});
|
472
|
+
|
473
|
+
for (let reference in typeReferences) {
|
474
|
+
reference = JSON.parse(reference);
|
475
|
+
|
476
|
+
if (reference.package === packageJSON?.name && reference.module === moduleDoc.path) {
|
477
|
+
const hasExport = moduleDoc.exports.some(e => e.declaration?.name === reference.name && e.declaration?.module === reference.module)
|
478
|
+
|
479
|
+
if (!hasExport) {
|
480
|
+
const JSDocErrors = getJSDocErrors();
|
481
|
+
JSDocErrors.push(
|
482
|
+
`=== ERROR: Problem found with ${reference.name} type reference in ${moduleDoc.path?.replace(/^dist/, "src").replace(/\.js$/, ".ts")}: \n\t- ${reference.name} is used as type of public API, but it's not exported`)
|
483
|
+
}
|
484
|
+
}
|
485
|
+
}
|
486
|
+
},
|
487
|
+
packageLinkPhase({ context }) {
|
488
|
+
if (context.dev) {
|
489
|
+
const JSDocErrors = getJSDocErrors();
|
490
|
+
if (JSDocErrors.length > 0) {
|
491
|
+
console.log(JSDocErrors.join("\n"));
|
492
|
+
console.log(`Invalid JSDoc. ${JSDocErrors.length} were found.`);
|
493
|
+
throw new Error(`Invalid JSDoc.`);
|
494
|
+
}
|
495
|
+
}
|
496
|
+
}
|
497
|
+
},
|
498
|
+
],
|
499
|
+
};
|