diff --git a/package-lock.json b/package-lock.json index 9013b77..05b0e55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/core", - "version": "4.10.2", + "version": "4.10.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/core", - "version": "4.10.2", + "version": "4.10.3", "license": "MIT", "dependencies": { "pretty-repl": "^3.1.2", diff --git a/package.json b/package.json index 89d2a5d..6ec210c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/core", - "version": "4.10.2", + "version": "4.10.3", "description": "The plug and play Node.js framework.", "license": "MIT", "author": "João Lenon ", diff --git a/src/repl/ReplImpl.ts b/src/repl/ReplImpl.ts index 4eb4484..245b1fc 100644 --- a/src/repl/ReplImpl.ts +++ b/src/repl/ReplImpl.ts @@ -116,15 +116,15 @@ export class ReplImpl { /** * Import a module in the repl session. */ - public import(key: string, path: string): ReplImpl { - return this.write(`const ${key} = await import('${path}')`) + public async import(key: string, path: string) { + this.setInContext(key, await import(path)) } /** * Import a module and register all it properties * in the repl context. */ - public async importInContext(path: string) { + public async importAll(path: string) { let module = await Module.resolve(path, Config.get('rc.parentURL'), { import: true, getModule: false diff --git a/tests/unit/repl/ReplImplTest.ts b/tests/unit/repl/ReplImplTest.ts index 0fe14c1..f836177 100644 --- a/tests/unit/repl/ReplImplTest.ts +++ b/tests/unit/repl/ReplImplTest.ts @@ -151,12 +151,14 @@ export default class ReplImplTest { const repl = new ReplImpl() repl.session = { - write: Mock.fake() + context: {} } as any - repl.import('common', '@athenna/common') + await repl.import('common', '@athenna/common') + + const common = await import('@athenna/common') - assert.calledWithMatch(repl.session.write, "const common = await import('@athenna/common')") + assert.deepEqual(repl.session.context.common.Clean, common.Clean) } @Test() @@ -170,7 +172,7 @@ export default class ReplImplTest { context: {} } as any - await repl.importInContext('@athenna/common') + await repl.importAll('@athenna/common') const common = await import('@athenna/common') @@ -189,7 +191,7 @@ export default class ReplImplTest { context: {} } as any - await repl.importInContext('#tests/fixtures/modules/default-class') + await repl.importAll('#tests/fixtures/modules/default-class') const module = await import('#tests/fixtures/modules/default-class') @@ -207,7 +209,7 @@ export default class ReplImplTest { context: {} } as any - await repl.importInContext('#tests/fixtures/modules/default-fn') + await repl.importAll('#tests/fixtures/modules/default-fn') const module = await import('#tests/fixtures/modules/default-fn') @@ -225,7 +227,7 @@ export default class ReplImplTest { context: {} } as any - await repl.importInContext('#tests/fixtures/modules/default-arrow-fn') + await repl.importAll('#tests/fixtures/modules/default-arrow-fn') const module = await import('#tests/fixtures/modules/default-arrow-fn') @@ -243,7 +245,7 @@ export default class ReplImplTest { context: {} } as any - await repl.importInContext('#tests/fixtures/modules/default-const') + await repl.importAll('#tests/fixtures/modules/default-const') const module = await import('#tests/fixtures/modules/default-const') @@ -261,7 +263,7 @@ export default class ReplImplTest { context: {} } as any - await repl.importInContext('#tests/fixtures/modules/default-object') + await repl.importAll('#tests/fixtures/modules/default-object') const module = await import('#tests/fixtures/modules/default-object')