const fs = require ( 'fs' ) ; const path = require ( 'path' ) ; const lwcJestResolver = require ( '@lwc/jest-resolver' ) ; const lwcModuleResolver = require ( '@lwc/module-resolver' ) ; const { isValidModuleName , getInfoFromId } = require ( './webpack/module' ) ; import { lwcConfig } from '../config/lwcConfig' ; function getProjectInfo ( ) { const cwd = fs . realpathSync ( process . cwd ( ) ) ; const modulesDir = path . resolve ( cwd , lwcConfig . sourceDir , 'modules' ) ; const namespaces = fs . readdirSync ( modulesDir ) ; return { modulesDir , namespaces } ; } function isFile ( file ) { let result = false ; try { const stat = fs . statSync ( file ) ; result = stat . isFile ( ) || stat . isFIFO ( ) ; } catch ( e ) { if ( ! ( e && e . code === 'ENOENT' ) ) { throw e ; } result = false ; } return result ; } function resolveAsFile ( name , extensions ) { if ( isFile ( name ) ) { return name ; } for ( const extension of extensions ) { const file = name + extension ; if ( isFile ( file ) ) { return file ; } } return null ; } module . exports = function ( modulePath , options ) : string { if ( isValidModuleName ( modulePath ) ) { const { modulesDir } = getProjectInfo ( ) ; const { ns , name } = getInfoFromId ( modulePath ) ; try { const mod = lwcModuleResolver . resolveModule ( modulePath , process . cwd ( ) ) ; return mod . entry ; } catch ( e ) { } const file = resolveAsFile ( path . join ( modulesDir , ns , name , name ) , options . extensions ) ; if ( file ) { return fs . realpathSync ( file ) ; } } return lwcJestResolver ( ... arguments ) ; } ;