@hamedb89/localghost 0.5.0 → 0.6.1
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/cli.js +82 -19
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +36 -2
- package/dist/index.js.map +1 -1
- package/dist/vite.js +34 -0
- package/dist/vite.js.map +1 -1
- package/docs/localghost.1.md +10 -0
- package/package.json +1 -1
package/dist/vite.js
CHANGED
|
@@ -306,6 +306,9 @@ function validRegistry(value) {
|
|
|
306
306
|
function pruneRegistry(registry, now, isRunning) {
|
|
307
307
|
registry.leases = registry.leases.filter((lease) => lease.expiresAt > now && isRunning(lease.pid));
|
|
308
308
|
}
|
|
309
|
+
function isTestSessionKey(instanceKey) {
|
|
310
|
+
return instanceKey.startsWith("test:");
|
|
311
|
+
}
|
|
309
312
|
async function readJson(path) {
|
|
310
313
|
try {
|
|
311
314
|
return JSON.parse(await readFile(path, "utf8"));
|
|
@@ -402,6 +405,37 @@ function createLocalghostRegistry(options = {}) {
|
|
|
402
405
|
await releaseLock();
|
|
403
406
|
}
|
|
404
407
|
},
|
|
408
|
+
async pruneTestSessions() {
|
|
409
|
+
const releaseLock = await lock();
|
|
410
|
+
try {
|
|
411
|
+
const registry = await readRegistry();
|
|
412
|
+
const staleTestKeys = new Set(
|
|
413
|
+
registry.leases.filter((lease) => isTestSessionKey(lease.instanceKey) && (lease.expiresAt <= now() || !isRunning(lease.pid))).map((lease) => leaseKey(lease.projectCwd, lease.instanceKey))
|
|
414
|
+
);
|
|
415
|
+
const beforeLeases = registry.leases.length;
|
|
416
|
+
registry.leases = registry.leases.filter((lease) => !staleTestKeys.has(leaseKey(lease.projectCwd, lease.instanceKey)));
|
|
417
|
+
const activeKeys = new Set(registry.leases.map((lease) => leaseKey(lease.projectCwd, lease.instanceKey)));
|
|
418
|
+
const beforeAllocations = registry.allocations.length;
|
|
419
|
+
registry.allocations = registry.allocations.filter(
|
|
420
|
+
(allocation) => !isTestSessionKey(allocation.instanceKey) || activeKeys.has(leaseKey(allocation.projectCwd, allocation.instanceKey))
|
|
421
|
+
);
|
|
422
|
+
await writeRegistry(registry);
|
|
423
|
+
return {
|
|
424
|
+
removedLeases: beforeLeases - registry.leases.length,
|
|
425
|
+
removedAllocations: beforeAllocations - registry.allocations.length
|
|
426
|
+
};
|
|
427
|
+
} finally {
|
|
428
|
+
await releaseLock();
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
async reset() {
|
|
432
|
+
const releaseLock = await lock();
|
|
433
|
+
try {
|
|
434
|
+
await writeRegistry({ version: 1, allocations: [], leases: [] });
|
|
435
|
+
} finally {
|
|
436
|
+
await releaseLock();
|
|
437
|
+
}
|
|
438
|
+
},
|
|
405
439
|
async acquirePort(acquireOptions) {
|
|
406
440
|
const projectCwd = canonicalizeLocalghostProjectCwd(acquireOptions.projectCwd ?? cwd);
|
|
407
441
|
if (!acquireOptions.instanceKey) throw new Error("instanceKey is required");
|