lunel-cli 0.1.99 → 0.1.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +38 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1525,7 +1525,7 @@ function handleProcessesList() {
1525
1525
  }
1526
1526
  return { processes: result };
1527
1527
  }
1528
- function handleProcessesSpawn(payload) {
1528
+ async function handleProcessesSpawn(payload) {
1529
1529
  const command = payload.command;
1530
1530
  const args = payload.args || [];
1531
1531
  const cwd = payload.cwd;
@@ -1539,7 +1539,31 @@ function handleProcessesSpawn(payload) {
1539
1539
  stdio: ["pipe", "pipe", "pipe"],
1540
1540
  shell: false,
1541
1541
  });
1542
- const pid = proc.pid;
1542
+ const pid = await new Promise((resolve, reject) => {
1543
+ let settled = false;
1544
+ const handleSpawn = () => {
1545
+ if (settled)
1546
+ return;
1547
+ settled = true;
1548
+ proc.removeListener("error", handleError);
1549
+ if (!proc.pid) {
1550
+ reject(Object.assign(new Error(`Failed to spawn "${command}"`), { code: "ERROR" }));
1551
+ return;
1552
+ }
1553
+ resolve(proc.pid);
1554
+ };
1555
+ const handleError = (err) => {
1556
+ if (settled)
1557
+ return;
1558
+ settled = true;
1559
+ proc.removeListener("spawn", handleSpawn);
1560
+ reject(Object.assign(new Error(err.message || `Failed to spawn "${command}"`), {
1561
+ code: err.code || "ERROR",
1562
+ }));
1563
+ };
1564
+ proc.once("spawn", handleSpawn);
1565
+ proc.once("error", handleError);
1566
+ });
1543
1567
  const channel = `proc-${pid}`;
1544
1568
  const managedProc = {
1545
1569
  pid,
@@ -1569,6 +1593,17 @@ function handleProcessesSpawn(payload) {
1569
1593
  };
1570
1594
  proc.stdout?.on("data", sendOutput("stdout"));
1571
1595
  proc.stderr?.on("data", sendOutput("stderr"));
1596
+ proc.on("error", (err) => {
1597
+ const message = err.message || `Process "${command}" failed`;
1598
+ processOutputBuffers.set(channel, (processOutputBuffers.get(channel) || "") + `${message}\n`);
1599
+ emitAppEvent({
1600
+ v: 1,
1601
+ id: `evt-${Date.now()}`,
1602
+ ns: "processes",
1603
+ action: "output",
1604
+ payload: { pid, channel, stream: "stderr", data: `${message}\n` },
1605
+ });
1606
+ });
1572
1607
  proc.on("close", (code, signal) => {
1573
1608
  const msg = {
1574
1609
  v: 1,
@@ -2565,7 +2600,7 @@ async function processMessage(message) {
2565
2600
  result = handleProcessesList();
2566
2601
  break;
2567
2602
  case "spawn":
2568
- result = handleProcessesSpawn(payload);
2603
+ result = await handleProcessesSpawn(payload);
2569
2604
  break;
2570
2605
  case "kill":
2571
2606
  result = handleProcessesKill(payload);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lunel-cli",
3
- "version": "0.1.99",
3
+ "version": "0.1.100",
4
4
  "author": [
5
5
  {
6
6
  "name": "Soham Bharambe",