@appium/support
Version:
Support libs used across Appium packages
105 lines • 4.18 kB
TypeScript
import type { PackageJson } from 'type-fest';
import type { StringRecord } from '@appium/types';
import type { TeenProcessExecOptions } from 'teen_process';
/**
* Relative path to directory containing any Appium internal files
* XXX: this is duplicated in `appium/lib/constants.js`.
*/
export declare const CACHE_DIR_RELATIVE_PATH: string;
/**
* Relative path to lockfile used when installing an extension via `appium`
*/
export declare const INSTALL_LOCKFILE_RELATIVE_PATH: string;
/** Options for {@link NPM.exec} */
export interface ExecOpts {
/** Current working directory */
cwd: string;
/** If true, supply `--json` flag to npm and resolve w/ parsed JSON */
json?: boolean;
/** Path to lockfile to use */
lockFile?: string;
}
/** Options for {@link NPM.installPackage} */
export interface InstallPackageOpts {
/** Name of the package to install */
pkgName: string;
/** Whether to install from a local path or from npm */
installType?: 'local' | string;
}
/** Result of {@link NPM.installPackage} */
export interface NpmInstallReceipt {
/** Path to installed package */
installPath: string;
/** Package data */
pkg: PackageJson;
}
export interface NpmExecResult {
stdout: string;
stderr: string;
code: number | null;
json?: unknown;
}
/**
* XXX: This should probably be a singleton, but it isn't. Maybe this module should just export functions?
*/
export declare class NPM {
/**
* Execute `npm` with given args.
*
* If the process exits with a nonzero code, the contents of `STDOUT` and `STDERR` will be in the
* `message` of any rejected error.
*/
exec(cmd: string, args: string[], opts: ExecOpts, execOpts?: Omit<TeenProcessExecOptions, 'cwd'>): Promise<NpmExecResult>;
/**
* Gets the latest published version of a package from npm registry.
*
* @param cwd - Current working directory for npm command
* @param pkg - Package name to query
* @returns Latest version string, or `null` if package not found (e.g. 404)
*/
getLatestVersion(cwd: string, pkg: string): Promise<string | null>;
/**
* Gets the latest version of a package that is a safe upgrade from the current version
* (same major, no prereleases). Fetches versions from npm and delegates to
* {@link NPM.getLatestSafeUpgradeFromVersions}.
*
* @param cwd - Current working directory for npm command
* @param pkg - Package name to query
* @param curVersion - Current installed version
* @returns Latest safe upgrade version string, or `null` if none or package not found
*/
getLatestSafeUpgradeVersion(cwd: string, pkg: string, curVersion: string): Promise<string | null>;
/**
* Runs `npm ls`, optionally for a particular package.
*/
list(cwd: string, pkg?: string): Promise<unknown>;
/**
* Given a current version and a list of all versions for a package, return the version which is
* the highest safely-upgradable version (meaning not crossing any major revision boundaries, and
* not including any alpha/beta/rc versions)
*/
getLatestSafeUpgradeFromVersions(curVersion: string, allVersions: string[]): string | null;
/**
* Installs a package w/ `npm`
*/
installPackage(cwd: string, installStr: string, opts: InstallPackageOpts): Promise<NpmInstallReceipt>;
/**
* Uninstalls a package with `npm uninstall`.
*
* @param cwd - Current working directory (project root)
* @param pkg - Package name to uninstall
*/
uninstallPackage(cwd: string, pkg: string): Promise<void>;
/**
* Fetches package metadata from the npm registry via `npm info`.
*
* @param pkg - Npm package spec to query
* @param entries - Field names to be included into the resulting output. By default all fields are included.
* @returns Package metadata as a record of string values
*/
getPackageInfo(pkg: string, entries?: string[]): Promise<StringRecord>;
/** Returns path to "install" lockfile */
private _getInstallLockfilePath;
}
export declare const npm: NPM;
//# sourceMappingURL=npm.d.ts.map