All files / src/helpers safeImports.ts

25% Statements 5/20
100% Branches 0/0
0% Functions 0/1
25% Lines 5/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 201x 1x 1x 1x 1x                              
import { C } from 'topkat-utils'
import Path from 'path'
import { getProjectPaths } from './getProjectPaths'
 
export async function safeImport(path: string) {

  const verbose = process.env.SAFE_IMPORT_VERBOSE === '1'

  const { mainConfig } = await getProjectPaths()
  const pathRelative = Path.relative(mainConfig.folderPath, path)

  if (verbose) C.log('Importing ' + pathRelative)

  const resp = await import(path)

  if (verbose) C.clearLastLines(1)
  if (verbose) C.success('Imported ' + pathRelative)

  return resp
}