@ui5/webcomponents-tools 0.0.0-918b4fbe7 → 0.0.0-9261ac932

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 (69) hide show
  1. package/CHANGELOG.md +1305 -0
  2. package/README.md +3 -5
  3. package/assets-meta.js +15 -10
  4. package/components-package/cypress/support/commands.js +39 -0
  5. package/components-package/cypress/support/component-index.html +17 -0
  6. package/components-package/cypress/support/component.d.ts +23 -0
  7. package/components-package/cypress/support/component.js +34 -0
  8. package/components-package/cypress.config.js +19 -0
  9. package/components-package/eslint.js +61 -15
  10. package/components-package/nps.js +68 -49
  11. package/components-package/postcss.components.js +1 -21
  12. package/components-package/postcss.themes.js +1 -26
  13. package/components-package/vite.config.js +6 -5
  14. package/components-package/wdio.js +42 -13
  15. package/icons-collection/nps.js +13 -8
  16. package/lib/amd-to-es6/index.js +102 -0
  17. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  18. package/lib/cem/custom-elements-manifest.config.mjs +527 -0
  19. package/lib/cem/event.mjs +148 -0
  20. package/lib/cem/schema-internal.json +1413 -0
  21. package/lib/cem/schema.json +1098 -0
  22. package/lib/cem/types-internal.d.ts +808 -0
  23. package/lib/cem/types.d.ts +736 -0
  24. package/lib/cem/utils.mjs +398 -0
  25. package/lib/cem/validate.js +70 -0
  26. package/lib/copy-list/index.js +2 -2
  27. package/lib/create-icons/index.js +38 -13
  28. package/lib/create-illustrations/index.js +51 -30
  29. package/lib/create-new-component/index.js +59 -101
  30. package/lib/create-new-component/tsFileContentTemplate.js +71 -0
  31. package/lib/css-processors/css-processor-components.mjs +77 -0
  32. package/lib/css-processors/css-processor-themes.mjs +79 -0
  33. package/lib/css-processors/scope-variables.mjs +49 -0
  34. package/lib/css-processors/shared.mjs +76 -0
  35. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  36. package/lib/dev-server/{dev-server.js → dev-server.mjs} +4 -4
  37. package/lib/dev-server/virtual-index-html-plugin.js +2 -2
  38. package/lib/generate-js-imports/illustrations.js +78 -64
  39. package/lib/generate-json-imports/i18n.js +45 -61
  40. package/lib/generate-json-imports/themes.js +16 -33
  41. package/lib/hbs2lit/src/compiler.js +9 -6
  42. package/lib/hbs2lit/src/litVisitor2.js +42 -17
  43. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  44. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
  45. package/lib/hbs2ui5/index.js +23 -6
  46. package/lib/i18n/defaults.js +11 -3
  47. package/lib/i18n/toJSON.js +1 -1
  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 +10 -2
  54. package/package.json +26 -12
  55. package/tsconfig.json +16 -0
  56. package/types/index.d.ts +1 -0
  57. package/components-package/wdio.sync.js +0 -360
  58. package/lib/esm-abs-to-rel/index.js +0 -58
  59. package/lib/generate-custom-elements-manifest/index.js +0 -369
  60. package/lib/jsdoc/config.json +0 -29
  61. package/lib/jsdoc/configTypescript.json +0 -29
  62. package/lib/jsdoc/plugin.js +0 -2468
  63. package/lib/jsdoc/preprocess.js +0 -60
  64. package/lib/jsdoc/template/publish.js +0 -4120
  65. package/lib/postcss-css-to-esm/index.js +0 -57
  66. package/lib/postcss-css-to-json/index.js +0 -47
  67. package/lib/postcss-new-files/index.js +0 -36
  68. package/lib/postcss-p/postcss-p.mjs +0 -14
  69. package/lib/replace-global-core/index.js +0 -25
@@ -1,3 +1,6 @@
1
+ const dns = require("node:dns");
2
+ const assert = require("chai").assert;
3
+
1
4
  exports.config = {
2
5
  //
3
6
  // ====================
@@ -56,7 +59,16 @@ exports.config = {
56
59
  'goog:chromeOptions': {
57
60
  // to run chrome headless the following flags are required
58
61
  // (see https://developers.google.com/web/updates/2017/04/headless-chrome)
59
- args: ['--headless', '--disable-gpu'],
62
+ args: [
63
+ '--headless=old',
64
+ '--disable-search-engine-choice-screen',
65
+ '--start-maximized',
66
+ '--no-sandbox',
67
+ '--disable-gpu',
68
+ '--disable-infobars',
69
+ '--disable-extensions',
70
+ '--disable-dev-shm-usage',
71
+ ],
60
72
  // args: ['--disable-gpu'],
61
73
  }
62
74
  }],
@@ -99,8 +111,7 @@ exports.config = {
99
111
  // Services take over a specific job you don't want to take care of. They enhance
100
112
  // your test setup with almost no effort. Unlike plugins, they don't add new
101
113
  // commands. Instead, they hook themselves up into the test process.
102
- services: ['chromedriver', 'devtools',
103
- ['static-server', {
114
+ services: ['chromedriver', ['static-server', {
104
115
  folders: [
105
116
  { mount: '/', path: './dist' },
106
117
  ],
@@ -153,6 +164,9 @@ exports.config = {
153
164
  */
154
165
  // beforeSession: function (config, capabilities, specs) {
155
166
  // },
167
+ beforeSession: () => {
168
+ dns.setDefaultResultOrder('ipv4first');
169
+ },
156
170
  /**
157
171
  * Gets executed before test execution begins. At this point you can access to all global
158
172
  * variables like `browser`. It is the perfect place to define custom commands.
@@ -217,12 +231,17 @@ exports.config = {
217
231
  }, this, className);
218
232
  }, true);
219
233
 
220
- await browser.addCommand("getStaticAreaItemClassName", async function(selector) {
221
- return browser.executeAsync(async (selector, done) => {
222
- const staticAreaItem = await document.querySelector(selector).getStaticAreaItemDomRef();
223
- done(staticAreaItem.host.classList[0]);
224
- }, selector);
225
- }, false);
234
+ await browser.addCommand("hasAttribute", async function(attrName) {
235
+ return browser.executeAsync((elem, attrName, done) => {
236
+ done(elem.hasAttribute(attrName));
237
+ }, this, attrName);
238
+ }, true);
239
+
240
+ await browser.addCommand("matches", async function(selector) {
241
+ return browser.executeAsync((elem, selector, done) => {
242
+ done(elem.matches(selector));
243
+ }, this, selector);
244
+ }, true);
226
245
 
227
246
  await browser.addLocatorStrategy('activeElement', (selector) => {
228
247
  return document.querySelector(selector).shadowRoot.activeElement;
@@ -238,11 +257,12 @@ exports.config = {
238
257
  "$",
239
258
  "$$",
240
259
  "getAttribute",
260
+ "hasAttribute", // custom
261
+ "matches", // custom
241
262
  "getCSSProperty",
242
263
  "getHTML",
243
264
  "getProperty",
244
265
  "getSize",
245
- "getStaticAreaItemClassName", // custom
246
266
  "getText",
247
267
  "getValue",
248
268
  "hasClass", // custom
@@ -254,7 +274,7 @@ exports.config = {
254
274
  "isFocusedDeep", // custom
255
275
  "isFocusedDeepElement", // custom
256
276
  "shadow$",
257
- "shadow$$",
277
+ "shadow$$"
258
278
  ];
259
279
  if (waitFor.includes(commandName)) {
260
280
  await browser.executeAsync(function (done) {
@@ -291,8 +311,17 @@ exports.config = {
291
311
  * Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
292
312
  * @param {Object} test test details
293
313
  */
294
- // afterTest: function (test) {
295
- // },
314
+ afterTest: async function (test) {
315
+ // fetch the browser logs and fail the test if there are `console.error` messages with the `[UI5-FWK]` marker
316
+ const logs = await browser.getLogs('browser');
317
+ const severeLogs = logs
318
+ .filter(l => l.level === "SEVERE" && l.message.includes("[UI5-FWK]"))
319
+ .map(l => l.message);
320
+
321
+ if (severeLogs.length) {
322
+ test.callback(new Error(`[${test.title}]\n\n ${severeLogs.join("\n ")}`));
323
+ }
324
+ },
296
325
  /**
297
326
  * Hook that gets executed after the suite has ended
298
327
  * @param {Object} suite suite details
@@ -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" dist/generated/assets/`,
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" dist/generated/assets/${v}/`;
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,23 +41,28 @@ const copyIconAssetsCommand = (options) => {
41
41
  const getScripts = (options) => {
42
42
  const createJSImportsCmd = createIconImportsCommand(options);
43
43
  const copyAssetsCmd = copyIconAssetsCommand(options);
44
+ const tsCommand = !options.legacy ? "tsc --build" : "";
45
+ const tsCrossEnv = !options.legacy ? "cross-env UI5_TS=true" : "";
44
46
 
45
47
  const scripts = {
46
- clean: "rimraf dist",
48
+ clean: "rimraf dist && rimraf src/generated",
47
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/",
48
52
  build: {
49
- default: `nps clean copy build.i18n build.icons build.jsonImports`,
53
+ default: `${tsCrossEnv} nps clean copy build.i18n typescript build.icons build.jsonImports`,
50
54
  i18n: {
51
55
  default: "nps build.i18n.defaultsjs build.i18n.json",
52
- defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n dist/generated/i18n`,
53
- json: `mkdirp dist/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n dist/generated/assets/i18n`,
56
+ defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
57
+ json: `mkdirp src/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n src/generated/assets/i18n`,
54
58
  },
55
59
  jsonImports: {
56
- default: "mkdirp dist/generated/json-imports && nps build.jsonImports.i18n",
57
- i18n: `node "${LIB}/generate-json-imports/i18n.js" dist/generated/assets/i18n dist/generated/json-imports`,
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`,
58
62
  },
59
63
  icons: createJSImportsCmd,
60
64
  },
65
+ typescript: tsCommand,
61
66
  };
62
67
 
63
68
  return scripts;
@@ -0,0 +1,102 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+ const basePath = process.argv[2];
4
+ const babelCore = require("@babel/core");
5
+ const babelParser = require("@babel/parser");
6
+ const babelGenerator = require("@babel/generator").default;
7
+ const replaceAsync = require('replace-in-file');
8
+
9
+ const convertSAPUIDefineToDefine = async (filePath) => {
10
+ return replaceAsync({
11
+ files: filePath,
12
+ processor: (input) => {
13
+ return input.replace("sap.ui.define", "define").replace(", /* bExport= */ false", "").replace(", /* bExport= */ true", "");
14
+ }
15
+ })
16
+ }
17
+
18
+ const convertAmdToEs6 = async (code) => {
19
+ return (await babelCore.transformAsync(code, {
20
+ plugins: [['babel-plugin-amd-to-esm', {}]]
21
+ })).code;
22
+ }
23
+
24
+ const convertAbsImportsToRelative = (filePath, code) => {
25
+ let changed = false;
26
+ // console.log("File processing started: ", srcPath);
27
+
28
+ if (code.includes("import(")) {
29
+ // esprima can't parse this, but it's from the project files
30
+ return;
31
+ }
32
+
33
+ const tree = babelParser.parse(code, { sourceType: "module" });
34
+ const importer = filePath.replace(basePath, "");
35
+ const importerDir = path.dirname(importer);
36
+ // console.log("Importer -> ", importer);
37
+
38
+ tree?.program?.body?.forEach(node => {
39
+ if (node.type === "ImportDeclaration") {
40
+ let importee = node.source.value;
41
+ // console.log(importee);
42
+ if (importee.startsWith(".")) {
43
+ // add .js extension if missing
44
+ if (!importee.endsWith(".js")) {
45
+ node.source.value += ".js"
46
+ changed = true;
47
+ }
48
+ return;
49
+ }
50
+ let importeeDir = path.dirname(importee);
51
+ let importeeFile = path.basename(importee);
52
+ let relativePath = path.relative(importerDir, importeeDir);
53
+ if (relativePath.length === 0) {
54
+ relativePath = "."
55
+ }
56
+ if (!relativePath.startsWith(".")) {
57
+ relativePath = "./" + relativePath;
58
+ }
59
+
60
+ relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
61
+ let relativeImport = `${relativePath}/${importeeFile}.js`;
62
+ // console.log(importee + " --> " + relativeImport);
63
+ node.source.value = relativeImport;
64
+ changed = true;
65
+ }
66
+ });
67
+
68
+ return changed ? babelGenerator(tree).code : code;
69
+ }
70
+
71
+ const replaceGlobalCoreUsage = (filePath, code) => {
72
+ if (!filePath.includes("Configuration")) {
73
+ const replaced = code.replace(/sap\.ui\.getCore\(\)/g, `Core`);
74
+ return code !== replaced ? `import Core from 'sap/ui/core/Core';${replaced}` : code;
75
+ }
76
+
77
+ return code;
78
+ };
79
+
80
+ const transformAmdToES6Module = async (filePath) => {
81
+ await convertSAPUIDefineToDefine(filePath);
82
+
83
+ let code = (await fs.readFile(filePath)).toString();
84
+
85
+ code = await convertAmdToEs6(code);
86
+
87
+ code = replaceGlobalCoreUsage(filePath, code);
88
+
89
+ code = convertAbsImportsToRelative(filePath, code);
90
+
91
+ return fs.writeFile(filePath, code);
92
+ }
93
+
94
+ const transformAmdToES6Modules = async () => {
95
+ const { globby } = await import("globby");
96
+ const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
97
+ return Promise.all(fileNames.map(transformAmdToES6Module).filter(x => !!x));
98
+ };
99
+
100
+ transformAmdToES6Modules().then(() => {
101
+ console.log("Success: all amd modules are transformed to es6!");
102
+ });
@@ -0,0 +1,33 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+ const basePath = process.argv[2];
4
+ const babelCore = require("@babel/core");
5
+ const babelParser = require("@babel/parser");
6
+ const babelGenerator = require("@babel/generator").default;
7
+ const walk = require("estree-walk");
8
+
9
+ const checkHasRequire = (filePath, code) => {
10
+ code = code.replace(/sap\.ui\.require/g, "unhandledRequire");
11
+
12
+ const tree = babelParser.parse(code, { sourceType: "module" });
13
+ walk(tree, {
14
+ CallExpression: function (node) {
15
+ if (node.type === "CallExpression" && node?.callee?.name === "unhandledRequire") {
16
+ throw new Error(`sap.ui.require found in ${filePath}`);
17
+ }
18
+ }
19
+ });
20
+ }
21
+
22
+ const checkFile = async (filePath) => {
23
+ let code = (await fs.readFile(filePath)).toString();
24
+ checkHasRequire(filePath, code);
25
+ }
26
+
27
+ const checkAll = async () => {
28
+ const { globby } = await import("globby");
29
+ const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
30
+ return Promise.all(fileNames.map(checkFile).filter(x => !!x));
31
+ };
32
+
33
+ checkAll();