Files
reverse-engineering-anything/src/process/ProcessCommandIdentity.ts
T

25 lines
812 B
TypeScript

import { basename } from "node:path";
/** Match process-table command text while handling macOS executable-name normalization. */
export const matchesOwnedProcessCommand = (
actual: string,
expected: string,
platform: NodeJS.Platform = process.platform,
): boolean => {
const actualCommand = actual.trim();
const expectedCommand = expected.trim();
if (
actualCommand === expectedCommand ||
actualCommand.startsWith(`${expectedCommand} `)
)
return true;
if (platform !== "darwin") return false;
const actualExecutable = actualCommand.split(/\s+/u, 1)[0];
const expectedExecutable = expectedCommand.split(/\s+/u, 1)[0];
return (
actualExecutable !== undefined &&
expectedExecutable !== undefined &&
basename(actualExecutable) === basename(expectedExecutable)
);
};