Skip to content

Commit

Permalink
fix: ensure to remove file ext .js only from module path (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
petermuessig authored Jun 2, 2024
1 parent 76dacf3 commit c6afb92
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/plugin/__test__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ exports[`imports import-multiple.js 1`] = `
`;
exports[`imports import-remove-fileext.js 1`] = `
"sap.ui.define(["array-flatten/dist/index"], function (__array_flatten_dist_indexjs) {
"sap.ui.define(["@dummy/chart.js", "chart.js", "array-flatten/dist/index"], function (___dummy_chartjs, __chartjs, __array_flatten_dist_indexjs) {
"use strict";
});"
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import "@dummy/chart.js";
import "chart.js";
import "array-flatten/dist/index.js";
4 changes: 2 additions & 2 deletions packages/plugin/src/modules/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const hasGlobalExportFlag = (node) => hasJsdocGlobalExportFlag(node);
const addImport = (imports, imp, filename, first) => {
const existingImport = imports.find((i) => i.src === imp.src);
if (!existingImport) {
// if a module ends with the file extension ".js" and it can be resolved to
// if a module path ends with the file extension ".js" and it can be resolved to
// a local file having also the file extension ".js" and not ".js.js" then
// we need to slice the file extension to avoid redundant file extension
// (the require/define of UI5 always adds the file extension ".js" to the module name)
if (imp.src.indexOf(".js") != -1) {
if (/^(?:(@[^/]+)\/)?([^/]+)\/(.*)\.js$/.test(imp.src)) {
try {
const modulePath = require.resolve(imp.src);
if (modulePath.endsWith(imp.src.split("/").pop())) {
Expand Down

0 comments on commit c6afb92

Please sign in to comment.