1import { SpawnOptions, SpawnPromise, SpawnResult } from '@expo/spawn-async';
2
3import { PendingSpawnPromise } from './utils/spawn';
4
5export interface PackageManagerOptions extends SpawnOptions {
6  /**
7   * If the package manager should run in silent mode.
8   * Note, this will hide possible error output from executed commands.
9   * When running in silent mode, make sure you handle them properly.
10   */
11  silent?: boolean;
12
13  /**
14   * The logging method used to communicate the command which is executed.
15   * Without `silent`, this defaults to `console.log`.
16   * When `silent` is set to `true`, this defaults to a no-op.
17   */
18  log?: (...args: any[]) => void;
19}
20
21export interface PackageManager {
22  /** The options for this package manager */
23  readonly options: PackageManagerOptions;
24
25  /** Run any command using the package manager */
26  runAsync(command: string[]): SpawnPromise<SpawnResult>;
27
28  /** Get the version of the used package manager */
29  versionAsync(): Promise<string>;
30  /** Get a single configuration property from the package manager */
31  getConfigAsync(key: string): Promise<string>;
32  /** Remove the lock file within the project, if any */
33  removeLockfileAsync(): Promise<void>;
34  /** Get the workspace root package manager, if this project is within a workspace/monorepo */
35  workspaceRoot(): PackageManager | null;
36
37  /** Install all current dependencies using the package manager */
38  installAsync():
39    | Promise<SpawnResult>
40    | SpawnPromise<SpawnResult>
41    | PendingSpawnPromise<SpawnResult>;
42  /** Uninstall all current dependencies by removing the folder containing the packages */
43  uninstallAsync(): Promise<void>;
44
45  /** Add a normal dependency to the project */
46  addAsync(namesOrFlags: string[]): SpawnPromise<SpawnResult> | PendingSpawnPromise<SpawnResult>;
47  /** Add a development dependency to the project */
48  addDevAsync(namesOrFlags: string[]): SpawnPromise<SpawnResult> | PendingSpawnPromise<SpawnResult>;
49  /** Add a global dependency to the environment */
50  addGlobalAsync(
51    namesOrFlags: string[]
52  ): SpawnPromise<SpawnResult> | PendingSpawnPromise<SpawnResult>;
53
54  /** Remove a normal dependency from the project */
55  removeAsync(namesOrFlags: string[]): SpawnPromise<SpawnResult> | PendingSpawnPromise<SpawnResult>;
56  /** Remove a development dependency from the project */
57  removeDevAsync(
58    namesOrFlags: string[]
59  ): SpawnPromise<SpawnResult> | PendingSpawnPromise<SpawnResult>;
60  /** Remove a global dependency from the environments */
61  removeGlobalAsync(
62    namesOrFlags: string[]
63  ): SpawnPromise<SpawnResult> | PendingSpawnPromise<SpawnResult>;
64}
65