MCPcopy
hub / github.com/mksglu/context-mode / applyLegacyRewrite

Function applyLegacyRewrite

tests/hooks/integration.test.ts:1242–1259  ·  view source on GitHub ↗
(command: string, targetDir: string)

Source from the content-addressed store, hash-verified

1240 // block. The test deliberately uses a *spaced* targetDir to mirror the
1241 // user-reported Dropbox/iCloud scenario from #636.
1242 function applyLegacyRewrite(command: string, targetDir: string): string | null {
1243 if (
1244 command &&
1245 command.includes(".mjs") &&
1246 command.includes("context-mode") &&
1247 !command.includes(targetDir)
1248 ) {
1249 const scriptMatch = command.match(/([a-z]+\.mjs)\s*"?\s*$/);
1250 if (scriptMatch) {
1251 const scriptPath = resolve(targetDir, "hooks", scriptMatch[1]);
1252 // MUST match the production form in hooks/pretooluse.mjs (#636 fix):
1253 // path is JSON.stringify'd so spaces inside targetDir survive
1254 // /bin/sh word-splitting at hook-spawn time.
1255 return `node ${JSON.stringify(scriptPath)}`;
1256 }
1257 }
1258 return null;
1259 }
1260
1261 test.skipIf(skipOnWindows)(
1262 "rewritten command keeps spaced path quoted so /bin/sh sees one arg",

Callers 1

Calls 1

includesMethod · 0.45

Tested by

no test coverage detected