| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | import { dirname, join } from 'path'import { existsSync, promises as fs, readFileSync } from 'fs'import { createRequire } from 'module'export { loadPackageJSON, isPackageListed } from './dist/shared.mjs'const _require = createRequire(import.meta.url)export function resolveModule(name, options) {  try {    return _require.resolve(name, options)  }  catch (e) {    return undefined  }}export function importModule(path) {  return import(path).then((i) => {    if (i && i.default && i.default.__esModule)      return i.default    return i  })}export function isPackageExists(name, options) {  return !!resolvePackage(name, options)}function getPackageJsonPath(name, options) {  const entry = resolvePackage(name, options)  if (!entry)    return  return searchPackageJSON(entry)}export async function getPackageInfo(name, options) {  const packageJsonPath = getPackageJsonPath(name, options)  if (!packageJsonPath)    return  const pkg = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'))  return {    name,    version: pkg.version,    rootPath: dirname(packageJsonPath),    packageJsonPath,    packageJson: pkg,  }}export function getPackageInfoSync(name, options) {  const packageJsonPath = getPackageJsonPath(name, options)  if (!packageJsonPath)    return  const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf8'))  return {    name,    version: pkg.version,    rootPath: dirname(packageJsonPath),    packageJsonPath,    packageJson: pkg,  }}function resolvePackage(name, options = {}) {  try {    return _require.resolve(`${name}/package.json`, options)  }  catch {  }  try {    return _require.resolve(name, options)  }  catch (e) {    if (e.code !== 'MODULE_NOT_FOUND')      console.error(e)    return false  }}function searchPackageJSON(dir) {  let packageJsonPath  while (true) {    if (!dir)      return    const newDir = dirname(dir)    if (newDir === dir)      return    dir = newDir    packageJsonPath = join(dir, 'package.json')    if (existsSync(packageJsonPath))      break  }  return packageJsonPath}
 |