index.d.cts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { PackageJson } from 'pkg-types';
  2. interface PackageInfo {
  3. name: string;
  4. rootPath: string;
  5. packageJsonPath: string;
  6. version: string;
  7. packageJson: PackageJson;
  8. }
  9. interface PackageResolvingOptions {
  10. paths?: string[];
  11. /**
  12. * @default 'auto'
  13. * Resolve path as posix or win32
  14. */
  15. platform?: 'posix' | 'win32' | 'auto';
  16. }
  17. declare function resolveModule(name: string, options?: PackageResolvingOptions): string | undefined;
  18. declare function importModule<T = any>(path: string): Promise<T>;
  19. declare function isPackageExists(name: string, options?: PackageResolvingOptions): boolean;
  20. declare function getPackageInfo(name: string, options?: PackageResolvingOptions): Promise<{
  21. name: string;
  22. version: string | undefined;
  23. rootPath: string;
  24. packageJsonPath: string;
  25. packageJson: PackageJson;
  26. } | undefined>;
  27. declare function getPackageInfoSync(name: string, options?: PackageResolvingOptions): {
  28. name: string;
  29. version: string | undefined;
  30. rootPath: string;
  31. packageJsonPath: string;
  32. packageJson: PackageJson;
  33. } | undefined;
  34. declare function loadPackageJSON(cwd?: string): Promise<PackageJson | null>;
  35. declare function isPackageListed(name: string, cwd?: string): Promise<boolean>;
  36. export { type PackageInfo, type PackageResolvingOptions, getPackageInfo, getPackageInfoSync, importModule, isPackageExists, isPackageListed, loadPackageJSON, resolveModule };