@lasso-ai/cli 1.0.9 → 1.0.10
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/host/daemon.js
CHANGED
|
@@ -51,6 +51,7 @@ class LassoHost {
|
|
|
51
51
|
dnsHandle = null;
|
|
52
52
|
resolver;
|
|
53
53
|
registry;
|
|
54
|
+
cleanupOnStart = new Set();
|
|
54
55
|
running = new Map();
|
|
55
56
|
starting = new Map();
|
|
56
57
|
crashLog = new Map();
|
|
@@ -63,6 +64,8 @@ class LassoHost {
|
|
|
63
64
|
this.secureServer.on("upgrade", (req, socket, head) => this.handleUpgrade(req, socket, head));
|
|
64
65
|
this.resolver = (0, dns_1.createDomainResolver)();
|
|
65
66
|
this.registry = (0, registry_1.loadRegistry)();
|
|
67
|
+
for (const domain of Object.keys(this.registry))
|
|
68
|
+
this.cleanupOnStart.add(domain);
|
|
66
69
|
this.log(`host starting (version ${opts.version || "unknown"})`);
|
|
67
70
|
}
|
|
68
71
|
log(message) {
|
|
@@ -119,7 +122,7 @@ class LassoHost {
|
|
|
119
122
|
}
|
|
120
123
|
this.crashLog.set(domain, crashes);
|
|
121
124
|
const startup = (async () => {
|
|
122
|
-
const result = await (0, runtime_1.startProjectRuntime)(project.directory);
|
|
125
|
+
const result = await (0, runtime_1.startProjectRuntime)(project.directory, { cleanupExisting: this.cleanupOnStart.delete(domain) });
|
|
123
126
|
if (!result.ok || !result.runtime) {
|
|
124
127
|
this.crashLog.set(domain, [...crashes, Date.now()]);
|
|
125
128
|
throw new Error(result.error || `Could not start ${domain}.`);
|
|
@@ -210,6 +213,7 @@ class LassoHost {
|
|
|
210
213
|
for (const [domain, runtime] of this.running) {
|
|
211
214
|
runtime.child.kill("SIGTERM");
|
|
212
215
|
this.running.delete(domain);
|
|
216
|
+
this.cleanupOnStart.add(domain);
|
|
213
217
|
stopped.push(domain);
|
|
214
218
|
this.log(`stopped ${domain} for restart`);
|
|
215
219
|
}
|
|
@@ -224,6 +228,7 @@ class LassoHost {
|
|
|
224
228
|
if (!domain)
|
|
225
229
|
return writeJson(res, 400, { ok: false, error: "A project domain is required." });
|
|
226
230
|
const runtime = this.running.get(domain);
|
|
231
|
+
this.cleanupOnStart.add(domain);
|
|
227
232
|
if (runtime) {
|
|
228
233
|
runtime.child.kill("SIGTERM");
|
|
229
234
|
this.running.delete(domain);
|
|
@@ -20,4 +20,6 @@ export interface StartRuntimeResult {
|
|
|
20
20
|
* answers HTTP before returning. Reuses Lasso's existing framework detection —
|
|
21
21
|
* the Host never guesses a package manager or hardcodes a runtime.
|
|
22
22
|
*/
|
|
23
|
-
export declare function startProjectRuntime(directory: string
|
|
23
|
+
export declare function startProjectRuntime(directory: string, options?: {
|
|
24
|
+
cleanupExisting?: boolean;
|
|
25
|
+
}): Promise<StartRuntimeResult>;
|
package/dist/cli/host/runtime.js
CHANGED
|
@@ -11,10 +11,12 @@ const node_net_1 = __importDefault(require("node:net"));
|
|
|
11
11
|
const node_http_1 = __importDefault(require("node:http"));
|
|
12
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
13
13
|
const node_child_process_1 = require("node:child_process");
|
|
14
|
+
const node_util_1 = require("node:util");
|
|
14
15
|
const framework_1 = require("../utils/framework");
|
|
15
16
|
const paths_1 = require("./paths");
|
|
16
17
|
const READY_TIMEOUT_MS = 60_000;
|
|
17
18
|
const READY_POLL_MS = 500;
|
|
19
|
+
const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
18
20
|
function pickFreePort() {
|
|
19
21
|
return new Promise((resolve, reject) => {
|
|
20
22
|
const server = node_net_1.default.createServer();
|
|
@@ -88,18 +90,57 @@ async function waitUntilReady(port) {
|
|
|
88
90
|
}
|
|
89
91
|
return false;
|
|
90
92
|
}
|
|
93
|
+
async function stopExistingNextDev(directory) {
|
|
94
|
+
if (process.platform === "win32")
|
|
95
|
+
return;
|
|
96
|
+
const lockPath = node_path_1.default.join(directory, ".next", "dev", "lock");
|
|
97
|
+
let pid = 0;
|
|
98
|
+
try {
|
|
99
|
+
const lock = JSON.parse(node_fs_1.default.readFileSync(lockPath, "utf8"));
|
|
100
|
+
pid = Number(lock.pid);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!Number.isInteger(pid) || pid <= 0 || pid === process.pid)
|
|
106
|
+
return;
|
|
107
|
+
try {
|
|
108
|
+
process.kill(pid, 0);
|
|
109
|
+
const { stdout } = await execFileAsync("ps", ["-p", String(pid), "-o", "command="], { maxBuffer: 16 * 1024 });
|
|
110
|
+
if (!/\bnext(?:-dev)?\b|next.*\bdev\b/i.test(stdout))
|
|
111
|
+
return;
|
|
112
|
+
process.kill(pid, "SIGTERM");
|
|
113
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
114
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
115
|
+
try {
|
|
116
|
+
process.kill(pid, 0);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
log(directory, `stopped previous Next.js process ${pid}`);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
process.kill(pid, "SIGKILL");
|
|
124
|
+
log(directory, `force-stopped previous Next.js process ${pid}`);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// The lock may be stale or the process may have exited between checks.
|
|
128
|
+
}
|
|
129
|
+
}
|
|
91
130
|
/**
|
|
92
131
|
* Starts the project's development server on a free port and waits until it
|
|
93
132
|
* answers HTTP before returning. Reuses Lasso's existing framework detection —
|
|
94
133
|
* the Host never guesses a package manager or hardcodes a runtime.
|
|
95
134
|
*/
|
|
96
|
-
async function startProjectRuntime(directory) {
|
|
135
|
+
async function startProjectRuntime(directory, options = {}) {
|
|
97
136
|
const port = await pickFreePort();
|
|
98
137
|
const bridgePort = await pickFreePort();
|
|
99
138
|
const plan = spawnCommand(directory, port, bridgePort);
|
|
100
139
|
if (!plan) {
|
|
101
140
|
return { ok: false, error: `${node_path_1.default.basename(directory)} is not a Vite or Next.js project, so Lasso Host can't start it automatically. Run its dev server yourself.` };
|
|
102
141
|
}
|
|
142
|
+
if (options.cleanupExisting && plan.framework === "next")
|
|
143
|
+
await stopExistingNextDev(directory);
|
|
103
144
|
const child = (0, node_child_process_1.spawn)(plan.command, plan.args, {
|
|
104
145
|
cwd: directory,
|
|
105
146
|
env: { ...process.env, PORT: String(port) },
|
package/package.json
CHANGED