Skip to content

Commit

Permalink
feat: add support for ES6 module type
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed Jul 15, 2023
1 parent 39d10fb commit c083a2e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function createJSMiddlewareHandler(handlers, pathToRoot) {
}, {});

const imports = Object.keys(handlersInfo)
.map((handler) => `const ${handlersInfo[handler]} = require('${pathToRoot}/${handler}');`).join('\n');
.map((handler) => `const ${handlersInfo[handler]} = require('${pathToRoot}/${handler}.js');`).join('\n');

const promiseChain = handlers.map((handler) => {
if (handler.then && handler.catch) {
Expand Down
2 changes: 1 addition & 1 deletion src/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function createTSMiddlewareHandler(handlers, pathToRoot) {
}, {});

const imports = Object.keys(handlersInfo)
.map((handler) => `import * as ${handlersInfo[handler]} from '${pathToRoot}/${handler}';`).join('\n');
.map((handler) => `import * as ${handlersInfo[handler]} from '${pathToRoot}/${handler}.js';`).join('\n');

const promiseChain = handlers.map((handler) => {
if (handler.then && handler.catch) {
Expand Down
4 changes: 2 additions & 2 deletions test/utils/generatedFunctionTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class GeneratedFunctionTester {
// eslint-disable-next-line no-new-func
return new Function('event', 'context', 'dependencies', `
const require = (dependencyName) => {
const dependency = dependencies[dependencyName.replace('../', '')];
const dependency = dependencies[dependencyName.replace('../', '').replace(/^(.+).js$/, '$1')];
if (!dependency) {
throw new Error(\`Unknow dependency (\${dep})\`);
throw new Error(\`Unknow dependency (\${dependencyName})\`);
}
return dependency;
Expand Down

0 comments on commit c083a2e

Please sign in to comment.