babel-plugin-transform-modules-ui5 7.3.0 → 7.3.1
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 +12 -0
- package/dist/modules/visitor.js +65 -22
- package/dist/utils/templates.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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
|
+
## [7.3.1](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.3.0...v7.3.1) (2024-05-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* remove file extensions from imports to avoid redundant extensions ([#125](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/125)) ([e86d6f6](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/e86d6f675451b6eaaaf63f9433200cd7406d0245))
|
|
12
|
+
* support index modules for dependencies ([#123](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/123)) ([f510380](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/f510380f7c201d9aba3e735badea21546f81f03d))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
6
18
|
# [7.3.0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.2.6...v7.3.0) (2024-01-18)
|
|
7
19
|
|
|
8
20
|
|
package/dist/modules/visitor.js
CHANGED
|
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ModuleTransformVisitor = void 0;
|
|
7
|
+
var _path = require("path");
|
|
8
|
+
var _fs = require("fs");
|
|
7
9
|
var _core = require("@babel/core");
|
|
8
10
|
var th = _interopRequireWildcard(require("../utils/templates"));
|
|
9
11
|
var ast = _interopRequireWildcard(require("../utils/ast"));
|
|
10
12
|
var _jsdoc = require("../classes/helpers/jsdoc");
|
|
11
|
-
const _excluded = ["opts"];
|
|
13
|
+
const _excluded = ["filename", "opts"];
|
|
12
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -18,25 +20,58 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
|
18
20
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
19
21
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
20
22
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
23
|
+
const resolveSource = (src, filename) => {
|
|
24
|
+
src = src.replace(/\\/g, "/");
|
|
25
|
+
const dir = (0, _path.dirname)(filename);
|
|
26
|
+
const absoluteSrc = (0, _path.join)(dir, src);
|
|
27
|
+
if ((0, _fs.existsSync)(absoluteSrc) && (0, _fs.statSync)(absoluteSrc).isDirectory) {
|
|
28
|
+
if ((0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.js")) || (0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.jsx")) || (0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.ts")) || (0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.tsx")) || (0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.mjs")) || (0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.cjs"))) {
|
|
29
|
+
src = `${src}/index`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return src;
|
|
33
|
+
};
|
|
21
34
|
const cleanImportSource = src => src.replace(/(\/)|(-)|(@)/g, "_").replace(/\./g, "");
|
|
22
35
|
const tempModuleName = name => `__${name}`;
|
|
23
36
|
const hasGlobalExportFlag = node => (0, _jsdoc.hasJsdocGlobalExportFlag)(node);
|
|
24
|
-
const
|
|
25
|
-
const existingImport = imports.find(
|
|
37
|
+
const addImport = (imports, imp, filename, first) => {
|
|
38
|
+
const existingImport = imports.find(i => i.src === imp.src);
|
|
26
39
|
if (!existingImport) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
// if a module ends with the file extension ".js" and it can be resolved to
|
|
41
|
+
// a local file having also the file extension ".js" and not ".js.js" then
|
|
42
|
+
// we need to slice the file extension to avoid redundant file extension
|
|
43
|
+
// (the require/define of UI5 always adds the file extension ".js" to the module name)
|
|
44
|
+
if (imp.src.indexOf(".js") != -1) {
|
|
45
|
+
try {
|
|
46
|
+
const modulePath = require.resolve(imp.src);
|
|
47
|
+
if (modulePath.endsWith(imp.src.split("/").pop())) {
|
|
48
|
+
console.log(`\x1b[33mHint:\x1b[0m Removed file extension for dependency "\x1b[34m${imp.src}\x1b[0m" found in \x1b[90m${filename}\x1b[0m`);
|
|
49
|
+
imp.src = imp.src.slice(0, -3);
|
|
50
|
+
}
|
|
51
|
+
} catch (ex) {
|
|
52
|
+
// ignore the error, do not slice file extension as the module
|
|
53
|
+
// can't be resolved with the given file extension, e.g.
|
|
54
|
+
// myns/module.js must be provided as myns/module
|
|
55
|
+
// myns/module.js.js must be provided as myns/module.js
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
imports[first ? "unshift" : "push"](imp);
|
|
32
59
|
}
|
|
33
60
|
};
|
|
61
|
+
const addModuleImport = (imports, name, filename) => {
|
|
62
|
+
addImport(imports, {
|
|
63
|
+
src: name,
|
|
64
|
+
name: name,
|
|
65
|
+
tmpName: name
|
|
66
|
+
}, filename, true);
|
|
67
|
+
};
|
|
34
68
|
const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
35
69
|
/*!
|
|
36
70
|
* Removes the ES6 import and adds the details to the import array in our state.
|
|
37
71
|
*/
|
|
38
72
|
ImportDeclaration(path, _ref) {
|
|
39
73
|
let {
|
|
74
|
+
filename,
|
|
40
75
|
opts = {}
|
|
41
76
|
} = _ref,
|
|
42
77
|
state = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -49,7 +84,7 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
49
84
|
specifiers,
|
|
50
85
|
source
|
|
51
86
|
} = node;
|
|
52
|
-
const src = source.value
|
|
87
|
+
const src = resolveSource(source.value, filename);
|
|
53
88
|
|
|
54
89
|
// When 'libs' are used, only 'libs' will be converted to UI5 imports.
|
|
55
90
|
const {
|
|
@@ -159,7 +194,7 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
159
194
|
}
|
|
160
195
|
imp.deconstructors = imp.deconstructors.concat(deconstructors);
|
|
161
196
|
if (!existingImport) {
|
|
162
|
-
this.imports
|
|
197
|
+
addImport(this.imports, imp, filename);
|
|
163
198
|
}
|
|
164
199
|
},
|
|
165
200
|
/**
|
|
@@ -167,7 +202,9 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
167
202
|
* The reason we don't export in place is to handle the situation
|
|
168
203
|
* where a let or var can be defined, and the latest one should be exported.
|
|
169
204
|
*/
|
|
170
|
-
ExportNamedDeclaration(path
|
|
205
|
+
ExportNamedDeclaration(path, {
|
|
206
|
+
filename
|
|
207
|
+
}) {
|
|
171
208
|
const {
|
|
172
209
|
node
|
|
173
210
|
} = path;
|
|
@@ -179,14 +216,14 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
179
216
|
let fromSource = "";
|
|
180
217
|
if (source) {
|
|
181
218
|
// e.g. export { one, two } from 'x'
|
|
182
|
-
const src = source.value;
|
|
219
|
+
const src = resolveSource(source.value, filename);
|
|
183
220
|
const name = cleanImportSource(src);
|
|
184
221
|
const tmpName = tempModuleName(name);
|
|
185
|
-
this.imports
|
|
222
|
+
addImport(this.imports, {
|
|
186
223
|
src,
|
|
187
224
|
name,
|
|
188
225
|
tmpName
|
|
189
|
-
});
|
|
226
|
+
}, filename);
|
|
190
227
|
fromSource = tmpName + ".";
|
|
191
228
|
}
|
|
192
229
|
if (specifiers && specifiers.length) {
|
|
@@ -229,7 +266,9 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
229
266
|
return;
|
|
230
267
|
}
|
|
231
268
|
},
|
|
232
|
-
ExportDefaultDeclaration(path
|
|
269
|
+
ExportDefaultDeclaration(path, {
|
|
270
|
+
filename
|
|
271
|
+
}) {
|
|
233
272
|
const {
|
|
234
273
|
node
|
|
235
274
|
} = path;
|
|
@@ -267,15 +306,17 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
267
306
|
this.defaultExport = th.exportsIdentifier;
|
|
268
307
|
}
|
|
269
308
|
},
|
|
270
|
-
ExportAllDeclaration(path
|
|
271
|
-
|
|
309
|
+
ExportAllDeclaration(path, {
|
|
310
|
+
filename
|
|
311
|
+
}) {
|
|
312
|
+
const src = resolveSource(path.node.source.value, filename);
|
|
272
313
|
const name = cleanImportSource(src);
|
|
273
314
|
const tmpName = tempModuleName(name);
|
|
274
|
-
this.imports
|
|
315
|
+
addImport(this.imports, {
|
|
275
316
|
src,
|
|
276
317
|
name,
|
|
277
318
|
tmpName
|
|
278
|
-
});
|
|
319
|
+
}, filename);
|
|
279
320
|
this.exportAllHelper = true;
|
|
280
321
|
this.namedExports.push({
|
|
281
322
|
all: true,
|
|
@@ -300,7 +341,9 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
300
341
|
}));
|
|
301
342
|
}
|
|
302
343
|
},
|
|
303
|
-
MemberExpression(path
|
|
344
|
+
MemberExpression(path, {
|
|
345
|
+
filename
|
|
346
|
+
}) {
|
|
304
347
|
var _node$object;
|
|
305
348
|
const {
|
|
306
349
|
node
|
|
@@ -310,12 +353,12 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
310
353
|
// replace all "import.meta.url" with "module.url"
|
|
311
354
|
if ((node === null || node === void 0 || (_node$property = node.property) === null || _node$property === void 0 ? void 0 : _node$property.name) === "url") {
|
|
312
355
|
path.replaceWith(_objectSpread(_objectSpread({}, node), (0, _core.template)`module.url`()));
|
|
313
|
-
addModuleImport(this.imports, "module");
|
|
356
|
+
addModuleImport(this.imports, "module", filename);
|
|
314
357
|
}
|
|
315
358
|
// replace all "import.meta.resolve(...)" with "require.toUrl(...)"
|
|
316
359
|
else if ((node === null || node === void 0 || (_node$property2 = node.property) === null || _node$property2 === void 0 ? void 0 : _node$property2.name) === "resolve") {
|
|
317
360
|
path.replaceWith(_objectSpread(_objectSpread({}, node), (0, _core.template)`require.toUrl`()));
|
|
318
|
-
addModuleImport(this.imports, "require");
|
|
361
|
+
addModuleImport(this.imports, "require", filename);
|
|
319
362
|
}
|
|
320
363
|
}
|
|
321
364
|
}
|
package/dist/utils/templates.js
CHANGED
|
@@ -49,7 +49,7 @@ function buildNamedExport(obj) {
|
|
|
49
49
|
}
|
|
50
50
|
const buildAllExportHelper = exports.buildAllExportHelper = (0, _core.template)(`
|
|
51
51
|
function extendExports(exports, obj) {
|
|
52
|
-
Object.keys(obj).forEach(function (key) {
|
|
52
|
+
obj && Object.keys(obj).forEach(function (key) {
|
|
53
53
|
if (key === "default" || key === "__esModule") return;
|
|
54
54
|
Object.defineProperty(exports, key, {
|
|
55
55
|
enumerable: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-transform-modules-ui5",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.1",
|
|
4
4
|
"description": "An unofficial babel plugin for SAP UI5.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"prettier": "^3.1.0",
|
|
95
95
|
"rimraf": "^5.0.5"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "aaa2b6503de89f673191f11f84879996b5b5936a"
|
|
98
98
|
}
|