import { lstatSync , accessSync , constants } from 'fs' ; import { createHash } from 'crypto' ; export function isDir ( filename ) { try { const stat = lstatSync ( filename ) ; return stat . isDirectory ( ) ; } catch ( e ) { return false ; } } export function isWritable ( filename ) { try { accessSync ( filename , constants . W_OK ) ; return true ; } catch ( e ) { return false ; } } export function md5 ( content , len = 8 ) { return createHash ( 'md5' ) . update ( content ) . digest ( 'hex' ) . substr ( 0 , len ) ; } export function detectESMSyntax ( code ) { return code . match ( /^\s*import .* from|\s*export .*/m ) ; } export function detectLegacySyntax ( code ) { return code . match ( /\?\.|\?\?/ ) ; } export function isObject ( val ) { return val !== null && typeof val === 'object' ; } export function interopDefault ( sourceModule ) { if ( ! isObject ( sourceModule ) || ! ( 'default' in sourceModule ) ) { return sourceModule ; } const newModule = sourceModule . default ; for ( const key in sourceModule ) { if ( key === 'default' ) { try { if ( ! ( key in newModule ) ) { Object . defineProperty ( newModule , key , { enumerable : false , configurable : false , get ( ) { return newModule ; } } ) ; } } catch ( _err ) { } } else { try { if ( ! ( key in newModule ) ) { Object . defineProperty ( newModule , key , { enumerable : true , configurable : true , get ( ) { return sourceModule [ key ] ; } } ) ; } } catch ( _err ) { } } } return newModule ; }