@ui5/webcomponents-tools 0.0.0-d0bcf47c7 → 0.0.0-d473b9686

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 (62) hide show
  1. package/CHANGELOG.md +1410 -1
  2. package/README.md +6 -6
  3. package/assets-meta.js +158 -0
  4. package/bin/dev.js +12 -1
  5. package/components-package/eslint.js +36 -0
  6. package/components-package/nps.js +122 -46
  7. package/components-package/postcss.components.js +1 -21
  8. package/components-package/postcss.themes.js +1 -23
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +152 -65
  11. package/icons-collection/nps.js +71 -28
  12. package/lib/amd-to-es6/index.js +102 -0
  13. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  14. package/lib/cem/custom-elements-manifest.config.mjs +501 -0
  15. package/lib/cem/event.mjs +131 -0
  16. package/lib/cem/schema-internal.json +1357 -0
  17. package/lib/cem/schema.json +1098 -0
  18. package/lib/cem/types-internal.d.ts +796 -0
  19. package/lib/cem/types.d.ts +736 -0
  20. package/lib/cem/utils.mjs +384 -0
  21. package/lib/cem/validate.js +70 -0
  22. package/lib/copy-and-watch/index.js +145 -0
  23. package/lib/copy-list/index.js +28 -0
  24. package/lib/create-icons/index.js +126 -0
  25. package/lib/create-illustrations/index.js +182 -0
  26. package/lib/create-new-component/index.js +114 -0
  27. package/lib/create-new-component/tsFileContentTemplate.js +71 -0
  28. package/lib/css-processors/css-processor-component-styles.mjs +48 -0
  29. package/lib/css-processors/css-processor-components.mjs +77 -0
  30. package/lib/css-processors/css-processor-themes.mjs +79 -0
  31. package/lib/css-processors/scope-variables.mjs +49 -0
  32. package/lib/css-processors/shared.mjs +76 -0
  33. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  34. package/lib/dev-server/dev-server.js +66 -0
  35. package/lib/dev-server/ssr-dom-shim-loader.js +26 -0
  36. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  37. package/lib/generate-js-imports/illustrations.js +86 -0
  38. package/lib/generate-json-imports/i18n.js +71 -0
  39. package/lib/generate-json-imports/themes.js +58 -0
  40. package/lib/hbs2lit/index.js +3 -0
  41. package/lib/hbs2lit/src/compiler.js +60 -0
  42. package/lib/hbs2lit/src/extendedAttributeMapping.js +12 -0
  43. package/lib/hbs2lit/src/includesReplacer.js +31 -0
  44. package/lib/hbs2lit/src/litVisitor2.js +278 -0
  45. package/lib/hbs2lit/src/partials2.js +51 -0
  46. package/lib/hbs2lit/src/partialsVisitor.js +187 -0
  47. package/lib/hbs2lit/src/svgProcessor.js +76 -0
  48. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +40 -0
  49. package/lib/hbs2ui5/index.js +119 -0
  50. package/lib/i18n/defaults.js +82 -0
  51. package/lib/i18n/toJSON.js +43 -0
  52. package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
  53. package/lib/remove-dev-mode/remove-dev-mode.mjs +37 -0
  54. package/lib/scoping/get-all-tags.js +37 -0
  55. package/lib/scoping/lint-src.js +32 -0
  56. package/lib/scoping/missing-dependencies.js +65 -0
  57. package/lib/scoping/report-tags-usage.js +28 -0
  58. package/lib/scoping/scope-test-pages.js +41 -0
  59. package/lib/test-runner/test-runner.js +71 -0
  60. package/package.json +56 -55
  61. package/bin/init-ui5-package.js +0 -3
  62. package/package-lock.json +0 -9994
@@ -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
  // ====================
@@ -50,13 +53,21 @@ exports.config = {
50
53
  // maxInstances can get overwritten per capability. So if you have an in-house Selenium
51
54
  // grid with only 5 firefox instances available you can make sure that not more than
52
55
  // 5 instances get started at a time.
53
- maxInstances: process.env.TRAVIS ? 1 : 5,
56
+ maxInstances: 5,
54
57
  //
55
58
  browserName: 'chrome',
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',
64
+ '--start-maximized',
65
+ '--no-sandbox',
66
+ '--disable-gpu',
67
+ '--disable-infobars',
68
+ '--disable-extensions',
69
+ '--disable-dev-shm-usage',
70
+ ],
60
71
  // args: ['--disable-gpu'],
61
72
  }
62
73
  }],
@@ -82,7 +93,7 @@ exports.config = {
82
93
  // with `/`, the base url gets prepended, not including the path portion of your baseUrl.
83
94
  // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
84
95
  // gets prepended directly.
85
- baseUrl: '',
96
+ baseUrl: 'http://localhost:4567', // This is important since WDIO 7+ does not accept an empty string for baseUrl
86
97
  path: '',
87
98
  //
88
99
  // Default timeout for all waitFor* commands.
@@ -99,7 +110,13 @@ exports.config = {
99
110
  // Services take over a specific job you don't want to take care of. They enhance
100
111
  // your test setup with almost no effort. Unlike plugins, they don't add new
101
112
  // commands. Instead, they hook themselves up into the test process.
102
- services: ['chromedriver'],
113
+ services: ['chromedriver', ['static-server', {
114
+ folders: [
115
+ { mount: '/', path: './dist' },
116
+ ],
117
+ port: '4567',
118
+ }],
119
+ ],
103
120
  // options
104
121
  chromeDriverArgs: ['--port=9515'], // default
105
122
  // Framework you want to run your specs with.
@@ -146,52 +163,33 @@ exports.config = {
146
163
  */
147
164
  // beforeSession: function (config, capabilities, specs) {
148
165
  // },
166
+ beforeSession: () => {
167
+ dns.setDefaultResultOrder('ipv4first');
168
+ },
149
169
  /**
150
170
  * Gets executed before test execution begins. At this point you can access to all global
151
171
  * variables like `browser`. It is the perfect place to define custom commands.
152
172
  * @param {Array.<Object>} capabilities list of capabilities details
153
173
  * @param {Array.<String>} specs List of spec file paths that are to be run
154
174
  */
155
- before: function (capabilities, specs) {
156
- browser.addCommand("findElementDeep", function (selector) {
157
- const selectors = selector.split(">>>");
175
+ before: async function (capabilities, specs) {
176
+ await browser.addCommand("isFocusedDeep", async function () {
177
+ return browser.executeAsync(function (elem, done) {
178
+ let activeElement = document.activeElement;
158
179
 
159
- for (var i = 0; i < selectors.length; i++) {
160
- if (i === 0) {
161
- curElement = browser.$(selectors[i]);
162
- continue;
180
+ while (activeElement.shadowRoot) {
181
+ if (activeElement.shadowRoot.activeElement) {
182
+ activeElement = activeElement.shadowRoot.activeElement;
183
+ } else {
184
+ break;
185
+ }
163
186
  }
187
+ done(elem === activeElement);
188
+ }, this);
189
+ }, true);
164
190
 
165
- // wait for the shadowDom to be filled before executing the selector
166
- browser.executeAsync(function (elem, done) {
167
- elem._waitForDomRef().then(done);
168
- }, curElement);
169
-
170
- // find the next element from the selector
171
- curElement = curElement.$(new Function (`
172
- return this.shadowRoot.querySelector("${selectors[i]}");
173
- `));
174
- }
175
-
176
- return curElement;
177
-
178
- });
179
-
180
- browser.addCommand("findElementDeep", function (selector) {
181
- const selectors = selector.split(">>>");
182
- let curElement = this;
183
-
184
- for (var i = 0; i < selectors.length; i++) {
185
- curElement = curElement.$(new Function (`
186
- return this.shadowRoot.querySelector("${selectors[i]}");
187
- `));
188
- }
189
-
190
- return curElement;
191
- }, this);
192
-
193
- browser.addCommand("isFocusedDeep", function () {
194
- return browser.execute(function (elem) {
191
+ await browser.addCommand("isFocusedDeepElement", async function (element) {
192
+ return browser.executeAsync(function (elem, element, done) {
195
193
  let activeElement = document.activeElement;
196
194
 
197
195
  while (activeElement.shadowRoot) {
@@ -201,41 +199,88 @@ exports.config = {
201
199
  break;
202
200
  }
203
201
  }
204
- return elem === activeElement;
205
- }, this);
202
+ done(element === activeElement);
203
+ }, this, element);
206
204
  }, true);
207
205
 
208
- browser.addCommand("setProperty", function(property, value) {
209
- return browser.execute((elem, property, value) => {
210
- return elem[property] = value;
206
+ await browser.addCommand("setProperty", async function(property, value) {
207
+ return browser.executeAsync((elem, property, value, done) => {
208
+ elem[property] = value;
209
+ done();
211
210
  }, this, property, value);
212
211
  }, true);
213
212
 
214
- browser.addCommand("setAttribute", function(attribute, value) {
215
- return browser.execute((elem, attribute, value) => {
216
- return elem.setAttribute(attribute, value);
213
+ await browser.addCommand("setAttribute", async function(attribute, value) {
214
+ return browser.executeAsync((elem, attribute, value, done) => {
215
+ elem.setAttribute(attribute, value);
216
+ done();
217
217
  }, this, attribute, value);
218
218
  }, true);
219
219
 
220
- browser.addCommand("removeAttribute", function(attribute) {
221
- return browser.execute((elem, attribute) => {
222
- return elem.removeAttribute(attribute);
220
+ await browser.addCommand("removeAttribute", async function(attribute) {
221
+ return browser.executeAsync((elem, attribute, done) => {
222
+ elem.removeAttribute(attribute);
223
+ done();
223
224
  }, this, attribute);
224
225
  }, true);
225
226
 
226
- browser.addCommand("hasClass", function(className) {
227
- return browser.execute((elem, className) => {
228
- return elem.classList.contains(className);
227
+ await browser.addCommand("hasClass", async function(className) {
228
+ return browser.executeAsync((elem, className, done) => {
229
+ done(elem.classList.contains(className));
229
230
  }, this, className);
230
231
  }, true);
232
+
233
+ await browser.addCommand("hasAttribute", async function(attrName) {
234
+ return browser.executeAsync((elem, attrName, done) => {
235
+ done(elem.hasAttribute(attrName));
236
+ }, this, attrName);
237
+ }, true);
238
+
239
+ await browser.addCommand("matches", async function(selector) {
240
+ return browser.executeAsync((elem, selector, done) => {
241
+ done(elem.matches(selector));
242
+ }, this, selector);
243
+ }, true);
244
+
245
+ await browser.addLocatorStrategy('activeElement', (selector) => {
246
+ return document.querySelector(selector).shadowRoot.activeElement;
247
+ });
231
248
  },
232
249
  /**
233
250
  * Runs before a WebdriverIO command gets executed.
234
251
  * @param {String} commandName hook command name
235
252
  * @param {Array} args arguments that command would receive
236
253
  */
237
- // beforeCommand: function (commandName, args) {
238
- // },
254
+ beforeCommand: async function (commandName, args) {
255
+ const waitFor = [
256
+ "$",
257
+ "$$",
258
+ "getAttribute",
259
+ "hasAttribute", // custom
260
+ "matches", // custom
261
+ "getCSSProperty",
262
+ "getHTML",
263
+ "getProperty",
264
+ "getSize",
265
+ "getText",
266
+ "getValue",
267
+ "hasClass", // custom
268
+ "isDisplayed",
269
+ "isDisplayedInViewport",
270
+ "isEnabled",
271
+ "isExisting",
272
+ "isFocused",
273
+ "isFocusedDeep", // custom
274
+ "isFocusedDeepElement", // custom
275
+ "shadow$",
276
+ "shadow$$"
277
+ ];
278
+ if (waitFor.includes(commandName)) {
279
+ await browser.executeAsync(function (done) {
280
+ window["sap-ui-webcomponents-bundle"].renderFinished().then(done);
281
+ });
282
+ }
283
+ },
239
284
 
240
285
  /**
241
286
  * Hook that gets executed before the suite starts
@@ -265,8 +310,17 @@ exports.config = {
265
310
  * Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
266
311
  * @param {Object} test test details
267
312
  */
268
- // afterTest: function (test) {
269
- // },
313
+ afterTest: async function (test, context) {
314
+ // fetch the browser logs and fail the test if there are `console.error` messages with the `[UI5-FWK]` marker
315
+ const logs = await browser.getLogs('browser');
316
+ const severeLogs = logs
317
+ .filter(l => l.level === "SEVERE" && l.message.includes("[UI5-FWK]"))
318
+ .map(l => l.message);
319
+ assert.equal(severeLogs.length, 0, `[${test.title}]\n\n ${severeLogs.join("\n ")}`)
320
+ if (severeLogs.length) {
321
+ test.callback(new Error('Framework errors detected.'))
322
+ }
323
+ },
270
324
  /**
271
325
  * Hook that gets executed after the suite has ended
272
326
  * @param {Object} suite suite details
@@ -281,13 +335,46 @@ exports.config = {
281
335
  * @param {Number} result 0 - command success, 1 - command error
282
336
  * @param {Object} error error object if any
283
337
  */
284
- afterCommand: function (commandName, args, result, error) {
285
- const waitFor = ["$", "$$", "shadow$", "click", "performActions", "elementClick", "keys", "sendKeys", "findElement", "elementClear", "elementSendKeys", "setValue", "addValue", "getHTML", "getProperty", "setAttribute", "removeAttribute", "getElementProperty"];
286
- if (waitFor.includes(commandName)) {
287
- browser.executeAsync(function (done) {
288
- // run all the tests in no conflict mode
338
+ afterCommand: async function (commandName, args, result, error) {
339
+
340
+ // url -> set configuration first
341
+ if (commandName === "url" && !args[0].includes("do-not-change-configuration")) {
342
+ await browser.executeAsync(function(done) {
289
343
  window["sap-ui-webcomponents-bundle"].configuration.setNoConflict(true);
290
- window.RenderScheduler.whenFinished().then(done);
344
+ done();
345
+ });
346
+ }
347
+
348
+ const waitFor = [
349
+ "addValue",
350
+ "clearValue",
351
+ "click",
352
+ "doubleClick",
353
+ "dragAndDrop",
354
+ "pause",
355
+ "removeAttribute", // custom
356
+ "scrollIntoView",
357
+ "setAttribute", // custom
358
+ "setProperty", // custom
359
+ "setValue",
360
+ "setWindowSize",
361
+ "touchAction",
362
+ "url",
363
+ ];
364
+
365
+ const waitForWithDelay = [
366
+ "keys",
367
+ ];
368
+
369
+ if (waitFor.includes(commandName)) {
370
+ await browser.executeAsync(function (done) {
371
+ window["sap-ui-webcomponents-bundle"].renderFinished().then(done);
372
+ });
373
+ } else if (waitForWithDelay.includes(commandName)) {
374
+ await browser.executeAsync(function (done) {
375
+ setTimeout(() => {
376
+ window["sap-ui-webcomponents-bundle"].renderFinished().then(done);
377
+ }, 10);
291
378
  });
292
379
  }
293
380
  },
@@ -1,28 +1,71 @@
1
- const path = require("path");
2
-
3
- const LIB = path.join(__dirname, `../lib/`);
4
-
5
- const getScripts = () => {
6
-
7
- const scripts = {
8
- clean: "rimraf dist",
9
- copy: {
10
- default: "nps copy.json-imports copy.icon-collections",
11
- "json-imports": 'copy-and-watch "src/**/*.js" dist/',
12
- "icon-collections": 'copy-and-watch "src/icon-collections/**/*.json" dist/generated/assets/icon-collections/'
13
- },
14
- build: {
15
- default: "nps clean copy build.i18n build.icons",
16
- i18n: {
17
- default: "nps build.i18n.defaultsjs build.i18n.json",
18
- defaultsjs: `mkdirp dist/generated/i18n && node ${LIB}/i18n/defaults.js src/i18n dist/generated/i18n`,
19
- json: `mkdirp dist/generated/assets/i18n && node ${LIB}/i18n/toJSON.js src/i18n dist/generated/assets/i18n`,
20
- },
21
- icons: `node ${LIB}/create-icons/index.js`,
22
- }
23
- };
24
-
25
- return scripts;
26
- };
27
-
28
- module.exports = getScripts;
1
+ const path = require("path");
2
+
3
+ const LIB = path.join(__dirname, `../lib/`);
4
+
5
+ const createIconImportsCommand = (options) => {
6
+ if (!options.versions) {
7
+ return `node "${LIB}/create-icons/index.js" "${options.collectionName}"`;
8
+ }
9
+
10
+ const command = { default: "nps" };
11
+ options.versions.forEach((v) => {
12
+ command.default += ` build.icons.create${v}`;
13
+ command[`create${v}`] = `node "${LIB}/create-icons/index.js" "${options.collectionName}" "${v}"`;
14
+ });
15
+
16
+ return command;
17
+ }
18
+
19
+ const copyIconAssetsCommand = (options) => {
20
+ if (!options.versions) {
21
+ return {
22
+ default: "nps copy.json-imports copy.icon-collection",
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" src/generated/assets/`,
25
+ }
26
+ }
27
+
28
+ const command = {
29
+ default: "nps copy.json-imports ",
30
+ "json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
31
+ };
32
+
33
+ options.versions.forEach((v) => {
34
+ command.default += ` copy.icon-collection${v}`;
35
+ command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" src/generated/assets/${v}/`;
36
+ });
37
+
38
+ return command;
39
+ }
40
+
41
+ const getScripts = (options) => {
42
+ const createJSImportsCmd = createIconImportsCommand(options);
43
+ const copyAssetsCmd = copyIconAssetsCommand(options);
44
+ const tsCommand = !options.legacy ? "tsc --build" : "";
45
+ const tsCrossEnv = !options.legacy ? "cross-env UI5_TS=true" : "";
46
+
47
+ const scripts = {
48
+ clean: "rimraf dist && rimraf src/generated",
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/",
52
+ build: {
53
+ default: `${tsCrossEnv} nps clean copy build.i18n typescript build.icons build.jsonImports`,
54
+ i18n: {
55
+ default: "nps build.i18n.defaultsjs build.i18n.json",
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`,
58
+ },
59
+ jsonImports: {
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`,
62
+ },
63
+ icons: createJSImportsCmd,
64
+ },
65
+ typescript: tsCommand,
66
+ };
67
+
68
+ return scripts;
69
+ };
70
+
71
+ module.exports = getScripts;
@@ -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();