Skip to content

Commit

Permalink
fix(repl): import things to context instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Oct 16, 2023
1 parent d6fb999 commit b0a53c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down
6 changes: 3 additions & 3 deletions src/repl/ReplImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions tests/unit/repl/ReplImplTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand Down

0 comments on commit b0a53c5

Please sign in to comment.