@ui5/webcomponents-tools 1.14.5 → 1.14.7
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 +19 -0
- package/lib/amd-to-es6/index.js +104 -0
- package/package.json +2 -2
- package/lib/esm-abs-to-rel/index.js +0 -58
- package/lib/replace-global-core/index.js +0 -25
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,25 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [1.14.7](https://github.com/SAP/ui5-webcomponents/compare/v1.14.6...v1.14.7) (2024-01-25)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
|
11
|
+
* **framework:** update openi5/core to 1.120.3 ([#8122](https://github.com/SAP/ui5-webcomponents/issues/8122)) ([727ef13](https://github.com/SAP/ui5-webcomponents/commit/727ef13ab0aed2dc93b9dc185e2341e55992ebc1))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
## [1.14.6](https://github.com/SAP/ui5-webcomponents/compare/v1.14.5...v1.14.6) (2023-11-22)
|
18
|
+
|
19
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
6
25
|
## [1.14.5](https://github.com/SAP/ui5-webcomponents/compare/v1.14.4...v1.14.5) (2023-06-26)
|
7
26
|
|
8
27
|
**Note:** Version bump only for package @ui5/webcomponents-tools
|
@@ -0,0 +1,104 @@
|
|
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
|
+
code = code.replace(/sap\.ui\.require/g, "require");
|
20
|
+
|
21
|
+
return (await babelCore.transformAsync(code, {
|
22
|
+
plugins: [['babel-plugin-amd-to-esm', {}]]
|
23
|
+
})).code;
|
24
|
+
}
|
25
|
+
|
26
|
+
const convertAbsImportsToRelative = (filePath, code) => {
|
27
|
+
let changed = false;
|
28
|
+
// console.log("File processing started: ", srcPath);
|
29
|
+
|
30
|
+
if (code.includes("import(")) {
|
31
|
+
// esprima can't parse this, but it's from the project files
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
|
35
|
+
const tree = babelParser.parse(code, { sourceType: "module" });
|
36
|
+
const importer = filePath.replace(basePath, "");
|
37
|
+
const importerDir = path.dirname(importer);
|
38
|
+
// console.log("Importer -> ", importer);
|
39
|
+
|
40
|
+
tree?.program?.body?.forEach(node => {
|
41
|
+
if (node.type === "ImportDeclaration") {
|
42
|
+
let importee = node.source.value;
|
43
|
+
// console.log(importee);
|
44
|
+
if (importee.startsWith(".")) {
|
45
|
+
// add .js extension if missing
|
46
|
+
if (!importee.endsWith(".js")) {
|
47
|
+
node.source.value += ".js"
|
48
|
+
changed = true;
|
49
|
+
}
|
50
|
+
return;
|
51
|
+
}
|
52
|
+
let importeeDir = path.dirname(importee);
|
53
|
+
let importeeFile = path.basename(importee);
|
54
|
+
let relativePath = path.relative(importerDir, importeeDir);
|
55
|
+
if (relativePath.length === 0) {
|
56
|
+
relativePath = "."
|
57
|
+
}
|
58
|
+
if (!relativePath.startsWith(".")) {
|
59
|
+
relativePath = "./" + relativePath;
|
60
|
+
}
|
61
|
+
|
62
|
+
relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
|
63
|
+
let relativeImport = `${relativePath}/${importeeFile}.js`;
|
64
|
+
// console.log(importee + " --> " + relativeImport);
|
65
|
+
node.source.value = relativeImport;
|
66
|
+
changed = true;
|
67
|
+
}
|
68
|
+
});
|
69
|
+
|
70
|
+
return changed ? babelGenerator(tree).code : code;
|
71
|
+
}
|
72
|
+
|
73
|
+
const replaceGlobalCoreUsage = (filePath, code) => {
|
74
|
+
if (!filePath.includes("Configuration")) {
|
75
|
+
const replaced = code.replace(/sap\.ui\.getCore\(\)/g, `Core`);
|
76
|
+
return code !== replaced ? `import Core from 'sap/ui/core/Core';${replaced}` : code;
|
77
|
+
}
|
78
|
+
|
79
|
+
return code;
|
80
|
+
};
|
81
|
+
|
82
|
+
const transformAmdToES6Module = async (filePath) => {
|
83
|
+
await convertSAPUIDefineToDefine(filePath);
|
84
|
+
|
85
|
+
let code = (await fs.readFile(filePath)).toString();
|
86
|
+
|
87
|
+
code = await convertAmdToEs6(code);
|
88
|
+
|
89
|
+
code = replaceGlobalCoreUsage(filePath, code);
|
90
|
+
|
91
|
+
code = convertAbsImportsToRelative(filePath, code);
|
92
|
+
|
93
|
+
return fs.writeFile(filePath, code);
|
94
|
+
}
|
95
|
+
|
96
|
+
const transformAmdToES6Modules = async () => {
|
97
|
+
const { globby } = await import("globby");
|
98
|
+
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
99
|
+
return Promise.all(fileNames.map(transformAmdToES6Module).filter(x => !!x));
|
100
|
+
};
|
101
|
+
|
102
|
+
transformAmdToES6Modules().then(() => {
|
103
|
+
console.log("Success: all amd modules are transformed to es6!");
|
104
|
+
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ui5/webcomponents-tools",
|
3
|
-
"version": "1.14.
|
3
|
+
"version": "1.14.7",
|
4
4
|
"description": "UI5 Web Components: webcomponents.tools",
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
6
6
|
"license": "Apache-2.0",
|
@@ -79,5 +79,5 @@
|
|
79
79
|
"devDependencies": {
|
80
80
|
"yargs": "^17.5.1"
|
81
81
|
},
|
82
|
-
"gitHead": "
|
82
|
+
"gitHead": "8c67ea36fdfa3eb6780b98da607a0136afef67ef"
|
83
83
|
}
|
@@ -1,58 +0,0 @@
|
|
1
|
-
const esprima = require("esprima");
|
2
|
-
const escodegen = require("escodegen");
|
3
|
-
|
4
|
-
const fs = require("fs").promises;
|
5
|
-
const path = require("path");
|
6
|
-
const basePath = process.argv[2];
|
7
|
-
|
8
|
-
const convertImports = async (srcPath) => {
|
9
|
-
let changed = false;
|
10
|
-
// console.log("scanning imports of", srcPath);
|
11
|
-
let code = (await fs.readFile(srcPath)).toString();
|
12
|
-
const tree = esprima.parseModule(code);
|
13
|
-
const importer = srcPath.replace(basePath, "");
|
14
|
-
const importerDir = path.dirname(importer);
|
15
|
-
// console.log("-> ", importer);
|
16
|
-
tree.body.forEach(node => {
|
17
|
-
if (node.type === "ImportDeclaration") {
|
18
|
-
let importee = node.source.value;
|
19
|
-
if (importee.startsWith(".")) {
|
20
|
-
// add .js extension if missing
|
21
|
-
if (!importee.endsWith(".js")) {
|
22
|
-
node.source.value += ".js"
|
23
|
-
changed = true;
|
24
|
-
}
|
25
|
-
return;
|
26
|
-
}
|
27
|
-
let importeeDir = path.dirname(importee);
|
28
|
-
let importeeFile = path.basename(importee);
|
29
|
-
let relativePath = path.relative(importerDir, importeeDir);
|
30
|
-
if (relativePath.length === 0) {
|
31
|
-
relativePath = "."
|
32
|
-
}
|
33
|
-
if (!relativePath.startsWith(".")) {
|
34
|
-
relativePath = "./" + relativePath;
|
35
|
-
}
|
36
|
-
|
37
|
-
relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
|
38
|
-
let relativeImport = `${relativePath}/${importeeFile}.js`;
|
39
|
-
// console.log(importee + " --> " + relativeImport);
|
40
|
-
node.source.value = relativeImport;
|
41
|
-
changed = true;
|
42
|
-
}
|
43
|
-
});
|
44
|
-
|
45
|
-
if (changed) {
|
46
|
-
return fs.writeFile(srcPath, escodegen.generate(tree));
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
const generate = async () => {
|
51
|
-
const { globby } = await import("globby");
|
52
|
-
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
53
|
-
return Promise.all(fileNames.map(convertImports).filter(x => !!x));
|
54
|
-
};
|
55
|
-
|
56
|
-
generate().then(() => {
|
57
|
-
console.log("Success: Converted absolute imports to relative for files in:", basePath);
|
58
|
-
});
|
@@ -1,25 +0,0 @@
|
|
1
|
-
const fs = require("fs").promises;
|
2
|
-
|
3
|
-
const basePath = process.argv[2];
|
4
|
-
|
5
|
-
const replaceGlobalCoreUsage = async (srcPath) => {
|
6
|
-
|
7
|
-
const original = (await fs.readFile(srcPath)).toString();
|
8
|
-
let replaced = original.replace(/sap\.ui\.getCore\(\)/g, `Core`);
|
9
|
-
|
10
|
-
if (original !== replaced) {
|
11
|
-
replaced = `import Core from 'sap/ui/core/Core';
|
12
|
-
${replaced}`;
|
13
|
-
return fs.writeFile(srcPath, replaced);
|
14
|
-
}
|
15
|
-
};
|
16
|
-
|
17
|
-
const generate = async () => {
|
18
|
-
const { globby } = await import("globby");
|
19
|
-
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
20
|
-
return Promise.all(fileNames.map(replaceGlobalCoreUsage).filter(x => !!x));
|
21
|
-
};
|
22
|
-
|
23
|
-
generate().then(() => {
|
24
|
-
console.log("Success: Replaced global core usage in:", basePath);
|
25
|
-
});
|