overmux 0.0.1 → 0.0.2
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/CHANGELOG.md +16 -0
- package/README.md +7 -0
- package/dist/auth/.vite/manifest.json +11 -0
- package/dist/auth/assets/index-Bx8JhwVi.css +1 -0
- package/dist/auth/assets/index-CHIE7qYj.js +72 -0
- package/dist/auth/index.html +14 -0
- package/dist/bin.js +4504 -7870
- package/dist/bin.js.map +1 -0
- package/dist/docs/000-index.md +21 -0
- package/dist/docs/100-introduction/100-what-is-overmux.md +7 -0
- package/dist/docs/100-introduction/200-how-overmux-works.md +7 -0
- package/dist/docs/100-introduction/300-why-overmux.md +22 -0
- package/dist/docs/200-getting-started/100-install-and-run-overmux.md +51 -0
- package/dist/docs/200-getting-started/200-install-overmux-desktop.md +41 -0
- package/dist/docs/200-getting-started/300-install-overmux-pwa.mdx +92 -0
- package/dist/docs/200-getting-started/400-secure-with-https/100-choose-an-https-setup.md +14 -0
- package/dist/docs/200-getting-started/400-secure-with-https/200-tailscale-serve.md +44 -0
- package/dist/docs/200-getting-started/400-secure-with-https/300-cloudflare-tunnel.md +59 -0
- package/dist/docs/200-getting-started/400-secure-with-https/400-self-hosted-reverse-proxy.md +32 -0
- package/dist/docs/300-fundamentals/100-project-structure.md +3 -0
- package/dist/docs/300-fundamentals/200-configuration.md +3 -0
- package/dist/docs/300-fundamentals/300-theming.md +3 -0
- package/dist/docs/300-fundamentals/400-server.md +3 -0
- package/dist/docs/300-fundamentals/500-client.md +3 -0
- package/dist/docs/300-fundamentals/600-operations.md +3 -0
- package/dist/docs/300-fundamentals/700-resources.md +3 -0
- package/dist/docs/300-fundamentals/800-streams.md +3 -0
- package/dist/docs/300-fundamentals/900-authentication-and-security.md +3 -0
- package/dist/docs/400-reference/100-configuration.md +3 -0
- package/dist/docs/400-reference/200-server-api.md +3 -0
- package/dist/docs/400-reference/300-client-api.md +3 -0
- package/dist/docs/400-reference/400-cli/100-serve.md +33 -0
- package/dist/docs/400-reference/400-cli/200-auth.md +52 -0
- package/dist/docs/400-reference/400-cli/300-call.md +28 -0
- package/dist/docs/400-reference/400-cli/400-check.md +20 -0
- package/dist/docs/400-reference/400-cli/500-ai-context.md +102 -0
- package/dist/docs/400-reference/400-cli/600-docs.md +23 -0
- package/dist/docs/400-reference/400-cli/700-desktop.md +35 -0
- package/dist/docs/500-hosted-pages.md +31 -0
- package/dist/exports/client.d.ts +237 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +1643 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/index-D3_Dpy_T.d.ts +155 -0
- package/dist/exports/index-D3_Dpy_T.d.ts.map +1 -0
- package/dist/exports/index.d.ts +2 -0
- package/dist/exports/index.js +49 -0
- package/dist/exports/index.js.map +1 -0
- package/dist/exports/notifications-kDp16bU_.js +56 -0
- package/dist/exports/notifications-kDp16bU_.js.map +1 -0
- package/dist/exports/server.d.ts +63 -0
- package/dist/exports/server.d.ts.map +1 -0
- package/dist/exports/server.js +1120 -0
- package/dist/exports/server.js.map +1 -0
- package/dist/exports/style.css +368 -0
- package/dist/internal/server/coordinator/server-child.d.ts +1 -0
- package/dist/internal/server/coordinator/server-child.js +3299 -0
- package/dist/internal/server/coordinator/server-child.js.map +1 -0
- package/docs/000-index.md +21 -0
- package/docs/100-introduction/100-what-is-overmux.md +7 -0
- package/docs/100-introduction/200-how-overmux-works.md +7 -0
- package/docs/100-introduction/300-why-overmux.md +22 -0
- package/docs/200-getting-started/100-install-and-run-overmux.md +51 -0
- package/docs/200-getting-started/200-install-overmux-desktop.md +41 -0
- package/docs/200-getting-started/300-install-overmux-pwa.mdx +92 -0
- package/docs/200-getting-started/400-secure-with-https/100-choose-an-https-setup.md +14 -0
- package/docs/200-getting-started/400-secure-with-https/200-tailscale-serve.md +44 -0
- package/docs/200-getting-started/400-secure-with-https/300-cloudflare-tunnel.md +59 -0
- package/docs/200-getting-started/400-secure-with-https/400-self-hosted-reverse-proxy.md +32 -0
- package/docs/300-fundamentals/100-project-structure.md +3 -0
- package/docs/300-fundamentals/200-configuration.md +3 -0
- package/docs/300-fundamentals/300-theming.md +3 -0
- package/docs/300-fundamentals/400-server.md +3 -0
- package/docs/300-fundamentals/500-client.md +3 -0
- package/docs/300-fundamentals/600-operations.md +3 -0
- package/docs/300-fundamentals/700-resources.md +3 -0
- package/docs/300-fundamentals/800-streams.md +3 -0
- package/docs/300-fundamentals/900-authentication-and-security.md +3 -0
- package/docs/400-reference/100-configuration.md +3 -0
- package/docs/400-reference/200-server-api.md +3 -0
- package/docs/400-reference/300-client-api.md +3 -0
- package/docs/400-reference/400-cli/100-serve.md +33 -0
- package/docs/400-reference/400-cli/200-auth.md +52 -0
- package/docs/400-reference/400-cli/300-call.md +28 -0
- package/docs/400-reference/400-cli/400-check.md +20 -0
- package/docs/400-reference/400-cli/500-ai-context.md +102 -0
- package/docs/400-reference/400-cli/600-docs.md +23 -0
- package/docs/400-reference/400-cli/700-desktop.md +35 -0
- package/docs/500-hosted-pages.md +31 -0
- package/package.json +59 -18
- package/src/internal/cli/app.ts +72 -0
- package/src/internal/cli/bin.ts +3 -0
- package/src/internal/cli/commands/ai.ts +44 -0
- package/src/internal/cli/commands/auth.ts +195 -0
- package/src/internal/cli/commands/call.ts +128 -0
- package/src/internal/cli/commands/check.ts +48 -0
- package/src/internal/cli/commands/desktop-installer.ts +446 -0
- package/src/internal/cli/commands/desktop-release.ts +190 -0
- package/src/internal/cli/commands/desktop.ts +47 -0
- package/src/internal/cli/commands/docs.ts +34 -0
- package/src/internal/cli/commands/serve.ts +322 -0
- package/src/internal/cli/environment.ts +54 -0
- package/src/internal/cli/login.ts +46 -0
- package/src/internal/cli/managed-vite.ts +267 -0
- package/src/internal/cli/parse-port.ts +8 -0
- package/src/internal/client/auth/auth-api.ts +53 -0
- package/src/internal/client/auth/auth-shell.css +74 -0
- package/src/internal/client/auth/auth-shell.tsx +167 -0
- package/src/internal/client/auth/entry.tsx +26 -0
- package/src/internal/client/auth/index.html +13 -0
- package/src/internal/client/background-notifications.ts +194 -0
- package/src/internal/client/browser-api.ts +97 -0
- package/src/internal/client/client-definition.ts +184 -0
- package/src/internal/client/commands.tsx +260 -0
- package/src/internal/client/host/browser-log-forwarding.ts +149 -0
- package/src/internal/client/host/hosted-pages/browser-notification-settings.tsx +118 -0
- package/src/internal/client/host/hosted-pages/hosted-page.css +87 -0
- package/src/internal/client/host/hosted-pages/hosted-page.tsx +9 -0
- package/src/internal/client/host/hosted-pages/logout-page.tsx +75 -0
- package/src/internal/client/host/hosted-pages/settings-page.tsx +45 -0
- package/src/internal/client/host/notification-forwarding.ts +22 -0
- package/src/internal/client/host/overmux-host.tsx +200 -0
- package/src/internal/client/host/recovery-screen.css +75 -0
- package/src/internal/client/host/recovery-screen.tsx +17 -0
- package/src/internal/client/host/update-popover.css +82 -0
- package/src/internal/client/host/update-popover.tsx +166 -0
- package/src/internal/client/index.ts +45 -0
- package/src/internal/client/overmux-react.ts +283 -0
- package/src/internal/client/shortcuts.tsx +373 -0
- package/src/internal/client/theme-scope.css +114 -0
- package/src/internal/client/theme-scope.tsx +107 -0
- package/src/internal/client/transport.ts +69 -0
- package/src/internal/client/websocket.ts +441 -0
- package/src/internal/server/auth/auth-http.ts +414 -0
- package/src/internal/server/auth/auth-service.ts +627 -0
- package/src/internal/server/auth/auth-shell-http.ts +90 -0
- package/src/internal/server/auth/instance-control.ts +381 -0
- package/src/internal/server/check-overmux.ts +364 -0
- package/src/internal/server/coordinator/ipc-protocol.ts +44 -0
- package/src/internal/server/coordinator/server-child.ts +108 -0
- package/src/internal/server/coordinator/server-coordinator.ts +262 -0
- package/src/internal/server/coordinator/update-watcher.ts +54 -0
- package/src/internal/server/http/authenticated-http-app-test-helper.ts +45 -0
- package/src/internal/server/http/background-notification-handlers.ts +83 -0
- package/src/internal/server/http/control-handlers.ts +44 -0
- package/src/internal/server/http/create-http-app.ts +53 -0
- package/src/internal/server/http/development-web-backend.ts +83 -0
- package/src/internal/server/http/operation-handler.ts +93 -0
- package/src/internal/server/http/request-logging.ts +34 -0
- package/src/internal/server/http/routes.ts +241 -0
- package/src/internal/server/http/runtime-manifest-handler.ts +12 -0
- package/src/internal/server/index.ts +16 -0
- package/src/internal/server/notifications/background-notification-payload.ts +74 -0
- package/src/internal/server/notifications/background-notification-service.ts +139 -0
- package/src/internal/server/notifications/background-notification-store.ts +162 -0
- package/src/internal/server/notifications/notification-service.ts +70 -0
- package/src/internal/server/notifications/private-json-file.ts +84 -0
- package/src/internal/server/paths.ts +13 -0
- package/src/internal/server/rate-limiter.ts +58 -0
- package/src/internal/server/runtime/create-runtime.ts +87 -0
- package/src/internal/server/runtime/resource-dependency-graph.ts +128 -0
- package/src/internal/server/runtime/runtime-lifecycle.ts +95 -0
- package/src/internal/server/runtime/runtime-operations.ts +78 -0
- package/src/internal/server/runtime/runtime-resources.ts +201 -0
- package/src/internal/server/runtime/runtime-streams.ts +130 -0
- package/src/internal/server/server-logger.ts +110 -0
- package/src/internal/server/server-startup-options.ts +51 -0
- package/src/internal/server/start-application-server.ts +412 -0
- package/src/internal/server/start-overmux-server.ts +26 -0
- package/src/internal/server/test-port.ts +23 -0
- package/src/internal/server/vite-websocket-proxy.ts +201 -0
- package/src/internal/server/websocket-connection.ts +586 -0
- package/src/internal/server/websocket-limits.ts +2 -0
- package/src/internal/server/websocket-server.ts +311 -0
- package/src/internal/shared/background-notifications.ts +37 -0
- package/src/internal/shared/index.ts +2 -0
- package/src/internal/shared/protocol.ts +317 -0
- package/src/internal/shared/routes.ts +3 -0
- package/src/public/ai-context.ts +44 -0
- package/src/public/client.ts +53 -0
- package/src/public/config.ts +287 -0
- package/src/public/contracts.ts +55 -0
- package/src/public/index.ts +57 -0
- package/src/public/notifications.ts +10 -0
- package/src/public/server.ts +16 -0
- package/dist/public/core.ts +0 -119
- package/dist/public/protocol.ts +0 -51
- package/dist/public/terminal.ts +0 -23
- package/dist/web/assets/index-DC___IUw.css +0 -2
- package/dist/web/assets/index-DF9Cptse.js +0 -74
- package/dist/web/assets/terminal-component-BrP-ENHg.css +0 -1
- package/dist/web/assets/terminal-component-DyLEbMrx.js +0 -36
- package/dist/web/index.html +0 -14
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { loadOvermuxConfig } from "@overmux/shared/node";
|
|
2
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import { ZodError } from "zod";
|
|
5
|
+
|
|
6
|
+
import { createRuntime } from "./runtime/create-runtime";
|
|
7
|
+
|
|
8
|
+
export type CheckDiagnostic = {
|
|
9
|
+
code?: number | string;
|
|
10
|
+
column?: number;
|
|
11
|
+
file?: string;
|
|
12
|
+
line?: number;
|
|
13
|
+
message: string;
|
|
14
|
+
path?: string;
|
|
15
|
+
phase: "config" | "imports" | "runtime" | "types" | "ui";
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type CheckResult = {
|
|
19
|
+
operations?: number;
|
|
20
|
+
config: string;
|
|
21
|
+
diagnostics: CheckDiagnostic[];
|
|
22
|
+
files: number;
|
|
23
|
+
ok: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type CheckOvermuxOptions = {
|
|
27
|
+
aliases?: Record<string, string>;
|
|
28
|
+
configPath: string;
|
|
29
|
+
typeAliases?: Record<string, string>;
|
|
30
|
+
typesOnly?: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const loadCompilerOptions = (configPath: string) => {
|
|
34
|
+
const tsconfig = ts.findConfigFile(dirname(configPath), ts.sys.fileExists);
|
|
35
|
+
if (!tsconfig) {
|
|
36
|
+
return {
|
|
37
|
+
allowImportingTsExtensions: true,
|
|
38
|
+
allowJs: false,
|
|
39
|
+
esModuleInterop: true,
|
|
40
|
+
jsx: ts.JsxEmit.ReactJSX,
|
|
41
|
+
module: ts.ModuleKind.ESNext,
|
|
42
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
43
|
+
noEmit: true,
|
|
44
|
+
skipLibCheck: true,
|
|
45
|
+
strict: true,
|
|
46
|
+
target: ts.ScriptTarget.ES2022,
|
|
47
|
+
} satisfies ts.CompilerOptions;
|
|
48
|
+
}
|
|
49
|
+
const loaded = ts.readConfigFile(tsconfig, ts.sys.readFile);
|
|
50
|
+
if (loaded.error) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
ts.flattenDiagnosticMessageText(loaded.error.messageText, "\n"),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
const parsed = ts.parseJsonConfigFileContent(
|
|
56
|
+
loaded.config,
|
|
57
|
+
ts.sys,
|
|
58
|
+
dirname(tsconfig),
|
|
59
|
+
);
|
|
60
|
+
return {
|
|
61
|
+
...parsed.options,
|
|
62
|
+
allowImportingTsExtensions: true,
|
|
63
|
+
noEmit: true,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const diagnosticOf = (diagnostic: ts.Diagnostic): CheckDiagnostic => {
|
|
68
|
+
const position =
|
|
69
|
+
diagnostic.file && diagnostic.start !== undefined
|
|
70
|
+
? diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start)
|
|
71
|
+
: undefined;
|
|
72
|
+
return {
|
|
73
|
+
code: diagnostic.code,
|
|
74
|
+
column: position ? position.character + 1 : undefined,
|
|
75
|
+
file: diagnostic.file?.fileName,
|
|
76
|
+
line: position ? position.line + 1 : undefined,
|
|
77
|
+
message: ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"),
|
|
78
|
+
phase: "types",
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const kindOf = (fileName: string, configPath: string) => {
|
|
83
|
+
if (
|
|
84
|
+
resolve(fileName) === resolve(configPath) ||
|
|
85
|
+
fileName.match(/\.server\.[cm]?[jt]sx?$/)
|
|
86
|
+
) {
|
|
87
|
+
return "server";
|
|
88
|
+
}
|
|
89
|
+
if (fileName.match(/\.ui\.[cm]?[jt]sx?$/)) {
|
|
90
|
+
return "client";
|
|
91
|
+
}
|
|
92
|
+
if (fileName.match(/\.shared\.[cm]?[jt]sx?$/)) {
|
|
93
|
+
return "shared";
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
type ModuleKind = "client" | "server" | "shared";
|
|
99
|
+
|
|
100
|
+
type ResolvedImport = {
|
|
101
|
+
kind?: ModuleKind;
|
|
102
|
+
node: ts.ImportDeclaration | ts.ExportDeclaration;
|
|
103
|
+
source?: ts.SourceFile;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const kindOfSpecifier = (specifier: string): ModuleKind | undefined => {
|
|
107
|
+
if (specifier === "overmux/client" || specifier.endsWith("/react")) {
|
|
108
|
+
return "client";
|
|
109
|
+
}
|
|
110
|
+
if (
|
|
111
|
+
specifier === "overmux/server" ||
|
|
112
|
+
specifier.endsWith("/server") ||
|
|
113
|
+
specifier.startsWith("node:")
|
|
114
|
+
) {
|
|
115
|
+
return "server";
|
|
116
|
+
}
|
|
117
|
+
if (specifier === "overmux" || specifier.endsWith("/shared")) {
|
|
118
|
+
return "shared";
|
|
119
|
+
}
|
|
120
|
+
return undefined;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const isTypeOnlyReference = (
|
|
124
|
+
node: ts.ImportDeclaration | ts.ExportDeclaration,
|
|
125
|
+
) => {
|
|
126
|
+
if (ts.isExportDeclaration(node)) {
|
|
127
|
+
return Boolean(
|
|
128
|
+
node.isTypeOnly ||
|
|
129
|
+
(node.exportClause &&
|
|
130
|
+
ts.isNamedExports(node.exportClause) &&
|
|
131
|
+
node.exportClause.elements.every((element) => element.isTypeOnly)),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const clause = node.importClause;
|
|
135
|
+
if (!clause || clause.name) {
|
|
136
|
+
return Boolean(clause?.isTypeOnly);
|
|
137
|
+
}
|
|
138
|
+
return Boolean(
|
|
139
|
+
clause.isTypeOnly ||
|
|
140
|
+
(clause.namedBindings &&
|
|
141
|
+
ts.isNamedImports(clause.namedBindings) &&
|
|
142
|
+
clause.namedBindings.elements.every((element) => element.isTypeOnly)),
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const resolvedImports = (program: ts.Program, source: ts.SourceFile) => {
|
|
147
|
+
const imports: ResolvedImport[] = [];
|
|
148
|
+
source.forEachChild((node) => {
|
|
149
|
+
if (
|
|
150
|
+
(!ts.isImportDeclaration(node) && !ts.isExportDeclaration(node)) ||
|
|
151
|
+
!node.moduleSpecifier ||
|
|
152
|
+
!ts.isStringLiteral(node.moduleSpecifier) ||
|
|
153
|
+
isTypeOnlyReference(node)
|
|
154
|
+
) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const specifier = node.moduleSpecifier.text;
|
|
158
|
+
const resolved = ts.resolveModuleName(
|
|
159
|
+
specifier,
|
|
160
|
+
source.fileName,
|
|
161
|
+
program.getCompilerOptions(),
|
|
162
|
+
ts.sys,
|
|
163
|
+
).resolvedModule?.resolvedFileName;
|
|
164
|
+
const target = resolved ? program.getSourceFile(resolved) : undefined;
|
|
165
|
+
const kind = kindOfSpecifier(specifier);
|
|
166
|
+
if (kind || (target && !target.isDeclarationFile)) {
|
|
167
|
+
imports.push({
|
|
168
|
+
kind,
|
|
169
|
+
node,
|
|
170
|
+
source: target?.isDeclarationFile ? undefined : target,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return imports;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const invalidImport = (source: ModuleKind, target: ModuleKind | undefined) =>
|
|
178
|
+
(source === "server" && target === "client") ||
|
|
179
|
+
(source === "client" && target === "server") ||
|
|
180
|
+
(source === "shared" && target !== undefined && target !== "shared");
|
|
181
|
+
|
|
182
|
+
const visitImportGraph = ({
|
|
183
|
+
configPath,
|
|
184
|
+
diagnostics,
|
|
185
|
+
kind,
|
|
186
|
+
program,
|
|
187
|
+
seen,
|
|
188
|
+
source,
|
|
189
|
+
}: {
|
|
190
|
+
configPath: string;
|
|
191
|
+
diagnostics: CheckDiagnostic[];
|
|
192
|
+
kind: ModuleKind;
|
|
193
|
+
program: ts.Program;
|
|
194
|
+
seen: Set<string>;
|
|
195
|
+
source: ts.SourceFile;
|
|
196
|
+
}) => {
|
|
197
|
+
const visitKey = `${kind}:${source.fileName}`;
|
|
198
|
+
if (seen.has(visitKey)) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
seen.add(visitKey);
|
|
202
|
+
resolvedImports(program, source).forEach(
|
|
203
|
+
({ kind: importKind, node, source: target }) => {
|
|
204
|
+
const declaredKind =
|
|
205
|
+
importKind ??
|
|
206
|
+
(target ? kindOf(target.fileName, configPath) : undefined);
|
|
207
|
+
if (invalidImport(kind, declaredKind)) {
|
|
208
|
+
const position = source.getLineAndCharacterOfPosition(node.getStart());
|
|
209
|
+
diagnostics.push({
|
|
210
|
+
code: "OVERMUX_IMPORT_BOUNDARY",
|
|
211
|
+
column: position.character + 1,
|
|
212
|
+
file: source.fileName,
|
|
213
|
+
line: position.line + 1,
|
|
214
|
+
message: `${kind} modules may not import ${declaredKind} modules`,
|
|
215
|
+
phase: "imports",
|
|
216
|
+
});
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (target) {
|
|
220
|
+
visitImportGraph({
|
|
221
|
+
configPath,
|
|
222
|
+
diagnostics,
|
|
223
|
+
kind: declaredKind === "shared" ? "shared" : kind,
|
|
224
|
+
program,
|
|
225
|
+
seen,
|
|
226
|
+
source: target,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const importBoundaryDiagnostics = (
|
|
234
|
+
program: ts.Program,
|
|
235
|
+
configPath: string,
|
|
236
|
+
): CheckDiagnostic[] => {
|
|
237
|
+
const diagnostics: CheckDiagnostic[] = [];
|
|
238
|
+
const seen = new Set<string>();
|
|
239
|
+
program.getSourceFiles().forEach((source) => {
|
|
240
|
+
const kind = kindOf(source.fileName, configPath);
|
|
241
|
+
if (kind && !source.isDeclarationFile) {
|
|
242
|
+
visitImportGraph({
|
|
243
|
+
configPath,
|
|
244
|
+
diagnostics,
|
|
245
|
+
kind,
|
|
246
|
+
program,
|
|
247
|
+
seen,
|
|
248
|
+
source,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
return diagnostics;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const runtimeDiagnostics = (cause: unknown): CheckDiagnostic[] => {
|
|
256
|
+
if (cause instanceof ZodError) {
|
|
257
|
+
return cause.issues.map((issue) => ({
|
|
258
|
+
message: issue.message,
|
|
259
|
+
path: issue.path.length ? issue.path.join(".") : undefined,
|
|
260
|
+
phase: "runtime" as const,
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
263
|
+
return [
|
|
264
|
+
{
|
|
265
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
266
|
+
phase: "runtime",
|
|
267
|
+
},
|
|
268
|
+
];
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const typecheck = async ({
|
|
272
|
+
aliases = {},
|
|
273
|
+
configPath,
|
|
274
|
+
typeAliases,
|
|
275
|
+
}: CheckOvermuxOptions) => {
|
|
276
|
+
const options = loadCompilerOptions(configPath);
|
|
277
|
+
const aliasesForTypes =
|
|
278
|
+
typeAliases ??
|
|
279
|
+
Object.fromEntries(
|
|
280
|
+
Object.entries(aliases).filter(
|
|
281
|
+
([key]) => key === "overmux" || key.startsWith("overmux/"),
|
|
282
|
+
),
|
|
283
|
+
);
|
|
284
|
+
const absoluteAliases = Object.fromEntries(
|
|
285
|
+
Object.entries(aliasesForTypes).map(([key, value]) => [
|
|
286
|
+
key,
|
|
287
|
+
[isAbsolute(value) ? value : resolve(value)],
|
|
288
|
+
]),
|
|
289
|
+
);
|
|
290
|
+
const program = ts.createProgram({
|
|
291
|
+
options: {
|
|
292
|
+
...options,
|
|
293
|
+
baseUrl: options.baseUrl ?? "/",
|
|
294
|
+
paths: { ...options.paths, ...absoluteAliases },
|
|
295
|
+
},
|
|
296
|
+
rootNames: [configPath],
|
|
297
|
+
});
|
|
298
|
+
const diagnostics = [
|
|
299
|
+
...ts.getPreEmitDiagnostics(program).map(diagnosticOf),
|
|
300
|
+
...importBoundaryDiagnostics(program, configPath),
|
|
301
|
+
];
|
|
302
|
+
const files = program
|
|
303
|
+
.getSourceFiles()
|
|
304
|
+
.filter(
|
|
305
|
+
(file) =>
|
|
306
|
+
!file.isDeclarationFile && !file.fileName.includes("node_modules"),
|
|
307
|
+
).length;
|
|
308
|
+
return { diagnostics, files };
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
export const checkOvermux = async (
|
|
312
|
+
options: CheckOvermuxOptions,
|
|
313
|
+
): Promise<CheckResult> => {
|
|
314
|
+
const configPath = resolve(options.configPath);
|
|
315
|
+
let checked;
|
|
316
|
+
try {
|
|
317
|
+
checked = await typecheck({ ...options, configPath });
|
|
318
|
+
} catch (cause) {
|
|
319
|
+
return {
|
|
320
|
+
config: configPath,
|
|
321
|
+
diagnostics: [
|
|
322
|
+
{
|
|
323
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
324
|
+
phase: "config",
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
files: 0,
|
|
328
|
+
ok: false,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
if (checked.diagnostics.length || options.typesOnly) {
|
|
332
|
+
return {
|
|
333
|
+
config: configPath,
|
|
334
|
+
diagnostics: checked.diagnostics,
|
|
335
|
+
files: checked.files,
|
|
336
|
+
ok: checked.diagnostics.length === 0,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
let runtime: Awaited<ReturnType<typeof createRuntime>> | undefined;
|
|
341
|
+
try {
|
|
342
|
+
const { config } = await loadOvermuxConfig({
|
|
343
|
+
aliases: options.aliases,
|
|
344
|
+
configPath,
|
|
345
|
+
});
|
|
346
|
+
runtime = await createRuntime({ config });
|
|
347
|
+
return {
|
|
348
|
+
operations: runtime.manifest.operations.length,
|
|
349
|
+
config: configPath,
|
|
350
|
+
diagnostics: [],
|
|
351
|
+
files: checked.files,
|
|
352
|
+
ok: true,
|
|
353
|
+
};
|
|
354
|
+
} catch (cause) {
|
|
355
|
+
return {
|
|
356
|
+
config: configPath,
|
|
357
|
+
diagnostics: runtimeDiagnostics(cause),
|
|
358
|
+
files: checked.files,
|
|
359
|
+
ok: false,
|
|
360
|
+
};
|
|
361
|
+
} finally {
|
|
362
|
+
await runtime?.dispose();
|
|
363
|
+
}
|
|
364
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Defines the complete validated IPC boundary between coordinator and child.
|
|
2
|
+
// Application traffic never crosses this process boundary.
|
|
3
|
+
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
const childOptionsSchema = z.object({
|
|
7
|
+
configAliases: z.record(z.string(), z.string()).optional(),
|
|
8
|
+
configPath: z.string(),
|
|
9
|
+
debug: z.boolean().optional(),
|
|
10
|
+
developmentWebTarget: z.url().optional(),
|
|
11
|
+
host: z.string().optional(),
|
|
12
|
+
logFile: z.string().optional(),
|
|
13
|
+
port: z.number().int().min(0).max(65_535).optional(),
|
|
14
|
+
productionWebAssetsDir: z.string().optional(),
|
|
15
|
+
watch: z.boolean().optional(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const parentMessageSchema = z.discriminatedUnion("type", [
|
|
19
|
+
z.object({ options: childOptionsSchema, type: z.literal("start") }),
|
|
20
|
+
z.object({ type: z.literal("update-available") }),
|
|
21
|
+
z.object({ type: z.literal("stop") }),
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const childMessageSchema = z.discriminatedUnion("type", [
|
|
25
|
+
z.object({
|
|
26
|
+
host: z.string(),
|
|
27
|
+
port: z.number().int().min(1).max(65_535),
|
|
28
|
+
type: z.literal("ready"),
|
|
29
|
+
url: z.string(),
|
|
30
|
+
watch: z.boolean(),
|
|
31
|
+
}),
|
|
32
|
+
z.object({ type: z.literal("restart-requested") }),
|
|
33
|
+
z.object({ message: z.string(), type: z.literal("startup-failed") }),
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
export type ChildServerOptions = z.infer<typeof childOptionsSchema>;
|
|
37
|
+
export type ParentToChildMessage = z.infer<typeof parentMessageSchema>;
|
|
38
|
+
export type ChildToParentMessage = z.infer<typeof childMessageSchema>;
|
|
39
|
+
|
|
40
|
+
export const parseParentMessage = (value: unknown): ParentToChildMessage =>
|
|
41
|
+
parentMessageSchema.parse(value);
|
|
42
|
+
|
|
43
|
+
export const parseChildMessage = (value: unknown): ChildToParentMessage =>
|
|
44
|
+
childMessageSchema.parse(value);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Executable entry for one fresh application-server child process.
|
|
2
|
+
// It translates lifecycle IPC only and never retains state across restarts.
|
|
3
|
+
|
|
4
|
+
import { startApplicationServer } from "../start-application-server";
|
|
5
|
+
import { errorMessage } from "../server-logger";
|
|
6
|
+
import { parseParentMessage, type ChildToParentMessage } from "./ipc-protocol";
|
|
7
|
+
|
|
8
|
+
const send = (message: ChildToParentMessage) => {
|
|
9
|
+
if (!process.connected) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
process.send?.(message, () => undefined);
|
|
14
|
+
} catch {}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const disconnect = () => {
|
|
18
|
+
if (!process.connected) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
process.disconnect();
|
|
23
|
+
} catch {}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const runServerChild = () => {
|
|
27
|
+
let serverPromise: ReturnType<typeof startApplicationServer> | undefined;
|
|
28
|
+
let closing: Promise<void> | undefined;
|
|
29
|
+
|
|
30
|
+
const close = () => {
|
|
31
|
+
if (closing) {
|
|
32
|
+
return closing;
|
|
33
|
+
}
|
|
34
|
+
closing =
|
|
35
|
+
serverPromise?.then(
|
|
36
|
+
(server) => server.close(),
|
|
37
|
+
() => undefined,
|
|
38
|
+
) ?? Promise.resolve();
|
|
39
|
+
return closing;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
process.on("message", (raw) => {
|
|
43
|
+
let message;
|
|
44
|
+
try {
|
|
45
|
+
message = parseParentMessage(raw);
|
|
46
|
+
} catch (cause) {
|
|
47
|
+
send({ message: errorMessage(cause), type: "startup-failed" });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (message.type === "update-available") {
|
|
51
|
+
if (!closing) {
|
|
52
|
+
void serverPromise?.then(
|
|
53
|
+
(server) => server.announceUpdateAvailable(),
|
|
54
|
+
() => undefined,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (message.type === "stop") {
|
|
60
|
+
void close()
|
|
61
|
+
.catch((cause: unknown) => {
|
|
62
|
+
process.stderr.write(
|
|
63
|
+
`[overmux] child shutdown failed: ${errorMessage(cause)}\n`,
|
|
64
|
+
);
|
|
65
|
+
})
|
|
66
|
+
.finally(disconnect);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (serverPromise || closing) {
|
|
70
|
+
send({
|
|
71
|
+
message: "Server child received more than one start request",
|
|
72
|
+
type: "startup-failed",
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
serverPromise = startApplicationServer({
|
|
77
|
+
onRestartRequested: () => send({ type: "restart-requested" }),
|
|
78
|
+
options: message.options,
|
|
79
|
+
});
|
|
80
|
+
void serverPromise
|
|
81
|
+
.then((server) => {
|
|
82
|
+
if (closing) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
send({
|
|
86
|
+
host: server.host,
|
|
87
|
+
port: server.port,
|
|
88
|
+
type: "ready",
|
|
89
|
+
url: server.url,
|
|
90
|
+
watch: server.watch,
|
|
91
|
+
});
|
|
92
|
+
})
|
|
93
|
+
.catch((cause: unknown) => {
|
|
94
|
+
send({ message: errorMessage(cause), type: "startup-failed" });
|
|
95
|
+
disconnect();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
process.once("disconnect", () => {
|
|
100
|
+
void close().catch((cause: unknown) => {
|
|
101
|
+
process.stderr.write(
|
|
102
|
+
`[overmux] disconnected child shutdown failed: ${errorMessage(cause)}\n`,
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
runServerChild();
|