larness 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +205 -2
- package/app.js +131 -0
- package/apps/server/dist/address-UO6lb2Hx.js +95 -0
- package/apps/server/dist/client-DGXcZxzL.js +121 -0
- package/apps/server/dist/doctor-CTealIcx.js +131 -0
- package/apps/server/dist/doctor.js +13 -0
- package/apps/server/dist/index.js +25481 -0
- package/apps/server/dist/lock-8kmtcopF.js +102 -0
- package/apps/server/dist/managed-CHal_mk1.js +216 -0
- package/apps/server/dist/paths-Bp1nTSw3.js +2434 -0
- package/apps/server/dist/status-Dyecl2ni.js +50 -0
- package/apps/server/dist/status.js +31 -0
- package/apps/server/dist/tui.js +1628 -0
- package/apps/server/drizzle/0001_auth.sql +110 -0
- package/apps/server/drizzle/0002_projects.sql +13 -0
- package/apps/server/drizzle/0003_workspace.sql +81 -0
- package/apps/server/drizzle/0004_models.sql +30 -0
- package/apps/server/drizzle/0005_resources.sql +54 -0
- package/apps/server/drizzle/0006_commands.sql +24 -0
- package/apps/server/drizzle/0007_terminals.sql +42 -0
- package/apps/server/drizzle/0008_resource_actions.sql +24 -0
- package/apps/server/drizzle/0009_terminal_title.sql +1 -0
- package/apps/server/drizzle/0010_services.sql +32 -0
- package/apps/server/drizzle/0011_deployments.sql +88 -0
- package/apps/server/drizzle/0012_deployment_authorizations.sql +67 -0
- package/apps/server/drizzle/0013_service_ops.sql +64 -0
- package/apps/server/drizzle/0014_service_actions.sql +36 -0
- package/apps/server/drizzle/0015_model_catalog.sql +17 -0
- package/apps/server/drizzle/0016_multi_provider.sql +2 -0
- package/apps/server/drizzle/0017_model_visibility.sql +10 -0
- package/apps/server/drizzle/0018_model_defaults.sql +9 -0
- package/apps/server/drizzle/0019_credential_endpoint.sql +1 -0
- package/apps/server/drizzle/0020_compatible_context.sql +1 -0
- package/apps/server/drizzle/0021_context_summaries.sql +13 -0
- package/apps/server/drizzle/0022_scheduler.sql +58 -0
- package/apps/server/drizzle/meta/0001_snapshot.json +705 -0
- package/apps/server/drizzle/meta/0002_snapshot.json +784 -0
- package/apps/server/drizzle/meta/0003_snapshot.json +1300 -0
- package/apps/server/drizzle/meta/0004_snapshot.json +1489 -0
- package/apps/server/drizzle/meta/0005_snapshot.json +1794 -0
- package/apps/server/drizzle/meta/0006_snapshot.json +1953 -0
- package/apps/server/drizzle/meta/0007_snapshot.json +2232 -0
- package/apps/server/drizzle/meta/0008_snapshot.json +2391 -0
- package/apps/server/drizzle/meta/0009_snapshot.json +2398 -0
- package/apps/server/drizzle/meta/0010_snapshot.json +2601 -0
- package/apps/server/drizzle/meta/0015_snapshot.json +4332 -0
- package/apps/server/drizzle/meta/0016_snapshot.json +4346 -0
- package/apps/server/drizzle/meta/0017_snapshot.json +4408 -0
- package/apps/server/drizzle/meta/0018_snapshot.json +4468 -0
- package/apps/server/drizzle/meta/0019_snapshot.json +4475 -0
- package/apps/server/drizzle/meta/0020_snapshot.json +4482 -0
- package/apps/server/drizzle/meta/0021_snapshot.json +4565 -0
- package/apps/server/drizzle/meta/0022_snapshot.json +4960 -0
- package/apps/server/drizzle/meta/_journal.json +160 -0
- package/apps/server/package.json +57 -0
- package/apps/web/dist/assets/FileEditor-DpVfk7t3.js +1 -0
- package/apps/web/dist/assets/FileViewer-Bv5VYaA3.js +1 -0
- package/apps/web/dist/assets/abap-DLDM7-KI.js +1 -0
- package/apps/web/dist/assets/apex-DNDY2TF8.js +1 -0
- package/apps/web/dist/assets/azcli-Y6nb8tq_.js +1 -0
- package/apps/web/dist/assets/bat-BwHxbl9M.js +1 -0
- package/apps/web/dist/assets/bicep-CFznDFnq.js +2 -0
- package/apps/web/dist/assets/cameligo-Bf6VGUru.js +1 -0
- package/apps/web/dist/assets/clojure-Dnu-v4kV.js +1 -0
- package/apps/web/dist/assets/codicon-DF1abBS2.ttf +0 -0
- package/apps/web/dist/assets/coffee-Bd8akH9Z.js +1 -0
- package/apps/web/dist/assets/cpp-BbWJElDN.js +1 -0
- package/apps/web/dist/assets/csharp-Co3qMtFm.js +1 -0
- package/apps/web/dist/assets/csp-D-4FJmMZ.js +1 -0
- package/apps/web/dist/assets/css-DdJfP1eB.js +3 -0
- package/apps/web/dist/assets/css.worker-C_6RgliQ.js +97 -0
- package/apps/web/dist/assets/cssMode-EHCHSzzL.js +1 -0
- package/apps/web/dist/assets/cypher-cTPe9QuQ.js +1 -0
- package/apps/web/dist/assets/dart-BOtBlQCF.js +1 -0
- package/apps/web/dist/assets/dockerfile-BG73LgW2.js +1 -0
- package/apps/web/dist/assets/ecl-BEgZUVRK.js +1 -0
- package/apps/web/dist/assets/editor.worker-D1TDBLlL.js +30 -0
- package/apps/web/dist/assets/elixir-BkW5O-1t.js +1 -0
- package/apps/web/dist/assets/flow9-BeJ5waoc.js +1 -0
- package/apps/web/dist/assets/freemarker2-CYDUi4bR.js +3 -0
- package/apps/web/dist/assets/fsharp-PahG7c26.js +1 -0
- package/apps/web/dist/assets/go-acbASCJo.js +1 -0
- package/apps/web/dist/assets/graphql-BxJiqAUM.js +1 -0
- package/apps/web/dist/assets/handlebars-Bl5r-XBz.js +1 -0
- package/apps/web/dist/assets/hcl-DtV1sZF8.js +1 -0
- package/apps/web/dist/assets/html-Dimr8AuT.js +1 -0
- package/apps/web/dist/assets/html.worker-CLyYFd_g.js +474 -0
- package/apps/web/dist/assets/htmlMode-DbKEQN5e.js +1 -0
- package/apps/web/dist/assets/index-CiO_U1kt.js +158 -0
- package/apps/web/dist/assets/index-Cn8Mc6ux.css +1 -0
- package/apps/web/dist/assets/ini-Kd9XrMLS.js +1 -0
- package/apps/web/dist/assets/java-CXBNlu9o.js +1 -0
- package/apps/web/dist/assets/javascript-CAsmnqI3.js +1 -0
- package/apps/web/dist/assets/json.worker-BggoxaER.js +62 -0
- package/apps/web/dist/assets/jsonMode-FAO7KTW2.js +7 -0
- package/apps/web/dist/assets/julia-cl7-CwDS.js +1 -0
- package/apps/web/dist/assets/kotlin-s7OhZKlX.js +1 -0
- package/apps/web/dist/assets/less-9HpZscsL.js +2 -0
- package/apps/web/dist/assets/lexon-OrD6JF1K.js +1 -0
- package/apps/web/dist/assets/liquid-5H_43_EZ.js +1 -0
- package/apps/web/dist/assets/lspLanguageFeatures-DnuYc3pX.js +4 -0
- package/apps/web/dist/assets/lua-Cyyb5UIc.js +1 -0
- package/apps/web/dist/assets/m3-B8OfTtLu.js +1 -0
- package/apps/web/dist/assets/markdown-BFxVWTOG.js +1 -0
- package/apps/web/dist/assets/mdx-DJvtDn95.js +1 -0
- package/apps/web/dist/assets/mips-CiqrrVzr.js +1 -0
- package/apps/web/dist/assets/monaco-BEZSi3GX.js +1005 -0
- package/apps/web/dist/assets/monaco-Ced-qlZg.css +1 -0
- package/apps/web/dist/assets/msdax-DmeGPVcC.js +1 -0
- package/apps/web/dist/assets/mysql-C_tMU-Nz.js +1 -0
- package/apps/web/dist/assets/objective-c-BDtDVThU.js +1 -0
- package/apps/web/dist/assets/pascal-vHIfCaH5.js +1 -0
- package/apps/web/dist/assets/pascaligo-DtZ0uQbO.js +1 -0
- package/apps/web/dist/assets/perl-Ub6l9XKa.js +1 -0
- package/apps/web/dist/assets/pgsql-BlNEE0v7.js +1 -0
- package/apps/web/dist/assets/php-BBUBE1dy.js +1 -0
- package/apps/web/dist/assets/pla-DSh2-awV.js +1 -0
- package/apps/web/dist/assets/postiats-CocnycG-.js +1 -0
- package/apps/web/dist/assets/powerquery-tScXyioY.js +1 -0
- package/apps/web/dist/assets/powershell-COWaemsV.js +1 -0
- package/apps/web/dist/assets/protobuf-Brw8urJB.js +2 -0
- package/apps/web/dist/assets/pug-8SOpv6rk.js +1 -0
- package/apps/web/dist/assets/python-D4581wh8.js +1 -0
- package/apps/web/dist/assets/qsharp-Bw9ernYp.js +1 -0
- package/apps/web/dist/assets/r-j7ic8hl3.js +1 -0
- package/apps/web/dist/assets/razor-Cob92s3y.js +1 -0
- package/apps/web/dist/assets/redis-Bu5POkcn.js +1 -0
- package/apps/web/dist/assets/redshift-Bs9aos_-.js +1 -0
- package/apps/web/dist/assets/restructuredtext-CqXO7rUv.js +1 -0
- package/apps/web/dist/assets/ruby-zBfavPgS.js +1 -0
- package/apps/web/dist/assets/rust-BzKRNQWT.js +1 -0
- package/apps/web/dist/assets/sb-BBc9UKZt.js +1 -0
- package/apps/web/dist/assets/scala-D9hQfWCl.js +1 -0
- package/apps/web/dist/assets/scheme-BPhDTwHR.js +1 -0
- package/apps/web/dist/assets/scss-CBJaRo0y.js +3 -0
- package/apps/web/dist/assets/shell-DiJ1NA_G.js +1 -0
- package/apps/web/dist/assets/solidity-Db0IVjzk.js +1 -0
- package/apps/web/dist/assets/sophia-CnS9iZB_.js +1 -0
- package/apps/web/dist/assets/sparql-CJmd_6j2.js +1 -0
- package/apps/web/dist/assets/sql-ClhHkBeG.js +1 -0
- package/apps/web/dist/assets/st-CHwy0fLd.js +1 -0
- package/apps/web/dist/assets/swift-CnmFD0ga.js +1 -0
- package/apps/web/dist/assets/systemverilog-Bs9z6M-B.js +1 -0
- package/apps/web/dist/assets/tcl-Dm6ycUr_.js +1 -0
- package/apps/web/dist/assets/ts.worker-BrLZGe_E.js +67722 -0
- package/apps/web/dist/assets/tsMode-WJsr57wC.js +11 -0
- package/apps/web/dist/assets/twig-Csy3S7wG.js +1 -0
- package/apps/web/dist/assets/typescript-8M7GiCNW.js +1 -0
- package/apps/web/dist/assets/typespec-Btyra-wh.js +1 -0
- package/apps/web/dist/assets/vb-Db0cS2oM.js +1 -0
- package/apps/web/dist/assets/wgsl-BTesnYfV.js +298 -0
- package/apps/web/dist/assets/workers-FOC7l7Wh.js +1 -0
- package/apps/web/dist/assets/xml-Hm5ZZqOZ.js +1 -0
- package/apps/web/dist/assets/yaml-E7sEyvM5.js +1 -0
- package/apps/web/dist/favicon.svg +4 -0
- package/apps/web/dist/index.html +15 -0
- package/docs/README.md +26 -0
- package/docs/guides/install.md +63 -0
- package/package.json +94 -4
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
//#region src/bootstrap/lock.ts
|
|
4
|
+
var InstanceLockedError = class extends Error {
|
|
5
|
+
pid;
|
|
6
|
+
constructor(pid, message) {
|
|
7
|
+
super(message ?? `another Larness instance is already running (pid ${pid ?? "unknown"})`);
|
|
8
|
+
this.name = "InstanceLockedError";
|
|
9
|
+
this.pid = pid;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function lockFilePath(dataDir) {
|
|
13
|
+
return path.join(dataDir, "larness.lock");
|
|
14
|
+
}
|
|
15
|
+
function isProcessAlive(pid) {
|
|
16
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
17
|
+
try {
|
|
18
|
+
process.kill(pid, 0);
|
|
19
|
+
return true;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return error.code === "EPERM";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function parseRecord(text) {
|
|
25
|
+
try {
|
|
26
|
+
const value = JSON.parse(text);
|
|
27
|
+
if (typeof value !== "object" || value === null || !("pid" in value) || !("startedAt" in value) || !("version" in value)) return null;
|
|
28
|
+
const { pid, startedAt, version } = value;
|
|
29
|
+
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0 || typeof startedAt !== "number" || typeof version !== "string") return null;
|
|
30
|
+
return {
|
|
31
|
+
pid,
|
|
32
|
+
startedAt,
|
|
33
|
+
version
|
|
34
|
+
};
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function readRecord(lockPath) {
|
|
40
|
+
try {
|
|
41
|
+
return parseRecord(await readFile(lockPath, "utf8"));
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function inspectInstanceLock(dataDir) {
|
|
47
|
+
const lockPath = lockFilePath(dataDir);
|
|
48
|
+
try {
|
|
49
|
+
await readFile(lockPath);
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const record = await readRecord(lockPath);
|
|
54
|
+
return {
|
|
55
|
+
path: lockPath,
|
|
56
|
+
record,
|
|
57
|
+
alive: record !== null && isProcessAlive(record.pid)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async function removeIfUnchanged(lockPath, expected) {
|
|
61
|
+
try {
|
|
62
|
+
const current = parseRecord(await readFile(lockPath, "utf8"));
|
|
63
|
+
if (current === null || current.pid !== expected.pid || current.startedAt !== expected.startedAt) return;
|
|
64
|
+
await unlink(lockPath);
|
|
65
|
+
} catch {}
|
|
66
|
+
}
|
|
67
|
+
async function acquireInstanceLock(dataDir, options) {
|
|
68
|
+
const lockPath = lockFilePath(dataDir);
|
|
69
|
+
const record = {
|
|
70
|
+
pid: options.pid ?? process.pid,
|
|
71
|
+
startedAt: (options.now ?? Date.now)(),
|
|
72
|
+
version: options.version
|
|
73
|
+
};
|
|
74
|
+
for (let attempt = 0; attempt < 2; attempt += 1) try {
|
|
75
|
+
await writeFile(lockPath, `${JSON.stringify(record)}\n`, {
|
|
76
|
+
flag: "wx",
|
|
77
|
+
mode: 384
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
...record,
|
|
81
|
+
path: lockPath
|
|
82
|
+
};
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error.code !== "EEXIST") throw error;
|
|
85
|
+
const existing = await readRecord(lockPath);
|
|
86
|
+
if (existing === null) throw new InstanceLockedError(null, `lock file is unreadable: ${lockPath}; verify no server is running before removing it`);
|
|
87
|
+
if (isProcessAlive(existing.pid)) throw new InstanceLockedError(existing.pid);
|
|
88
|
+
await removeIfUnchanged(lockPath, existing);
|
|
89
|
+
}
|
|
90
|
+
throw new InstanceLockedError(null, "failed to acquire the instance lock after a stale-lock retry");
|
|
91
|
+
}
|
|
92
|
+
async function releaseInstanceLock(lock) {
|
|
93
|
+
const current = await readRecord(lock.path);
|
|
94
|
+
if (current === null || current.pid !== lock.pid) return;
|
|
95
|
+
try {
|
|
96
|
+
await unlink(lock.path);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error.code !== "ENOENT") throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
export { inspectInstanceLock as n, releaseInstanceLock as r, acquireInstanceLock as t };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { vn as OriginUrlSchema } from "./paths-Bp1nTSw3.js";
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { randomInt } from "node:crypto";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
const PAIRING_CODE_TTL_MS = 5 * 6e4;
|
|
8
|
+
const PAIRING_REQUEST_TTL_MS = 10 * 6e4;
|
|
9
|
+
const ENROLLMENT_TTL_MS = 5 * 6e4;
|
|
10
|
+
function generatePairingCode() {
|
|
11
|
+
const characters = [];
|
|
12
|
+
const limit = 256 - 256 % 32;
|
|
13
|
+
while (characters.length < 10) {
|
|
14
|
+
const byte = randomInt(0, 256);
|
|
15
|
+
if (byte < limit) characters.push("0123456789ABCDEFGHJKMNPQRSTVWXYZ"[byte % 32] ?? "0");
|
|
16
|
+
}
|
|
17
|
+
return characters.join("");
|
|
18
|
+
}
|
|
19
|
+
function formatPairingCode(code) {
|
|
20
|
+
const normalized = normalizePairingCode(code);
|
|
21
|
+
return `${normalized.slice(0, 5)}-${normalized.slice(5)}`;
|
|
22
|
+
}
|
|
23
|
+
function normalizePairingCode(input) {
|
|
24
|
+
return input.toUpperCase().replace(/[\s-]/g, "").replace(/O/g, "0").replace(/[IL]/g, "1");
|
|
25
|
+
}
|
|
26
|
+
function generateShortCode() {
|
|
27
|
+
return randomInt(0, 1e6).toString().padStart(6, "0");
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/dev-web/paths.ts
|
|
31
|
+
const Manifest = z.object({
|
|
32
|
+
dependencies: z.record(z.string(), z.string()).optional(),
|
|
33
|
+
optionalDependencies: z.record(z.string(), z.string()).optional(),
|
|
34
|
+
peerDependencies: z.record(z.string(), z.string()).optional()
|
|
35
|
+
});
|
|
36
|
+
const contains = (root, file) => file === root || file.startsWith(root + path.sep);
|
|
37
|
+
function webRoots(webRoot) {
|
|
38
|
+
const roots = /* @__PURE__ */ new Set();
|
|
39
|
+
const visit = (directory) => {
|
|
40
|
+
if (!existsSync(directory)) return;
|
|
41
|
+
const root = realpathSync(directory);
|
|
42
|
+
if (roots.has(root)) return;
|
|
43
|
+
roots.add(root);
|
|
44
|
+
const manifestPath = path.join(root, "package.json");
|
|
45
|
+
if (!existsSync(manifestPath)) return;
|
|
46
|
+
const pkg = Manifest.parse(JSON.parse(readFileSync(manifestPath, "utf8")));
|
|
47
|
+
for (const name of Object.keys({
|
|
48
|
+
...pkg.dependencies,
|
|
49
|
+
...pkg.optionalDependencies,
|
|
50
|
+
...pkg.peerDependencies
|
|
51
|
+
})) {
|
|
52
|
+
let base = root;
|
|
53
|
+
for (;;) {
|
|
54
|
+
const candidate = path.join(base, "node_modules", name);
|
|
55
|
+
if (existsSync(candidate)) {
|
|
56
|
+
visit(candidate);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
const parent = path.dirname(base);
|
|
60
|
+
if (parent === base) break;
|
|
61
|
+
base = parent;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
visit(webRoot);
|
|
66
|
+
visit(path.resolve(webRoot, "../../packages/ui"));
|
|
67
|
+
visit(path.resolve(webRoot, "../../packages/shared"));
|
|
68
|
+
visit(path.join(webRoot, "node_modules/vite"));
|
|
69
|
+
return [...roots];
|
|
70
|
+
}
|
|
71
|
+
function isDevPath(pathname) {
|
|
72
|
+
return /^\/(?:@vite(?:\/|$)|@react-refresh(?:\/|$)|@fs(?:\/|$)|@id(?:\/|$)|src(?:\/|$)|node_modules(?:\/|$)|__vite|__open-in-editor|_larness(?:\/|$))/.test(pathname);
|
|
73
|
+
}
|
|
74
|
+
function permittedPath(rawUrl, webRoot, roots) {
|
|
75
|
+
try {
|
|
76
|
+
const rawPath = rawUrl.split("?")[0] ?? "";
|
|
77
|
+
const decoded = decodeURIComponent(rawPath);
|
|
78
|
+
if (!decoded.startsWith("/") || decoded.startsWith("//") || decoded.includes("%") || decoded.includes("\\") || decoded.includes("\0")) return false;
|
|
79
|
+
if (decoded.split("/").some((s) => s === ".." || s === "." || s.startsWith(".env") || s === ".git" || /^(?:config\.json|master\.key|larness\.(?:db|lock)|vite\.config\..*|.*\.log)$/.test(s))) return false;
|
|
80
|
+
if (/^\/(?:api|ws|_larness)(?:\/|$)/.test(decoded) || decoded.startsWith("/__open-in-editor") || decoded.startsWith("/__vite")) return false;
|
|
81
|
+
const file = decoded.startsWith("/@fs/") ? decoded.slice(4) : path.join(webRoot, decoded);
|
|
82
|
+
if (existsSync(file)) return roots.some((root) => contains(realpathSync(root), realpathSync(file)));
|
|
83
|
+
let ancestor = file;
|
|
84
|
+
while (!existsSync(ancestor)) {
|
|
85
|
+
const parent = path.dirname(ancestor);
|
|
86
|
+
if (parent === ancestor) return false;
|
|
87
|
+
ancestor = parent;
|
|
88
|
+
}
|
|
89
|
+
return roots.some((root) => contains(realpathSync(root), realpathSync(ancestor)));
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/dev-web/control.ts
|
|
96
|
+
const HMR_PATH = "/_larness/dev/hmr";
|
|
97
|
+
const NONCE_MARKER = "LARNESS_DEV_RESPONSE_NONCE";
|
|
98
|
+
var DevWebUnavailable = class extends Error {
|
|
99
|
+
code = "DEV_WEB_UNAVAILABLE";
|
|
100
|
+
constructor() {
|
|
101
|
+
super("开发运行环境已停止,请重新启动 TUI");
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var EntryConfigError = class extends Error {
|
|
105
|
+
constructor(origin, port) {
|
|
106
|
+
const canonical = new URL(OriginUrlSchema.parse(origin));
|
|
107
|
+
const targetPort = Number(canonical.port || (canonical.protocol === "https:" ? 443 : 80));
|
|
108
|
+
super(`浏览器地址是 ${canonical.origin},Server 监听端口是 ${port}。请关闭实例,一次性将 config.json 的 server.port 对齐为 ${targetPort},保留 publicUrl 和其他配置;若端口来自环境变量,请调整对应环境变量。`);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const devWebCache = (generation) => path.join(tmpdir(), `larness-vite-cache-${z.uuid().parse(generation)}`);
|
|
112
|
+
const DevWebTargetSchema = z.strictObject({
|
|
113
|
+
generation: z.uuid(),
|
|
114
|
+
host: z.literal("127.0.0.1"),
|
|
115
|
+
port: z.int().min(1).max(65535)
|
|
116
|
+
});
|
|
117
|
+
const DevWebReadySchema = DevWebTargetSchema.extend({ type: z.literal("dev-web.ready") });
|
|
118
|
+
const DevWebAttachSchema = DevWebTargetSchema.extend({ type: z.literal("dev-web.attach") });
|
|
119
|
+
const DevWebAttachedSchema = z.strictObject({
|
|
120
|
+
type: z.literal("dev-web.attached"),
|
|
121
|
+
generation: z.uuid()
|
|
122
|
+
});
|
|
123
|
+
z.strictObject({
|
|
124
|
+
type: z.literal("dev-web.start"),
|
|
125
|
+
generation: z.uuid(),
|
|
126
|
+
origin: OriginUrlSchema
|
|
127
|
+
});
|
|
128
|
+
var DevWebControl = class {
|
|
129
|
+
current = null;
|
|
130
|
+
closed = false;
|
|
131
|
+
constructor(child, generation) {
|
|
132
|
+
this.child = child;
|
|
133
|
+
this.generation = generation;
|
|
134
|
+
}
|
|
135
|
+
get target() {
|
|
136
|
+
return this.current;
|
|
137
|
+
}
|
|
138
|
+
accept(child, message) {
|
|
139
|
+
const parsed = DevWebReadySchema.safeParse(message);
|
|
140
|
+
if (this.closed || child !== this.child || !parsed.success || parsed.data.generation !== this.generation) return false;
|
|
141
|
+
const { type: _type, ...target } = parsed.data;
|
|
142
|
+
if (this.current && this.current.port !== target.port) return false;
|
|
143
|
+
this.current = target;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
close() {
|
|
147
|
+
this.closed = true;
|
|
148
|
+
this.current = null;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/dev-web/managed.ts
|
|
153
|
+
function managedWebFiles(serverRoot, target) {
|
|
154
|
+
const webRoot = realpathSync(path.resolve(serverRoot, "../../apps/web"));
|
|
155
|
+
return {
|
|
156
|
+
webRoot,
|
|
157
|
+
roots: [...webRoots(webRoot), realpathSync(devWebCache(target.generation))]
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function receiveDevWebTarget(timeoutMs = 25e3, signal) {
|
|
161
|
+
if (!process.send) return Promise.reject(/* @__PURE__ */ new Error("开发转发需要受管控制通道"));
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
const timer = setTimeout(() => finish(/* @__PURE__ */ new Error("开发控制通道超时")), timeoutMs);
|
|
164
|
+
const disconnect = () => finish(/* @__PURE__ */ new Error("开发控制通道已关闭"));
|
|
165
|
+
const abort = () => finish(/* @__PURE__ */ new Error("启动已取消"));
|
|
166
|
+
const message = (value) => {
|
|
167
|
+
const parsed = DevWebAttachSchema.safeParse(value);
|
|
168
|
+
if (!parsed.success) {
|
|
169
|
+
finish(/* @__PURE__ */ new Error("开发控制消息无效"));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const { type: _type, ...target } = parsed.data;
|
|
173
|
+
finish(null, target);
|
|
174
|
+
};
|
|
175
|
+
const finish = (error, target) => {
|
|
176
|
+
clearTimeout(timer);
|
|
177
|
+
process.off("message", message);
|
|
178
|
+
process.off("disconnect", disconnect);
|
|
179
|
+
signal?.removeEventListener("abort", abort);
|
|
180
|
+
if (error) reject(error);
|
|
181
|
+
else if (target) resolve(target);
|
|
182
|
+
};
|
|
183
|
+
process.once("message", message);
|
|
184
|
+
process.once("disconnect", disconnect);
|
|
185
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
186
|
+
if (signal?.aborted) abort();
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function waitChildMessage(child, parse, signal, phase = "Server") {
|
|
190
|
+
return new Promise((resolve, reject) => {
|
|
191
|
+
const timer = setTimeout(() => finish(/* @__PURE__ */ new Error("开发子进程就绪超时")), 25e3);
|
|
192
|
+
const fail = () => finish(/* @__PURE__ */ new Error(`${phase} 未就绪即退出 (code=${child.exitCode ?? "none"}, signal=${child.signalCode ?? "none"})`));
|
|
193
|
+
const abort = () => finish(/* @__PURE__ */ new Error("启动已取消"));
|
|
194
|
+
const message = (value) => {
|
|
195
|
+
const parsed = parse(value);
|
|
196
|
+
if (parsed === null) finish(/* @__PURE__ */ new Error("开发子进程控制消息无效"));
|
|
197
|
+
else finish(null, parsed);
|
|
198
|
+
};
|
|
199
|
+
const finish = (error, value) => {
|
|
200
|
+
clearTimeout(timer);
|
|
201
|
+
child.off("message", message);
|
|
202
|
+
child.off("exit", fail);
|
|
203
|
+
child.off("error", fail);
|
|
204
|
+
signal?.removeEventListener("abort", abort);
|
|
205
|
+
if (error) reject(error);
|
|
206
|
+
else if (value !== void 0) resolve(value);
|
|
207
|
+
};
|
|
208
|
+
child.on("message", message);
|
|
209
|
+
child.once("exit", fail);
|
|
210
|
+
child.once("error", fail);
|
|
211
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
212
|
+
if (signal?.aborted) abort();
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
export { formatPairingCode as _, DevWebControl as a, normalizePairingCode as b, EntryConfigError as c, devWebCache as d, isDevPath as f, PAIRING_REQUEST_TTL_MS as g, PAIRING_CODE_TTL_MS as h, DevWebAttachedSchema as i, HMR_PATH as l, ENROLLMENT_TTL_MS as m, receiveDevWebTarget as n, DevWebTargetSchema as o, permittedPath as p, waitChildMessage as r, DevWebUnavailable as s, managedWebFiles as t, NONCE_MARKER as u, generatePairingCode as v, generateShortCode as y };
|