diff --git a/packages/plugin/__test__/__snapshots__/test.js.snap b/packages/plugin/__test__/__snapshots__/test.js.snap index a7b31eb..2c65d10 100644 --- a/packages/plugin/__test__/__snapshots__/test.js.snap +++ b/packages/plugin/__test__/__snapshots__/test.js.snap @@ -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"; });" `; diff --git a/packages/plugin/__test__/fixtures/imports/import-remove-fileext.js b/packages/plugin/__test__/fixtures/imports/import-remove-fileext.js index 4df6a88..9391e2f 100644 --- a/packages/plugin/__test__/fixtures/imports/import-remove-fileext.js +++ b/packages/plugin/__test__/fixtures/imports/import-remove-fileext.js @@ -1 +1,3 @@ +import "@dummy/chart.js"; +import "chart.js"; import "array-flatten/dist/index.js"; diff --git a/packages/plugin/src/modules/visitor.js b/packages/plugin/src/modules/visitor.js index c7223cd..35a6fc9 100644 --- a/packages/plugin/src/modules/visitor.js +++ b/packages/plugin/src/modules/visitor.js @@ -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())) {