babel-plugin-transform-modules-ui5 7.4.0 → 7.4.2

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 CHANGED
@@ -3,6 +3,28 @@
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.4.2](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.4.1...v7.4.2) (2024-06-25)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * remove mandatory ESM file extensions from sap.ui.define imports ([#129](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/129)) ([571dfa1](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/571dfa192984c9838c573909546b42a85b71e5b6))
12
+
13
+
14
+
15
+
16
+
17
+ ## [7.4.1](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.4.0...v7.4.1) (2024-06-02)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * ensure to remove file ext .js only from module path ([#127](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/127)) ([c6afb92](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/c6afb92c2f758a245086baa6f77d3274bb4e5466))
23
+
24
+
25
+
26
+
27
+
6
28
  # [7.4.0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.3.1...v7.4.0) (2024-05-31)
7
29
 
8
30
 
@@ -37,13 +37,29 @@ const hasGlobalExportFlag = node => (0, _jsdoc.hasJsdocGlobalExportFlag)(node);
37
37
  const addImport = (imports, imp, filename, first) => {
38
38
  const existingImport = imports.find(i => i.src === imp.src);
39
39
  if (!existingImport) {
40
- // if a module ends with the file extension ".js" and it can be resolved to
40
+ // if a module path ends with the file extension ".js" and it can be resolved to
41
41
  // a local file having also the file extension ".js" and not ".js.js" then
42
42
  // we need to slice the file extension to avoid redundant file extension
43
43
  // (the require/define of UI5 always adds the file extension ".js" to the module name)
44
- if (imp.src.indexOf(".js") != -1) {
44
+ if (/^(?:(@[^/]+)\/)?([^/]+)\/(.*)\.js$/.test(imp.src)) {
45
45
  try {
46
- const modulePath = require.resolve(imp.src);
46
+ let modulePath;
47
+ let absModuleSrc = imp.src;
48
+ // if the module has a relative path, resolve it to an absolute path
49
+ // and verify if the file exists, if not, try to resolve it as a module
50
+ if (/^\.\.?\//.test(absModuleSrc)) {
51
+ absModuleSrc = (0, _path.resolve)((0, _path.dirname)(filename), absModuleSrc);
52
+ // handle the fallback of module names introduced with Node 20.0.0
53
+ [".js", ".jsx", ".ts", ".tsx"].some(ext => {
54
+ if ((0, _fs.existsSync)(absModuleSrc.replace(/\.js$/, ext))) {
55
+ modulePath = imp.src;
56
+ return true;
57
+ }
58
+ });
59
+ } else {
60
+ modulePath = require.resolve(absModuleSrc);
61
+ }
62
+ // detect removal of file extension and log a hint
47
63
  if (modulePath.endsWith(imp.src.split("/").pop())) {
48
64
  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
65
  imp.src = imp.src.slice(0, -3);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-transform-modules-ui5",
3
- "version": "7.4.0",
3
+ "version": "7.4.2",
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": "76dacf36cedd90d054dba13d8a92168e66b1730b"
97
+ "gitHead": "840510e9de26aa1e17946cf0f3a2b6395089e7e1"
98
98
  }