From d622472edc858a76bd2dda448fda2fd8b76bc1c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Thu, 23 Mar 2023 14:28:07 -0300 Subject: [PATCH] fix(module): dont resolve path is starts with # --- package-lock.json | 4 ++-- package.json | 2 +- src/Helpers/Module.ts | 2 +- tests/Stubs/controllers/app.controller.ts | 10 ++++++++++ tests/Unit/ModuleTest.ts | 6 ++++++ 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 tests/Stubs/controllers/app.controller.ts diff --git a/package-lock.json b/package-lock.json index beb926d..fdcf9ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/common", - "version": "3.4.5", + "version": "3.4.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@athenna/common", - "version": "3.4.5", + "version": "3.4.6", "license": "MIT", "dependencies": { "@fastify/formbody": "^7.4.0", diff --git a/package.json b/package.json index 76b4bcc..c5dbb99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/common", - "version": "3.4.5", + "version": "3.4.6", "description": "The Athenna common helpers to use in any Node.js ESM project.", "license": "MIT", "author": "João Lenon ", diff --git a/src/Helpers/Module.ts b/src/Helpers/Module.ts index 371d06f..5e8fbb3 100644 --- a/src/Helpers/Module.ts +++ b/src/Helpers/Module.ts @@ -182,7 +182,7 @@ export class Module { path = splited[0] - if (extname(path)) { + if (!path.startsWith('#') && extname(path)) { path = resolve(path) } diff --git a/tests/Stubs/controllers/app.controller.ts b/tests/Stubs/controllers/app.controller.ts new file mode 100644 index 0000000..d8deaf2 --- /dev/null +++ b/tests/Stubs/controllers/app.controller.ts @@ -0,0 +1,10 @@ +/** + * @athenna/common + * + * (c) João Lenon + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +export class AppController {} diff --git a/tests/Unit/ModuleTest.ts b/tests/Unit/ModuleTest.ts index 95c0d36..c9aa055 100644 --- a/tests/Unit/ModuleTest.ts +++ b/tests/Unit/ModuleTest.ts @@ -96,6 +96,12 @@ test.group('ModuleTest', () => { assert.equal(Exception.name, 'Exception') }) + test('should be able to resolve import alias with dots in the path by meta url and import it', async ({ assert }) => { + const AppController = await Module.resolve('#tests/Stubs/controllers/app.controller', import.meta.url) + + assert.equal(AppController.name, 'AppController') + }) + test('should be able to resolve partial paths by meta url and import it', async ({ assert }) => { const Exception = await Module.resolve('./src/Helpers/Exception.js', import.meta.url)