File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -218,14 +218,16 @@ export function isVirtualExecutablePath(path: string): boolean {
218218/**
219219 * Extracts ProgramArguments[0] from rendered launchd plist text.
220220 */
221+ const PLIST_STRING_PATTERN = / < s t r i n g > ( [ ^ < ] + ) < \/ s t r i n g > / ;
222+
221223export function extractLaunchdProgramPath ( opts : {
222224 readonly plistText : string ;
223225} ) : string | null {
224226 const anchor = opts . plistText . indexOf ( "<key>ProgramArguments</key>" ) ;
225227 if ( anchor < 0 ) {
226228 return null ;
227229 }
228- const match = opts . plistText . slice ( anchor ) . match ( / < s t r i n g > ( [ ^ < ] + ) < \/ s t r i n g > / ) ;
230+ const match = opts . plistText . slice ( anchor ) . match ( PLIST_STRING_PATTERN ) ;
229231 return match ?. [ 1 ] ?? null ;
230232}
231233
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ function sleep({ ms }: { readonly ms: number }): Promise<void> {
6868}
6969
7070const DAEMON_COMMAND_MARKER = "daemon start --foreground" ;
71+ const WHITESPACE_PATTERN = / \s + / ;
7172
7273/**
7374 * Finds hackd processes that the pid file does not track ("orphans").
@@ -119,13 +120,13 @@ export async function findOrphanDaemonProcesses(opts: {
119120 * would also kill unrelated processes that merely mention them.
120121 */
121122function isHackDaemonCommand ( opts : { readonly command : string } ) : boolean {
122- const firstToken = opts . command . trim ( ) . split ( / \s + / ) [ 0 ] ?? "" ;
123+ const firstToken = opts . command . trim ( ) . split ( WHITESPACE_PATTERN ) [ 0 ] ?? "" ;
123124 const base = firstToken . split ( "/" ) . pop ( ) ?. toLowerCase ( ) ?? "" ;
124125 if ( base === "hack" || base . startsWith ( "hack-" ) ) {
125126 return true ;
126127 }
127128 if ( base === "bun" ) {
128- const secondToken = opts . command . trim ( ) . split ( / \s + / ) [ 1 ] ?? "" ;
129+ const secondToken = opts . command . trim ( ) . split ( WHITESPACE_PATTERN ) [ 1 ] ?? "" ;
129130 const secondBase = secondToken . split ( "/" ) . pop ( ) ?. toLowerCase ( ) ?? "" ;
130131 return secondBase === "index.ts" || secondBase . startsWith ( "hack" ) ;
131132 }
You can’t perform that action at this time.
0 commit comments