Skip to content

Commit

Permalink
fix: use ts-node instead node-eval with ts compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed May 4, 2020
1 parent 450d662 commit 93d66db
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/core/import-module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { transpileModule } from 'typescript'
import { readFile } from 'fs-extra'
import neval from 'node-eval'
import { register } from 'ts-node'

register({ transpileOnly: true })

export function esModuleInterop<T>(box?: T): T {
if (box === undefined) {
Expand All @@ -17,9 +17,7 @@ export function esModuleInterop<T>(box?: T): T {
*/
export async function importModule<T>(path: string): Promise<T> {
// TODO: Source possibly empty or have invalid format.
const source = await readFile(path, 'utf-8')
// TODO: Add diagnostic.
const transpileResult = transpileModule(source, {})
const result = neval(transpileResult.outputText, path)
const result = await import(path)
return esModuleInterop(result)
}

0 comments on commit 93d66db

Please sign in to comment.