MCPcopy Create free account
hub / github.com/delinoio/oss / spawnDevServer

Function spawnDevServer

scripts/spawn-dev-server.mjs:199–273  ·  view source on GitHub ↗
(
  command,
  args,
  options,
  { terminateProcessTree = false, captureOutput } = {},
)

Source from the content-addressed store, hash-verified

197}
198
199export async function spawnDevServer(
200 command,
201 args,
202 options,
203 { terminateProcessTree = false, captureOutput } = {},
204) {
205 const managePosixProcessGroup =
206 process.platform !== "win32" && terminateProcessTree;
207 const child = spawn(
208 command,
209 args,
210 managePosixProcessGroup ? { ...options, detached: true } : options,
211 );
212 const signalHandlers = new Map();
213 let forwardedSignal = null;
214 const terminationPromises = [];
215
216 const removeSignalHandlers = () => {
217 for (const [signal, handler] of signalHandlers) {
218 process.off(signal, handler);
219 }
220 };
221
222 for (const signal of terminationSignals) {
223 const handler = () => {
224 if (
225 !managePosixProcessGroup &&
226 (child.exitCode !== null || child.signalCode !== null)
227 ) {
228 return;
229 }
230
231 forwardedSignal = signal;
232 const terminationPromise = terminateProcessTree
233 ? process.platform === "win32"
234 ? terminateWindowsProcessTree(child, signal)
235 : terminatePosixProcessGroup(child, signal)
236 : Promise.resolve(child.kill(signal));
237 terminationPromises.push(terminationPromise);
238 // The child may take longer to exit than the termination command takes to
239 // fail. Attach a handler now and rethrow when both operations are awaited.
240 void terminationPromise.catch(() => {});
241 };
242
243 signalHandlers.set(signal, handler);
244 process.on(signal, handler);
245 }
246
247 const childResult = new Promise((resolve, reject) => {
248 child.once("error", (error) => {
249 reject(error);
250 });
251
252 child.once("exit", (code, signal) => {
253 resolve({ code, signal });
254 });
255 });
256

Callers 4

development.mjsFile · 0.90
tauri-cli.mjsFile · 0.90

Calls 4

spawnFunction · 0.85
removeSignalHandlersFunction · 0.85
resolveFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected