GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(desktop): stop dev cleanup from terminating other worktrees (#18397) · pingdotgg/t3code@b05ff17

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/desktop/scripts
    • dev-electron.mjs
    • electron-launcher.test.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/desktop/scripts/dev-electron.mjs‎

Copy file name to clipboardExpand all lines: apps/desktop/scripts/dev-electron.mjs
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ function cleanupStaleDevApps() {
9494
return;
9595
}
9696

97-
NodeChildProcess.spawnSync("pkill", ["-f", "--", `--t3code-dev-root=${desktopDir}`], {
98-
stdio: "ignore",
99-
});
97+
const escapedDesktopDir = desktopDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
98+
NodeChildProcess.spawnSync(
99+
"pkill",
100+
["-f", "--", `(^| )--t3code-dev-root=${escapedDesktopDir}( |$)`],
101+
{
102+
stdio: "ignore",
103+
},
104+
);
100105
}
101106

102107
function startApp() {
Collapse file

‎apps/desktop/scripts/electron-launcher.test.mjs‎

Copy file name to clipboardExpand all lines: apps/desktop/scripts/electron-launcher.test.mjs
+93Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import * as NodeChildProcess from "node:child_process";
2+
import * as NodeEvents from "node:events";
13
import * as NodeFS from "node:fs";
24
import * as NodeOS from "node:os";
35
import * as NodePath from "node:path";
6+
import * as NodeVM from "node:vm";
47

58
import { assert, describe, it } from "vite-plus/test";
69

@@ -151,3 +154,93 @@ describe("electron development launcher", () => {
151154
assert.equal(production.generatedIconPath, "/runtime/icon-prod.icns");
152155
});
153156
});
157+
158+
async function startupCleanupPattern(desktopDir) {
159+
const source = NodeFS.readFileSync(new URL("./dev-electron.mjs", import.meta.url), "utf8");
160+
let pattern;
161+
// Supply inert imports so the real startup runs without launching Electron or signalling processes.
162+
await NodeVM.runInNewContext(
163+
`(async () => { ${source.replace(/^import\s[\s\S]*?;\n/gm, "")} })()`,
164+
{
165+
NodeChildProcess: {
166+
execFileSync: () => undefined,
167+
spawnSync: (command, args) => {
168+
if (command === "pkill" && args.includes("-f")) pattern = args.at(-1);
169+
},
170+
spawn: () => new NodeEvents.EventEmitter(),
171+
},
172+
NodeFS: { watch: () => ({ close: () => undefined }) },
173+
NodeOS: { platform: () => "linux" },
174+
NodePath,
175+
desktopDir,
176+
resolveDevProtocolClient: () => null,
177+
resolveElectronLaunchCommand: (args) => ({ electronPath: "electron", args }),
178+
waitForResources: async () => undefined,
179+
URL,
180+
process: {
181+
env: { VITE_DEV_SERVER_URL: "http://localhost:1234" },
182+
execPath: "node",
183+
once: () => undefined,
184+
},
185+
},
186+
);
187+
assert.isString(pattern);
188+
return pattern;
189+
}
190+
191+
it
192+
// oxlint-disable-next-line t3code/no-global-process-runtime -- Native pgrep is unavailable on Windows.
193+
.skipIf(NodeOS.platform() === "win32")
194+
.each([
195+
"/tmp/t3-feature.one/apps/desktop",
196+
"/tmp/t3-feature.one [two](three)+?^${four}|back\\slash*/apps/desktop",
197+
])("dev cleanup matches only the literal root argument: %s", async (desktopDir) => {
198+
const pattern = await startupCleanupPattern(desktopDir);
199+
const flag = `--t3code-dev-root=${desktopDir}`;
200+
const argvCases = [
201+
[flag],
202+
[flag, "main.cjs"],
203+
[flag.replace(".one", "Xone")],
204+
[`${flag}-two`],
205+
[`prefix${flag}`],
206+
[`--t3code-dev-root=/other${desktopDir}`],
207+
];
208+
const children = [];
209+
try {
210+
for (const args of argvCases) {
211+
const child = NodeChildProcess.spawn(
212+
process.execPath,
213+
["-e", "process.send('ready'); setInterval(() => {}, 1000)", "--", ...args],
214+
{ stdio: ["ignore", "ignore", "inherit", "ipc"] },
215+
);
216+
children.push(child);
217+
await Promise.race([
218+
NodeEvents.once(child, "message"),
219+
NodeEvents.once(child, "exit").then(() => {
220+
throw new Error("Fixture exited before readiness");
221+
}),
222+
]);
223+
}
224+
// Use the native ERE engine, but never execute the launcher's signal-producing command.
225+
const result = NodeChildProcess.spawnSync(
226+
"pgrep",
227+
["-P", String(process.pid), "-f", "--", pattern],
228+
{ encoding: "utf8" },
229+
);
230+
assert.equal(result.status, 0, result.stderr);
231+
const matches = result.stdout.trim().split(/\s+/).map(Number);
232+
assert.sameMembers(
233+
matches,
234+
children.slice(0, 2).map((child) => child.pid),
235+
);
236+
} finally {
237+
await Promise.all(
238+
children.map(async (child) => {
239+
if (child.exitCode !== null || child.signalCode !== null) return;
240+
const exited = NodeEvents.once(child, "exit");
241+
child.kill("SIGTERM");
242+
await exited;
243+
}),
244+
);
245+
}
246+
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.