mirror of
https://github.com/morluto/rea.git
synced 2026-10-22 13:52:32 -05:00
29 lines
1014 B
TypeScript
29 lines
1014 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];
|
|
const normalizedActualExecutable =
|
|
actualExecutable?.startsWith("(") === true && actualExecutable.endsWith(")")
|
|
? actualExecutable.slice(1, -1)
|
|
: actualExecutable;
|
|
return (
|
|
normalizedActualExecutable !== undefined &&
|
|
expectedExecutable !== undefined &&
|
|
basename(normalizedActualExecutable) === basename(expectedExecutable)
|
|
);
|
|
};
|