import path from 'path' ; import { normalizePath } from 'vite' ; import fs from 'fs' ; import { createRequire } from 'module' ; export function resolveNodeModules ( libName , ... dir ) { const esRequire = createRequire ( import . meta . url ) ; let modulePath = '' ; try { modulePath = normalizePath ( esRequire . resolve ( libName ) ) ; } catch ( error ) { modulePath = normalizePath ( require . resolve ( libName ) ) ; } const lastIndex = modulePath . lastIndexOf ( libName ) ; return normalizePath ( path . resolve ( modulePath . substring ( 0 , lastIndex ) , ... dir ) ) ; } export function resolvePnp ( module ) { try { return normalizePath ( require . resolve ( module ) ) ; } catch ( error ) { return '' ; } } export const isPnp = ! ! process . versions . pnp ; export function isRegExp ( value ) { return Object . prototype . toString . call ( value ) === '[object RegExp]' ; } export function fileExists ( f ) { try { fs . accessSync ( f , fs . constants . W_OK ) ; return true ; } catch ( error ) { return false ; } }