@rechunk/utils
Version:
Utility functions and helpers for ReChunk packages and implementations
82 lines (80 loc) • 3.25 kB
TypeScript
/**
* Resolves the real native path for a given file path.
*
* This is particularly useful for case-insensitive file systems,
* where different casing can lead to discrepancies in file paths.
* For example, accessing the file as `C:\Code\Project` vs. `c:\code\projects`
* can cause issues when installing packages with the `-w` flag if the root directory
* is not consistently cased.
*
* @param {string} filePath - The path of the file to resolve
* @returns {string} The resolved real path, or the original path if resolution fails
*/
declare function getRealPath(filePath: string): string;
/**
* Recursively searches for the closest JSON file, starting from a given directory.
*
* @param {string} filename - The name of the JSON file to search for
* @param {string} start - The directory to start searching from, defaults to current working directory
* @param {number} level - The current depth of the recursive search, used to limit recursion
* @returns {any} The parsed JSON content, or an empty object if file not found after 10 levels
*/
declare function findClosestJSON(filename: string, start?: string, level?: number): any;
/**
* Finds the workspace directory by locating the workspace manifest file.
*
* Searches for workspace-related files using the `find-up` package
* in the current directory and its parents. Looks for:
* - package.json with workspaces field (npm/yarn/bun)
* - yarn.lock, pnpm-lock.yaml, or bun.lockb files
*
* @param {string} cwd - The current working directory from which to start searching
* @returns {string | undefined} The path to the workspace directory if found, or undefined if not found
*/
declare function findWorkspaceDir(cwd: string): string | undefined;
/**
* Options for process listing operations
*/
interface ProcessOptions {
/** Whether to show all processes. Defaults to true */
all?: boolean;
}
/**
* Information about a running process
*/
interface ProcessInfo {
/** Process ID */
pid: number;
/** Parent Process ID */
ppid: number;
/** User ID */
uid: number;
/** CPU usage percentage */
cpu: number;
/** Memory usage percentage */
memory: number;
/** Process name */
name: string;
/** Full command line */
cmd: string;
}
/**
* Retrieves information about running processes on a non-Windows system using the `ps` command.
*
* @param {ProcessOptions} options - Optional settings for the command
* @returns {ProcessInfo[]} Array of objects containing process information
* @throws {Error} If parsing the output from `ps` fails
*/
declare function nonWindowsCall(options?: ProcessOptions): ProcessInfo[];
/**
* Checks if the Rechunk development server is currently running.
*
* Inspects the system's running processes, looking for processes
* that match the `rechunk dev-server` command. Checks for matches that either:
* - Start with `node ./node_modules`
* - Start with `node <workspaceDir>`
*
* @returns {boolean} `true` if the Rechunk development server is running, otherwise `false`
*/
declare function isRechunkDevServerRunning(): boolean;
export { type ProcessInfo, type ProcessOptions, findClosestJSON, findWorkspaceDir, getRealPath, isRechunkDevServerRunning, nonWindowsCall };