index.d.ts 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. type PackageManagerName = "npm" | "yarn" | "pnpm" | "bun";
  2. type PackageManager = {
  3. name: PackageManagerName;
  4. command: string;
  5. version?: string;
  6. majorVersion?: string;
  7. lockFile?: string;
  8. files?: string[];
  9. };
  10. type OperationOptions = {
  11. cwd?: string;
  12. silent?: boolean;
  13. packageManager?: PackageManager | PackageManagerName;
  14. dev?: boolean;
  15. workspace?: boolean | string;
  16. };
  17. type DetectPackageManagerOptions = {
  18. /**
  19. * Whether to ignore the lock file
  20. *
  21. * @default false
  22. */
  23. ignoreLockFile?: boolean;
  24. /**
  25. * Whether to ignore the package.json file
  26. *
  27. * @default false
  28. */
  29. ignorePackageJSON?: boolean;
  30. /**
  31. * Whether to include parent directories
  32. *
  33. * @default false
  34. */
  35. includeParentDirs?: boolean;
  36. };
  37. declare const packageManagers: PackageManager[];
  38. declare function detectPackageManager(cwd: string, options?: DetectPackageManagerOptions): Promise<PackageManager | undefined>;
  39. /**
  40. * Installs project dependencies.
  41. *
  42. * @param options - Options to pass to the API call.
  43. * @param options.cwd - The directory to run the command in.
  44. * @param options.silent - Whether to run the command in silent mode.
  45. * @param options.packageManager - The package manager info to use (auto-detected).
  46. */
  47. declare function installDependencies(options?: Pick<OperationOptions, "cwd" | "silent" | "packageManager">): Promise<void>;
  48. /**
  49. * Adds dependency to the project.
  50. *
  51. * @param name - Name of the dependency to add.
  52. * @param options - Options to pass to the API call.
  53. * @param options.cwd - The directory to run the command in.
  54. * @param options.silent - Whether to run the command in silent mode.
  55. * @param options.packageManager - The package manager info to use (auto-detected).
  56. * @param options.dev - Whether to add the dependency as dev dependency.
  57. * @param options.workspace - The name of the workspace to use.
  58. */
  59. declare function addDependency(name: string | string[], options?: OperationOptions): Promise<void>;
  60. /**
  61. * Adds dev dependency to the project.
  62. *
  63. * @param name - Name of the dev dependency to add.
  64. * @param options - Options to pass to the API call.
  65. * @param options.cwd - The directory to run the command in.
  66. * @param options.silent - Whether to run the command in silent mode.
  67. * @param options.packageManager - The package manager info to use (auto-detected).
  68. * @param options.workspace - The name of the workspace to use.
  69. *
  70. */
  71. declare function addDevDependency(name: string | string[], options?: Omit<OperationOptions, "dev">): Promise<void>;
  72. /**
  73. * Removes dependency from the project.
  74. *
  75. * @param name - Name of the dependency to remove.
  76. * @param options - Options to pass to the API call.
  77. * @param options.cwd - The directory to run the command in.
  78. * @param options.silent - Whether to run the command in silent mode.
  79. * @param options.packageManager - The package manager info to use (auto-detected).
  80. * @param options.dev - Whether to remove dev dependency.
  81. * @param options.workspace - The name of the workspace to use.
  82. */
  83. declare function removeDependency(name: string, options?: OperationOptions): Promise<void>;
  84. /**
  85. * Ensures dependency is installed.
  86. *
  87. * @param name - Name of the dependency.
  88. * @param options - Options to pass to the API call.
  89. * @param options.cwd - The directory to run the command in.
  90. * @param options.dev - Whether to install as dev dependency (if not already installed).
  91. * @param options.workspace - The name of the workspace to install dependency in (if not already installed).
  92. */
  93. declare function ensureDependencyInstalled(name: string, options?: Pick<OperationOptions, "cwd" | "dev" | "workspace">): Promise<true | undefined>;
  94. export { type DetectPackageManagerOptions, type OperationOptions, type PackageManager, type PackageManagerName, addDependency, addDevDependency, detectPackageManager, ensureDependencyInstalled, installDependencies, packageManagers, removeDependency };