@shipers-dev/multi 0.24.4 → 0.24.6
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.
- package/dist/index.js +90 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -272877,7 +272877,7 @@ import { parseArgs } from "util";
|
|
|
272877
272877
|
// package.json
|
|
272878
272878
|
var package_default = {
|
|
272879
272879
|
name: "@shipers-dev/multi",
|
|
272880
|
-
version: "0.24.
|
|
272880
|
+
version: "0.24.6",
|
|
272881
272881
|
type: "module",
|
|
272882
272882
|
bin: {
|
|
272883
272883
|
"multi-agent": "./dist/index.js"
|
|
@@ -294306,7 +294306,7 @@ var connect2 = (wsUrl) => exports_Effect2.gen(function* () {
|
|
|
294306
294306
|
yield* send2({ _tag: "WSMessage.Ping", requestId: "ping" });
|
|
294307
294307
|
yield* exports_Queue.take(pongMessages).pipe(exports_Effect2.timeout(5000));
|
|
294308
294308
|
yield* exports_Effect2.sleep(25000);
|
|
294309
|
-
}).pipe(exports_Effect2.withSpan("@livestore/sync-cf:connect:checkPingPong")
|
|
294309
|
+
}).pipe(exports_Effect2.withSpan("@livestore/sync-cf:connect:checkPingPong"));
|
|
294310
294310
|
yield* waitUntilOnline.pipe(exports_Effect2.andThen(checkPingPong.pipe(exports_Effect2.forever)), exports_Effect2.tapErrorCause(() => exports_Deferred.succeed(connectionClosed, undefined)), exports_Effect2.forkScoped);
|
|
294311
294311
|
yield* connectionClosed;
|
|
294312
294312
|
}).pipe(exports_Effect2.scoped, exports_Effect2.withSpan("@livestore/sync-cf:connect"));
|
|
@@ -294715,7 +294715,7 @@ import { join as join17, dirname as dirname15 } from "path";
|
|
|
294715
294715
|
// package.json
|
|
294716
294716
|
var package_default2 = {
|
|
294717
294717
|
name: "@shipers-dev/multi",
|
|
294718
|
-
version: "0.24.
|
|
294718
|
+
version: "0.24.6",
|
|
294719
294719
|
type: "module",
|
|
294720
294720
|
bin: {
|
|
294721
294721
|
"multi-agent": "./dist/index.js"
|
|
@@ -296011,7 +296011,9 @@ async function livestoreMain({ cfg, projectIds }) {
|
|
|
296011
296011
|
await new Promise((resolve11) => {
|
|
296012
296012
|
const stop3 = () => {
|
|
296013
296013
|
log6("[livestore] shutdown");
|
|
296014
|
-
Promise.allSettled(stores.map(({ store }) => store.shutdown?.()))
|
|
296014
|
+
const settle = Promise.allSettled(stores.map(({ store }) => store.shutdown?.()));
|
|
296015
|
+
const fuse = new Promise((r9) => setTimeout(r9, 2000));
|
|
296016
|
+
Promise.race([settle, fuse]).finally(() => resolve11());
|
|
296015
296017
|
};
|
|
296016
296018
|
process.on("SIGINT", stop3);
|
|
296017
296019
|
process.on("SIGTERM", stop3);
|
|
@@ -296103,6 +296105,81 @@ async function assembleTask(opts) {
|
|
|
296103
296105
|
};
|
|
296104
296106
|
}
|
|
296105
296107
|
|
|
296108
|
+
// src/_impl/pid-lock.ts
|
|
296109
|
+
import { closeSync as closeSync2, existsSync as existsSync13, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync11, unlinkSync as unlinkSync6, writeSync as writeSync2 } from "fs";
|
|
296110
|
+
import { dirname as dirname16 } from "path";
|
|
296111
|
+
var isAlive = (pid) => {
|
|
296112
|
+
if (!Number.isFinite(pid) || pid <= 0)
|
|
296113
|
+
return false;
|
|
296114
|
+
try {
|
|
296115
|
+
process.kill(pid, 0);
|
|
296116
|
+
return true;
|
|
296117
|
+
} catch (e3) {
|
|
296118
|
+
return e3?.code === "EPERM";
|
|
296119
|
+
}
|
|
296120
|
+
};
|
|
296121
|
+
var writeExclusive = (path12, pid) => {
|
|
296122
|
+
mkdirSync7(dirname16(path12), { recursive: true });
|
|
296123
|
+
const fd2 = openSync2(path12, "wx");
|
|
296124
|
+
try {
|
|
296125
|
+
writeSync2(fd2, String(pid));
|
|
296126
|
+
} finally {
|
|
296127
|
+
closeSync2(fd2);
|
|
296128
|
+
}
|
|
296129
|
+
};
|
|
296130
|
+
var acquirePidLock = (path12) => {
|
|
296131
|
+
const ourPid = process.pid;
|
|
296132
|
+
try {
|
|
296133
|
+
writeExclusive(path12, ourPid);
|
|
296134
|
+
return { ok: true };
|
|
296135
|
+
} catch (e3) {
|
|
296136
|
+
if (e3?.code !== "EEXIST")
|
|
296137
|
+
throw e3;
|
|
296138
|
+
}
|
|
296139
|
+
const raw4 = (() => {
|
|
296140
|
+
try {
|
|
296141
|
+
return readFileSync11(path12, "utf8").trim();
|
|
296142
|
+
} catch {
|
|
296143
|
+
return "";
|
|
296144
|
+
}
|
|
296145
|
+
})();
|
|
296146
|
+
const existingPid = Number(raw4);
|
|
296147
|
+
if (existingPid === ourPid)
|
|
296148
|
+
return { ok: true };
|
|
296149
|
+
if (Number.isFinite(existingPid) && existingPid > 0 && isAlive(existingPid)) {
|
|
296150
|
+
return { ok: false, existingPid };
|
|
296151
|
+
}
|
|
296152
|
+
try {
|
|
296153
|
+
unlinkSync6(path12);
|
|
296154
|
+
} catch {}
|
|
296155
|
+
try {
|
|
296156
|
+
writeExclusive(path12, ourPid);
|
|
296157
|
+
return { ok: true };
|
|
296158
|
+
} catch (e3) {
|
|
296159
|
+
if (e3?.code !== "EEXIST")
|
|
296160
|
+
throw e3;
|
|
296161
|
+
const racingRaw = (() => {
|
|
296162
|
+
try {
|
|
296163
|
+
return readFileSync11(path12, "utf8").trim();
|
|
296164
|
+
} catch {
|
|
296165
|
+
return "";
|
|
296166
|
+
}
|
|
296167
|
+
})();
|
|
296168
|
+
const racingPid = Number(racingRaw);
|
|
296169
|
+
return { ok: false, existingPid: Number.isFinite(racingPid) ? racingPid : 0 };
|
|
296170
|
+
}
|
|
296171
|
+
};
|
|
296172
|
+
var releasePidLock = (path12) => {
|
|
296173
|
+
try {
|
|
296174
|
+
if (!existsSync13(path12))
|
|
296175
|
+
return;
|
|
296176
|
+
const raw4 = readFileSync11(path12, "utf8").trim();
|
|
296177
|
+
if (Number(raw4) !== process.pid)
|
|
296178
|
+
return;
|
|
296179
|
+
unlinkSync6(path12);
|
|
296180
|
+
} catch {}
|
|
296181
|
+
};
|
|
296182
|
+
|
|
296106
296183
|
// src/commands/connect.ts
|
|
296107
296184
|
var connectCmd = exports_Effect.fn("connectCmd")(function* () {
|
|
296108
296185
|
const config5 = yield* Config4;
|
|
@@ -296125,6 +296202,15 @@ var connectCmd = exports_Effect.fn("connectCmd")(function* () {
|
|
|
296125
296202
|
message: "no projects to subscribe to — link this device to a project first or set MULTI_LIVESTORE_PROJECTS=p1,p2"
|
|
296126
296203
|
}));
|
|
296127
296204
|
}
|
|
296205
|
+
if (process.env.MULTI_FORCE_CONNECT !== "1") {
|
|
296206
|
+
const lock = acquirePidLock(PID_PATH);
|
|
296207
|
+
if (!lock.ok) {
|
|
296208
|
+
return yield* exports_Effect.fail(new UsageError({
|
|
296209
|
+
message: `Another multi-agent daemon is already running (pid ${lock.existingPid}). ` + `Stop it with 'multi-agent stop' or set MULTI_FORCE_CONNECT=1 to override.`
|
|
296210
|
+
}));
|
|
296211
|
+
}
|
|
296212
|
+
process.on("exit", () => releasePidLock(PID_PATH));
|
|
296213
|
+
}
|
|
296128
296214
|
yield* logger3.log(`connect: device=${cfg.deviceId} projects=${projectIds.join(",")}`);
|
|
296129
296215
|
yield* exports_Effect.tryPromise({
|
|
296130
296216
|
try: () => livestoreMain({ cfg, projectIds }),
|