@air-jam/server 0.9.1 → 0.9.3
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/bin/air-jam-server.mjs +43 -20
- package/dist/.tsbuildinfo +1 -1
- package/dist/chunk-AYTGY3H3.js +67 -0
- package/dist/chunk-AYTGY3H3.js.map +1 -0
- package/dist/{chunk-5ZVGSYXC.js → chunk-LWVOQ5PH.js} +50 -44
- package/dist/chunk-LWVOQ5PH.js.map +1 -0
- package/dist/chunk-PSWSCMDN.js +48 -0
- package/dist/chunk-PSWSCMDN.js.map +1 -0
- package/dist/cli.js +29 -112
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +465 -0
- package/dist/index.js +1086 -1879
- package/dist/index.js.map +1 -1
- package/dist/process-lifecycle-M4XOAN4Q.js +8 -0
- package/package.json +41 -26
- package/dist/chunk-5ZVGSYXC.js.map +0 -1
- package/dist/chunk-RM7AMBDY.js +0 -831
- package/dist/chunk-RM7AMBDY.js.map +0 -1
- package/dist/game-dev-D3TEAHOD.js +0 -422
- package/dist/game-dev-D3TEAHOD.js.map +0 -1
- package/dist/local-dev-state-QT7H5GUA.js +0 -270
- package/dist/local-dev-state-QT7H5GUA.js.map +0 -1
- package/dist/secure-dev-HMOGLYVC.js +0 -39
- package/dist/topology-PM3PI753.js +0 -140
- package/dist/topology-PM3PI753.js.map +0 -1
- package/src/project-cli/vite-config.d.mts +0 -17
- package/src/project-cli/vite-config.mjs +0 -121
- package/src/project-cli/vite-https.d.mts +0 -14
- package/src/project-cli/vite-https.mjs +0 -39
- /package/dist/{secure-dev-HMOGLYVC.js.map → process-lifecycle-M4XOAN4Q.js.map} +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createServerLogger
|
|
3
|
+
} from "./chunk-PSWSCMDN.js";
|
|
4
|
+
|
|
5
|
+
// src/process-lifecycle.ts
|
|
6
|
+
var installServerProcessSignalHandlers = ({
|
|
7
|
+
runtime,
|
|
8
|
+
logger = createServerLogger({
|
|
9
|
+
service: "air-jam-server",
|
|
10
|
+
component: "process-lifecycle"
|
|
11
|
+
})
|
|
12
|
+
}) => {
|
|
13
|
+
let shutdownPromise = null;
|
|
14
|
+
let unsubscribeTerminalFailure = null;
|
|
15
|
+
const removeHandlers = () => {
|
|
16
|
+
process.off("SIGINT", handleSignal);
|
|
17
|
+
process.off("SIGTERM", handleSignal);
|
|
18
|
+
unsubscribeTerminalFailure?.();
|
|
19
|
+
unsubscribeTerminalFailure = null;
|
|
20
|
+
};
|
|
21
|
+
const shutdown = ({
|
|
22
|
+
signal,
|
|
23
|
+
failureMessage
|
|
24
|
+
}) => {
|
|
25
|
+
if (shutdownPromise) return;
|
|
26
|
+
if (failureMessage) process.exitCode = 1;
|
|
27
|
+
removeHandlers();
|
|
28
|
+
shutdownPromise = (async () => {
|
|
29
|
+
logger.info(
|
|
30
|
+
{ signal, failureMessage },
|
|
31
|
+
failureMessage ? "Realtime authority failed; server started bounded drain" : "Realtime server started graceful drain"
|
|
32
|
+
);
|
|
33
|
+
const result = await runtime.drain();
|
|
34
|
+
logger.info(
|
|
35
|
+
{ signal, failureMessage, ...result },
|
|
36
|
+
result.completed ? "Realtime server drain completed" : "Realtime server drain reached its bounded timeout"
|
|
37
|
+
);
|
|
38
|
+
await runtime.stop();
|
|
39
|
+
})().catch(async (error) => {
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
logger.error(
|
|
42
|
+
{ err: error, signal, failureMessage },
|
|
43
|
+
"Realtime server shutdown failed"
|
|
44
|
+
);
|
|
45
|
+
try {
|
|
46
|
+
await runtime.stop();
|
|
47
|
+
} catch (stopError) {
|
|
48
|
+
logger.error(
|
|
49
|
+
{ err: stopError, signal },
|
|
50
|
+
"Realtime server forced cleanup failed"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const handleSignal = (signal) => shutdown({ signal });
|
|
56
|
+
process.once("SIGINT", handleSignal);
|
|
57
|
+
process.once("SIGTERM", handleSignal);
|
|
58
|
+
unsubscribeTerminalFailure = runtime.onTerminalFailure((failure) => {
|
|
59
|
+
shutdown({ failureMessage: failure.message });
|
|
60
|
+
});
|
|
61
|
+
return removeHandlers;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
installServerProcessSignalHandlers
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=chunk-AYTGY3H3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/process-lifecycle.ts"],"sourcesContent":["import type { AirJamServerRuntime } from \"./index.js\";\nimport { createServerLogger, type ServerLogger } from \"./logging/logger.js\";\n\ntype ShutdownSignal = \"SIGINT\" | \"SIGTERM\";\n\nexport const installServerProcessSignalHandlers = ({\n runtime,\n logger = createServerLogger({\n service: \"air-jam-server\",\n component: \"process-lifecycle\",\n }),\n}: {\n runtime: AirJamServerRuntime;\n logger?: ServerLogger;\n}): (() => void) => {\n let shutdownPromise: Promise<void> | null = null;\n let unsubscribeTerminalFailure: (() => void) | null = null;\n\n const removeHandlers = (): void => {\n process.off(\"SIGINT\", handleSignal);\n process.off(\"SIGTERM\", handleSignal);\n unsubscribeTerminalFailure?.();\n unsubscribeTerminalFailure = null;\n };\n\n const shutdown = ({\n signal,\n failureMessage,\n }: {\n signal?: ShutdownSignal;\n failureMessage?: string;\n }): void => {\n if (shutdownPromise) return;\n if (failureMessage) process.exitCode = 1;\n removeHandlers();\n shutdownPromise = (async () => {\n logger.info(\n { signal, failureMessage },\n failureMessage\n ? \"Realtime authority failed; server started bounded drain\"\n : \"Realtime server started graceful drain\",\n );\n const result = await runtime.drain();\n logger.info(\n { signal, failureMessage, ...result },\n result.completed\n ? \"Realtime server drain completed\"\n : \"Realtime server drain reached its bounded timeout\",\n );\n await runtime.stop();\n })().catch(async (error) => {\n process.exitCode = 1;\n logger.error(\n { err: error, signal, failureMessage },\n \"Realtime server shutdown failed\",\n );\n try {\n await runtime.stop();\n } catch (stopError) {\n logger.error(\n { err: stopError, signal },\n \"Realtime server forced cleanup failed\",\n );\n }\n });\n };\n\n const handleSignal = (signal: ShutdownSignal): void => shutdown({ signal });\n\n process.once(\"SIGINT\", handleSignal);\n process.once(\"SIGTERM\", handleSignal);\n unsubscribeTerminalFailure = runtime.onTerminalFailure((failure) => {\n shutdown({ failureMessage: failure.message });\n });\n return removeHandlers;\n};\n"],"mappings":";;;;;AAKO,IAAM,qCAAqC,CAAC;AAAA,EACjD;AAAA,EACA,SAAS,mBAAmB;AAAA,IAC1B,SAAS;AAAA,IACT,WAAW;AAAA,EACb,CAAC;AACH,MAGoB;AAClB,MAAI,kBAAwC;AAC5C,MAAI,6BAAkD;AAEtD,QAAM,iBAAiB,MAAY;AACjC,YAAQ,IAAI,UAAU,YAAY;AAClC,YAAQ,IAAI,WAAW,YAAY;AACnC,iCAA6B;AAC7B,iCAA6B;AAAA,EAC/B;AAEA,QAAM,WAAW,CAAC;AAAA,IAChB;AAAA,IACA;AAAA,EACF,MAGY;AACV,QAAI,gBAAiB;AACrB,QAAI,eAAgB,SAAQ,WAAW;AACvC,mBAAe;AACf,uBAAmB,YAAY;AAC7B,aAAO;AAAA,QACL,EAAE,QAAQ,eAAe;AAAA,QACzB,iBACI,4DACA;AAAA,MACN;AACA,YAAM,SAAS,MAAM,QAAQ,MAAM;AACnC,aAAO;AAAA,QACL,EAAE,QAAQ,gBAAgB,GAAG,OAAO;AAAA,QACpC,OAAO,YACH,oCACA;AAAA,MACN;AACA,YAAM,QAAQ,KAAK;AAAA,IACrB,GAAG,EAAE,MAAM,OAAO,UAAU;AAC1B,cAAQ,WAAW;AACnB,aAAO;AAAA,QACL,EAAE,KAAK,OAAO,QAAQ,eAAe;AAAA,QACrC;AAAA,MACF;AACA,UAAI;AACF,cAAM,QAAQ,KAAK;AAAA,MACrB,SAAS,WAAW;AAClB,eAAO;AAAA,UACL,EAAE,KAAK,WAAW,OAAO;AAAA,UACzB;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,eAAe,CAAC,WAAiC,SAAS,EAAE,OAAO,CAAC;AAE1E,UAAQ,KAAK,UAAU,YAAY;AACnC,UAAQ,KAAK,WAAW,YAAY;AACpC,+BAA6B,QAAQ,kBAAkB,CAAC,YAAY;AAClE,aAAS,EAAE,gBAAgB,QAAQ,QAAQ,CAAC;AAAA,EAC9C,CAAC;AACD,SAAO;AACT;","names":[]}
|
|
@@ -142,53 +142,60 @@ var formatEnvValidationError = (error, { color, includeReceived = true, docsHint
|
|
|
142
142
|
return lines.join("\n");
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
-
// src/
|
|
146
|
-
import
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
} from "
|
|
150
|
-
var
|
|
151
|
-
var
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
{
|
|
166
|
-
stream: {
|
|
167
|
-
write(chunk) {
|
|
168
|
-
const line = typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
169
|
-
devLogCollector.enqueueServerLogLine(line);
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
])
|
|
175
|
-
) : pino(baseLoggerOptions));
|
|
176
|
-
return bindings ? logger.child(bindings) : logger;
|
|
177
|
-
};
|
|
178
|
-
var redactIdentifier = (value) => {
|
|
179
|
-
if (!value) {
|
|
180
|
-
return void 0;
|
|
145
|
+
// src/env/load-workspace-env.ts
|
|
146
|
+
import dotenv from "dotenv";
|
|
147
|
+
import { existsSync } from "fs";
|
|
148
|
+
import { dirname, resolve } from "path";
|
|
149
|
+
import { fileURLToPath } from "url";
|
|
150
|
+
var MODULE_DIR = dirname(fileURLToPath(import.meta.url));
|
|
151
|
+
var SERVER_PACKAGE_ROOT = resolve(MODULE_DIR, "..", "..");
|
|
152
|
+
var WORKSPACE_ROOT = resolve(SERVER_PACKAGE_ROOT, "..", "..");
|
|
153
|
+
var DEFAULT_ENV_CANDIDATES = {
|
|
154
|
+
rootEnvLocal: resolve(WORKSPACE_ROOT, ".env.local"),
|
|
155
|
+
serverEnv: resolve(SERVER_PACKAGE_ROOT, ".env")
|
|
156
|
+
};
|
|
157
|
+
var loadedEnvCandidates = /* @__PURE__ */ new Set();
|
|
158
|
+
var resolveWorkspaceEnvCandidatePaths = ({
|
|
159
|
+
cwd,
|
|
160
|
+
candidates = DEFAULT_ENV_CANDIDATES
|
|
161
|
+
} = {}) => {
|
|
162
|
+
const resolvedPaths = [];
|
|
163
|
+
if (cwd) {
|
|
164
|
+
resolvedPaths.push(resolve(cwd, ".env.local"));
|
|
181
165
|
}
|
|
182
|
-
|
|
183
|
-
|
|
166
|
+
resolvedPaths.push(candidates.rootEnvLocal, candidates.serverEnv);
|
|
167
|
+
return [...new Set(resolvedPaths)];
|
|
168
|
+
};
|
|
169
|
+
var loadWorkspaceEnv = ({
|
|
170
|
+
processEnv = process.env,
|
|
171
|
+
candidates = DEFAULT_ENV_CANDIDATES,
|
|
172
|
+
cwd = process.cwd()
|
|
173
|
+
} = {}) => {
|
|
174
|
+
for (const candidate of resolveWorkspaceEnvCandidatePaths({
|
|
175
|
+
cwd,
|
|
176
|
+
candidates
|
|
177
|
+
})) {
|
|
178
|
+
if (loadedEnvCandidates.has(candidate)) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (!existsSync(candidate)) {
|
|
182
|
+
loadedEnvCandidates.add(candidate);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
dotenv.config({
|
|
186
|
+
path: candidate,
|
|
187
|
+
override: false,
|
|
188
|
+
quiet: true,
|
|
189
|
+
processEnv
|
|
190
|
+
});
|
|
191
|
+
loadedEnvCandidates.add(candidate);
|
|
184
192
|
}
|
|
185
|
-
return `${value.slice(0, 10)}...${value.slice(-4)}`;
|
|
186
193
|
};
|
|
187
194
|
|
|
188
195
|
// src/logging/log-paths.ts
|
|
189
196
|
import fs from "fs";
|
|
190
197
|
import path from "path";
|
|
191
|
-
import { fileURLToPath } from "url";
|
|
198
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
192
199
|
var readPackageName = (cwd) => {
|
|
193
200
|
const packageJsonPath = path.join(cwd, "package.json");
|
|
194
201
|
if (!fs.existsSync(packageJsonPath)) {
|
|
@@ -231,7 +238,7 @@ var resolveAirJamLogProjectRoot = (options) => {
|
|
|
231
238
|
return workspaceRoot;
|
|
232
239
|
}
|
|
233
240
|
const moduleUrl = options?.moduleUrl ?? import.meta.url;
|
|
234
|
-
const thisFilePath =
|
|
241
|
+
const thisFilePath = fileURLToPath2(moduleUrl);
|
|
235
242
|
const loggingDir = path.dirname(thisFilePath);
|
|
236
243
|
return path.resolve(loggingDir, "../../../../");
|
|
237
244
|
};
|
|
@@ -244,9 +251,8 @@ export {
|
|
|
244
251
|
isEnvValidationError,
|
|
245
252
|
validateEnv,
|
|
246
253
|
formatEnvValidationError,
|
|
247
|
-
|
|
248
|
-
redactIdentifier,
|
|
254
|
+
loadWorkspaceEnv,
|
|
249
255
|
AIR_JAM_WORKSPACE_ROOT,
|
|
250
256
|
resolveDefaultDevLogDir
|
|
251
257
|
};
|
|
252
|
-
//# sourceMappingURL=chunk-
|
|
258
|
+
//# sourceMappingURL=chunk-LWVOQ5PH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../env/index.mjs","../src/env/load-workspace-env.ts","../src/logging/log-paths.ts"],"sourcesContent":["const ANSI = {\n reset: \"\\u001b[0m\",\n bold: \"\\u001b[1m\",\n red: \"\\u001b[31m\",\n yellow: \"\\u001b[33m\",\n cyan: \"\\u001b[36m\",\n dim: \"\\u001b[2m\",\n};\n\nconst DEFAULT_FOOTER_HINT = \"Set the required environment variables and retry.\";\n\nconst resolveColorEnabled = (forced) => {\n if (typeof forced === \"boolean\") {\n return forced;\n }\n\n if (typeof process === \"undefined\") {\n return false;\n }\n\n if (typeof process.env?.NO_COLOR !== \"undefined\") {\n return false;\n }\n\n return Boolean(process.stderr?.isTTY);\n};\n\nconst paint = (enabled, tone, value) => {\n if (!enabled) {\n return value;\n }\n\n return `${ANSI[tone]}${value}${ANSI.reset}`;\n};\n\nconst toEnvKey = (path) => {\n if (!Array.isArray(path) || path.length === 0) {\n return \"<root>\";\n }\n\n const firstStringSegment = path.find(\n (segment) => typeof segment === \"string\",\n );\n return typeof firstStringSegment === \"string\" ? firstStringSegment : \"<root>\";\n};\n\nconst describeExpectedRule = (issue) => {\n switch (issue.code) {\n case \"invalid_type\":\n return `type ${String(issue.expected)}`;\n case \"invalid_value\":\n return issue.values && issue.values.length > 0\n ? `one of: ${issue.values.join(\", \")}`\n : \"a valid value\";\n case \"too_small\":\n return issue.minimum != null\n ? `at least ${issue.minimum}${issue.inclusive === false ? \" (exclusive)\" : \"\"}`\n : \"a larger value\";\n case \"too_big\":\n return issue.maximum != null\n ? `at most ${issue.maximum}${issue.inclusive === false ? \" (exclusive)\" : \"\"}`\n : \"a smaller value\";\n case \"invalid_format\":\n return issue.format ? `format ${issue.format}` : \"a valid format\";\n default:\n return \"a valid value\";\n }\n};\n\nconst toReceivedValue = (env, envKey) => {\n if (!env || envKey === \"<root>\") {\n return undefined;\n }\n\n const value = env[envKey];\n if (typeof value === \"undefined\") {\n return undefined;\n }\n\n return String(value);\n};\n\nconst normalizeIssues = ({ zodIssues, env, keyHints }) =>\n zodIssues\n .map((issue) => {\n const envKey = toEnvKey(issue.path);\n return {\n envKey,\n expected: describeExpectedRule(issue),\n received: toReceivedValue(env, envKey),\n message: issue.message,\n fix:\n keyHints?.[envKey] ??\n (envKey === \"<root>\"\n ? \"Adjust the environment values so the schema constraints pass.\"\n : `Set ${envKey} to a valid value.`),\n };\n })\n .sort((a, b) => {\n if (a.envKey === b.envKey) {\n return a.message.localeCompare(b.message);\n }\n\n return a.envKey.localeCompare(b.envKey);\n });\n\nexport class EnvValidationError extends Error {\n constructor({ boundary, issues, docsHint }) {\n const count = issues.length;\n super(\n `${boundary}: invalid environment configuration (${count} issue${count === 1 ? \"\" : \"s\"})`,\n );\n\n this.name = \"EnvValidationError\";\n this.boundary = boundary;\n this.issues = issues;\n this.docsHint = docsHint;\n }\n}\n\nexport const isEnvValidationError = (error) =>\n error instanceof EnvValidationError;\n\nexport const validateEnv = ({\n boundary,\n schema,\n env = process.env,\n docsHint,\n keyHints,\n}) => {\n const result = schema.safeParse(env);\n if (result.success) {\n return result.data;\n }\n\n throw new EnvValidationError({\n boundary,\n docsHint,\n issues: normalizeIssues({\n zodIssues: result.error.issues,\n env,\n keyHints,\n }),\n });\n};\n\nexport const formatEnvValidationError = (\n error,\n { color, includeReceived = true, docsHint } = {},\n) => {\n if (!isEnvValidationError(error)) {\n return String(error);\n }\n\n const colorEnabled = resolveColorEnabled(color);\n const heading = `✖ ${error.boundary}: invalid environment configuration`;\n\n const lines = [\n paint(colorEnabled, \"red\", paint(colorEnabled, \"bold\", heading)),\n ];\n\n for (const [index, issue] of error.issues.entries()) {\n lines.push(\n `${paint(colorEnabled, \"yellow\", `${index + 1}. ${issue.envKey}`)} ${paint(colorEnabled, \"dim\", `(${issue.message})`)}`,\n );\n lines.push(` expected: ${issue.expected}`);\n\n if (includeReceived) {\n lines.push(\n ` received: ${\n typeof issue.received === \"string\" && issue.received.length > 0\n ? `\"${issue.received}\"`\n : \"<missing>\"\n }`,\n );\n }\n\n lines.push(` fix: ${issue.fix}`);\n }\n\n lines.push(\"\");\n lines.push(\n paint(\n colorEnabled,\n \"cyan\",\n `Next: ${docsHint ?? error.docsHint ?? DEFAULT_FOOTER_HINT}`,\n ),\n );\n\n return lines.join(\"\\n\");\n};\n","import dotenv from \"dotenv\";\nimport { existsSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst MODULE_DIR = dirname(fileURLToPath(import.meta.url));\nconst SERVER_PACKAGE_ROOT = resolve(MODULE_DIR, \"..\", \"..\");\nconst WORKSPACE_ROOT = resolve(SERVER_PACKAGE_ROOT, \"..\", \"..\");\n\nexport interface WorkspaceEnvCandidates {\n rootEnvLocal: string;\n serverEnv: string;\n}\n\nexport interface LoadWorkspaceEnvOptions {\n processEnv?: Record<string, string | undefined>;\n candidates?: WorkspaceEnvCandidates;\n cwd?: string;\n}\n\nconst DEFAULT_ENV_CANDIDATES: WorkspaceEnvCandidates = {\n rootEnvLocal: resolve(WORKSPACE_ROOT, \".env.local\"),\n serverEnv: resolve(SERVER_PACKAGE_ROOT, \".env\"),\n};\n\nconst loadedEnvCandidates = new Set<string>();\n\nexport const resolveWorkspaceEnvCandidatePaths = ({\n cwd,\n candidates = DEFAULT_ENV_CANDIDATES,\n}: Pick<LoadWorkspaceEnvOptions, \"candidates\" | \"cwd\"> = {}) => {\n const resolvedPaths = [];\n\n if (cwd) {\n resolvedPaths.push(resolve(cwd, \".env.local\"));\n }\n\n resolvedPaths.push(candidates.rootEnvLocal, candidates.serverEnv);\n\n return [...new Set(resolvedPaths)];\n};\n\nexport const loadWorkspaceEnv = ({\n processEnv = process.env,\n candidates = DEFAULT_ENV_CANDIDATES,\n cwd = process.cwd(),\n}: LoadWorkspaceEnvOptions = {}): void => {\n for (const candidate of resolveWorkspaceEnvCandidatePaths({\n cwd,\n candidates,\n })) {\n if (loadedEnvCandidates.has(candidate)) {\n continue;\n }\n\n if (!existsSync(candidate)) {\n loadedEnvCandidates.add(candidate);\n continue;\n }\n\n dotenv.config({\n path: candidate,\n override: false,\n quiet: true,\n processEnv: processEnv as Record<string, string>,\n });\n loadedEnvCandidates.add(candidate);\n }\n};\n\nexport const resetWorkspaceEnvLoaderForTests = (): void => {\n loadedEnvCandidates.clear();\n};\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst readPackageName = (cwd: string): string | null => {\n const packageJsonPath = path.join(cwd, \"package.json\");\n if (!fs.existsSync(packageJsonPath)) {\n return null;\n }\n\n try {\n const packageJson = JSON.parse(\n fs.readFileSync(packageJsonPath, \"utf8\"),\n ) as {\n name?: string;\n };\n return typeof packageJson.name === \"string\" ? packageJson.name : null;\n } catch {\n return null;\n }\n};\n\nconst findWorkspaceRootFromCwd = (cwd: string): string | null => {\n let currentDir = cwd;\n\n while (true) {\n if (fs.existsSync(path.join(currentDir, \"pnpm-workspace.yaml\"))) {\n return currentDir;\n }\n\n const packageName = readPackageName(currentDir);\n if (packageName === \"air-jam\") {\n return currentDir;\n }\n\n const parentDir = path.dirname(currentDir);\n if (parentDir === currentDir) {\n return null;\n }\n currentDir = parentDir;\n }\n};\n\nexport const resolveAirJamLogProjectRoot = (options?: {\n cwd?: string;\n moduleUrl?: string;\n}): string => {\n const cwd = options?.cwd ?? process.cwd();\n const cwdPackageName = readPackageName(cwd);\n\n if (cwdPackageName && cwdPackageName !== \"@air-jam/server\") {\n return cwd;\n }\n\n const workspaceRoot = findWorkspaceRootFromCwd(cwd);\n if (workspaceRoot) {\n return workspaceRoot;\n }\n\n const moduleUrl = options?.moduleUrl ?? import.meta.url;\n const thisFilePath = fileURLToPath(moduleUrl);\n const loggingDir = path.dirname(thisFilePath);\n return path.resolve(loggingDir, \"../../../../\");\n};\n\nexport const AIR_JAM_WORKSPACE_ROOT = resolveAirJamLogProjectRoot();\n\nexport const resolveDefaultDevLogDir = (): string => {\n return path.join(AIR_JAM_WORKSPACE_ROOT, \".airjam\", \"logs\");\n};\n"],"mappings":";AAAA,IAAM,OAAO;AAAA,EACX,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,KAAK;AACP;AAEA,IAAM,sBAAsB;AAE5B,IAAM,sBAAsB,CAAC,WAAW;AACtC,MAAI,OAAO,WAAW,WAAW;AAC/B,WAAO;A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O,OAAO,YAAY,SAAS,WAAW,YAAY,OAAO;AAAA,EACnE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,IAAM,2BAA2B,CAAC,QAA+B;AAC/D,MAAI,aAAa;AAEjB,SAAO,MAAM;AACX,QAAI,GAAG,WAAW,KAAK,KAAK,YAAY,qBAAqB,CAAC,GAAG;AAC/D,aAAO;AAAA,IACT;AAEA,UAAM,cAAc,gBAAgB,UAAU;AAC9C,QAAI,gBAAgB,WAAW;AAC7B,aAAO;AAAA,IACT;AAEA,UAAM,YAAY,KAAK,QAAQ,UAAU;AACzC,QAAI,cAAc,YAAY;AAC5B,aAAO;AAAA,IACT;AACA,iBAAa;AAAA,EACf;AACF;AAEO,IAAM,8BAA8B,CAAC,YAG9B;AACZ,QAAM,MAAM,SAAS,OAAO,QAAQ,IAAI;AACxC,QAAM,iBAAiB,gBAAgB,GAAG;AAE1C,MAAI,kBAAkB,mBAAmB,mBAAmB;AAC1D,WAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,yBAAyB,GAAG;AAClD,MAAI,eAAe;AACjB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,SAAS,aAAa,YAAY;AACpD,QAAM,eAAeA,eAAc,SAAS;AAC5C,QAAM,aAAa,KAAK,QAAQ,YAAY;AAC5C,SAAO,KAAK,QAAQ,YAAY,cAAc;AAChD;AAEO,IAAM,yBAAyB,4BAA4B;AAE3D,IAAM,0BAA0B,MAAc;AACnD,SAAO,KAAK,KAAK,wBAAwB,WAAW,MAAM;AAC5D;","names":["path","fileURLToPath"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/logging/logger.ts
|
|
2
|
+
import pino, {
|
|
3
|
+
destination,
|
|
4
|
+
multistream
|
|
5
|
+
} from "pino";
|
|
6
|
+
var resolveDefaultLogLevel = (configuredLevel) => configuredLevel ?? process.env.AIR_JAM_LOG_LEVEL ?? "info";
|
|
7
|
+
var createBaseLoggerOptions = (configuredLevel) => ({
|
|
8
|
+
level: resolveDefaultLogLevel(configuredLevel),
|
|
9
|
+
base: void 0,
|
|
10
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
11
|
+
formatters: {
|
|
12
|
+
level: (label) => ({ level: label })
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
var createServerLogger = (bindings, parent, devLogCollector, options) => {
|
|
16
|
+
const baseLoggerOptions = createBaseLoggerOptions(options?.level);
|
|
17
|
+
const logger = parent ?? (devLogCollector?.enabled ? pino(
|
|
18
|
+
baseLoggerOptions,
|
|
19
|
+
multistream([
|
|
20
|
+
{ stream: destination(1) },
|
|
21
|
+
{
|
|
22
|
+
stream: {
|
|
23
|
+
write(chunk) {
|
|
24
|
+
const line = typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
25
|
+
devLogCollector.enqueueServerLogLine(line);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
])
|
|
31
|
+
) : pino(baseLoggerOptions));
|
|
32
|
+
return bindings ? logger.child(bindings) : logger;
|
|
33
|
+
};
|
|
34
|
+
var redactIdentifier = (value) => {
|
|
35
|
+
if (!value) {
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
if (value.length <= 12) {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
return `${value.slice(0, 10)}...${value.slice(-4)}`;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
createServerLogger,
|
|
46
|
+
redactIdentifier
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=chunk-PSWSCMDN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logging/logger.ts"],"sourcesContent":["import pino, {\n destination,\n multistream,\n type Bindings,\n type DestinationStream,\n type Logger,\n type LoggerOptions,\n} from \"pino\";\nimport type { DevLogCollector } from \"./dev-log-collector.js\";\n\nexport type ServerLogger = Logger;\n\nconst resolveDefaultLogLevel = (configuredLevel?: string): string =>\n configuredLevel ?? process.env.AIR_JAM_LOG_LEVEL ?? \"info\";\n\nconst createBaseLoggerOptions = (configuredLevel?: string): LoggerOptions => ({\n level: resolveDefaultLogLevel(configuredLevel),\n base: undefined,\n timestamp: pino.stdTimeFunctions.isoTime,\n formatters: {\n level: (label) => ({ level: label }),\n },\n});\n\ninterface CreateServerLoggerOptions {\n level?: string;\n}\n\nexport const createServerLogger = (\n bindings?: Bindings,\n parent?: ServerLogger,\n devLogCollector?: DevLogCollector | null,\n options?: CreateServerLoggerOptions,\n): ServerLogger => {\n const baseLoggerOptions = createBaseLoggerOptions(options?.level);\n const logger =\n parent ??\n (devLogCollector?.enabled\n ? pino(\n baseLoggerOptions,\n multistream([\n { stream: destination(1) },\n {\n stream: {\n write(chunk: string | Uint8Array) {\n const line =\n typeof chunk === \"string\"\n ? chunk\n : Buffer.from(chunk).toString(\"utf8\");\n devLogCollector.enqueueServerLogLine(line);\n return true;\n },\n } satisfies DestinationStream,\n },\n ]),\n )\n : pino(baseLoggerOptions));\n return bindings ? logger.child(bindings) : logger;\n};\n\nexport const redactIdentifier = (value?: string): string | undefined => {\n if (!value) {\n return undefined;\n }\n\n if (value.length <= 12) {\n return value;\n }\n\n return `${value.slice(0, 10)}...${value.slice(-4)}`;\n};\n"],"mappings":";AAAA,OAAO;AAAA,EACL;AAAA,EACA;AAAA,OAKK;AAKP,IAAM,yBAAyB,CAAC,oBAC9B,mBAAmB,QAAQ,IAAI,qBAAqB;AAEtD,IAAM,0BAA0B,CAAC,qBAA6C;AAAA,EAC5E,OAAO,uBAAuB,eAAe;AAAA,EAC7C,MAAM;AAAA,EACN,WAAW,KAAK,iBAAiB;AAAA,EACjC,YAAY;AAAA,IACV,OAAO,CAAC,WAAW,EAAE,OAAO,MAAM;AAAA,EACpC;AACF;AAMO,IAAM,qBAAqB,CAChC,UACA,QACA,iBACA,YACiB;AACjB,QAAM,oBAAoB,wBAAwB,SAAS,KAAK;AAChE,QAAM,SACJ,WACC,iBAAiB,UACd;AAAA,IACE;AAAA,IACA,YAAY;AAAA,MACV,EAAE,QAAQ,YAAY,CAAC,EAAE;AAAA,MACzB;AAAA,QACE,QAAQ;AAAA,UACN,MAAM,OAA4B;AAChC,kBAAM,OACJ,OAAO,UAAU,WACb,QACA,OAAO,KAAK,KAAK,EAAE,SAAS,MAAM;AACxC,4BAAgB,qBAAqB,IAAI;AACzC,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,IACA,KAAK,iBAAiB;AAC5B,SAAO,WAAW,OAAO,MAAM,QAAQ,IAAI;AAC7C;AAEO,IAAM,mBAAmB,CAAC,UAAuC;AACtE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,UAAU,IAAI;AACtB,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,MAAM,MAAM,EAAE,CAAC;AACnD;","names":[]}
|
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
AIR_JAM_WORKSPACE_ROOT,
|
|
4
|
-
createServerLogger,
|
|
5
4
|
formatEnvValidationError,
|
|
6
|
-
isEnvValidationError
|
|
7
|
-
|
|
5
|
+
isEnvValidationError,
|
|
6
|
+
loadWorkspaceEnv
|
|
7
|
+
} from "./chunk-LWVOQ5PH.js";
|
|
8
|
+
import {
|
|
9
|
+
createServerLogger
|
|
10
|
+
} from "./chunk-PSWSCMDN.js";
|
|
8
11
|
|
|
9
12
|
// src/cli.ts
|
|
10
13
|
import { AIRJAM_DEV_LOG_EVENTS } from "@air-jam/sdk/protocol";
|
|
@@ -12,61 +15,12 @@ import { Command as Command2 } from "commander";
|
|
|
12
15
|
import path2 from "path";
|
|
13
16
|
import { pathToFileURL } from "url";
|
|
14
17
|
|
|
15
|
-
// src/env/load-workspace-env.ts
|
|
16
|
-
import dotenv from "dotenv";
|
|
17
|
-
import { existsSync } from "fs";
|
|
18
|
-
import { dirname, resolve } from "path";
|
|
19
|
-
import { fileURLToPath } from "url";
|
|
20
|
-
var MODULE_DIR = dirname(fileURLToPath(import.meta.url));
|
|
21
|
-
var SERVER_PACKAGE_ROOT = resolve(MODULE_DIR, "..", "..");
|
|
22
|
-
var WORKSPACE_ROOT = resolve(SERVER_PACKAGE_ROOT, "..", "..");
|
|
23
|
-
var DEFAULT_ENV_CANDIDATES = {
|
|
24
|
-
rootEnvLocal: resolve(WORKSPACE_ROOT, ".env.local"),
|
|
25
|
-
serverEnv: resolve(SERVER_PACKAGE_ROOT, ".env")
|
|
26
|
-
};
|
|
27
|
-
var loadedEnvCandidates = /* @__PURE__ */ new Set();
|
|
28
|
-
var resolveWorkspaceEnvCandidatePaths = ({
|
|
29
|
-
cwd,
|
|
30
|
-
candidates = DEFAULT_ENV_CANDIDATES
|
|
31
|
-
} = {}) => {
|
|
32
|
-
const resolvedPaths = [];
|
|
33
|
-
if (cwd) {
|
|
34
|
-
resolvedPaths.push(resolve(cwd, ".env.local"));
|
|
35
|
-
}
|
|
36
|
-
resolvedPaths.push(candidates.rootEnvLocal, candidates.serverEnv);
|
|
37
|
-
return [...new Set(resolvedPaths)];
|
|
38
|
-
};
|
|
39
|
-
var loadWorkspaceEnv = ({
|
|
40
|
-
processEnv = process.env,
|
|
41
|
-
candidates = DEFAULT_ENV_CANDIDATES,
|
|
42
|
-
cwd = process.cwd()
|
|
43
|
-
} = {}) => {
|
|
44
|
-
for (const candidate of resolveWorkspaceEnvCandidatePaths({
|
|
45
|
-
cwd,
|
|
46
|
-
candidates
|
|
47
|
-
})) {
|
|
48
|
-
if (loadedEnvCandidates.has(candidate)) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (!existsSync(candidate)) {
|
|
52
|
-
loadedEnvCandidates.add(candidate);
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
dotenv.config({
|
|
56
|
-
path: candidate,
|
|
57
|
-
override: false,
|
|
58
|
-
processEnv
|
|
59
|
-
});
|
|
60
|
-
loadedEnvCandidates.add(candidate);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
18
|
// src/logging/dev-logs-cli.ts
|
|
65
19
|
import {
|
|
66
20
|
resolveAirJamBrowserConsoleCategory
|
|
67
21
|
} from "@air-jam/sdk/protocol";
|
|
68
22
|
import { Command } from "commander";
|
|
69
|
-
import { createReadStream, existsSync
|
|
23
|
+
import { createReadStream, existsSync, statSync, watch } from "fs";
|
|
70
24
|
import path from "path";
|
|
71
25
|
import readline from "readline";
|
|
72
26
|
var LEVEL_PRIORITY = {
|
|
@@ -355,7 +309,7 @@ var readFromOffset = async (filePath, start, options) => {
|
|
|
355
309
|
return stats.size;
|
|
356
310
|
};
|
|
357
311
|
var executeDevLogsCliOptions = async (options) => {
|
|
358
|
-
if (!
|
|
312
|
+
if (!existsSync(options.filePath)) {
|
|
359
313
|
console.error(`Dev log file not found: ${options.filePath}`);
|
|
360
314
|
return 1;
|
|
361
315
|
}
|
|
@@ -370,7 +324,7 @@ Following ${options.filePath}
|
|
|
370
324
|
if (eventType !== "change" && eventType !== "rename") {
|
|
371
325
|
return;
|
|
372
326
|
}
|
|
373
|
-
if (!
|
|
327
|
+
if (!existsSync(options.filePath)) {
|
|
374
328
|
return;
|
|
375
329
|
}
|
|
376
330
|
const currentSize = statSync(options.filePath).size;
|
|
@@ -383,15 +337,32 @@ Following ${options.filePath}
|
|
|
383
337
|
return 0;
|
|
384
338
|
};
|
|
385
339
|
|
|
340
|
+
// src/version.ts
|
|
341
|
+
import fs from "fs";
|
|
342
|
+
var manifest = JSON.parse(
|
|
343
|
+
fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")
|
|
344
|
+
);
|
|
345
|
+
if (typeof manifest.version !== "string" || manifest.version.length === 0) {
|
|
346
|
+
throw new Error("@air-jam/server package version is missing.");
|
|
347
|
+
}
|
|
348
|
+
var AIR_JAM_SERVER_VERSION = manifest.version;
|
|
349
|
+
|
|
386
350
|
// src/cli.ts
|
|
387
351
|
var runServer = async () => {
|
|
352
|
+
let runtime = null;
|
|
388
353
|
try {
|
|
389
354
|
loadWorkspaceEnv();
|
|
390
355
|
const { createAirJamServer } = await import("./index.js");
|
|
391
|
-
const
|
|
356
|
+
const { installServerProcessSignalHandlers } = await import("./process-lifecycle-M4XOAN4Q.js");
|
|
357
|
+
runtime = createAirJamServer();
|
|
392
358
|
await runtime.start();
|
|
359
|
+
installServerProcessSignalHandlers({ runtime });
|
|
393
360
|
return 0;
|
|
394
361
|
} catch (error) {
|
|
362
|
+
try {
|
|
363
|
+
await runtime?.stop();
|
|
364
|
+
} catch {
|
|
365
|
+
}
|
|
395
366
|
if (isEnvValidationError(error)) {
|
|
396
367
|
console.error(
|
|
397
368
|
formatEnvValidationError(error, {
|
|
@@ -414,78 +385,24 @@ var normalizeCliArgv = (argv) => {
|
|
|
414
385
|
}
|
|
415
386
|
return argv;
|
|
416
387
|
};
|
|
417
|
-
var normalizeProjectCliArgv = (argv) => argv.filter((value) => value !== "--");
|
|
418
388
|
var createServerCli = () => {
|
|
419
389
|
const program = new Command2();
|
|
420
|
-
program.name("air-jam-server").description("Air Jam development and production server").action(async () => {
|
|
390
|
+
program.name("air-jam-server").description("Air Jam development and production server").version(AIR_JAM_SERVER_VERSION).action(async () => {
|
|
421
391
|
process.exitCode = await runServer();
|
|
422
392
|
});
|
|
423
393
|
program.command("start").description("Start the Air Jam server").action(async () => {
|
|
424
394
|
process.exitCode = await runServer();
|
|
425
395
|
});
|
|
426
396
|
configureDevLogsCommand(program.command("logs")).action(async (options) => {
|
|
397
|
+
loadWorkspaceEnv();
|
|
427
398
|
process.exitCode = await executeDevLogsCliOptions(
|
|
428
399
|
coerceDevLogsCliOptions(options)
|
|
429
400
|
);
|
|
430
401
|
});
|
|
431
|
-
program.command("status").description("Show local Air Jam dev process and known-port status").option("--dir <path>", "Project directory to inspect").action(async (options) => {
|
|
432
|
-
const { getDevStatus } = await import("./local-dev-state-QT7H5GUA.js");
|
|
433
|
-
const status = await getDevStatus({ cwd: options.dir });
|
|
434
|
-
process.stdout.write(`${JSON.stringify(status, null, 2)}
|
|
435
|
-
`);
|
|
436
|
-
});
|
|
437
|
-
const resetCommand = program.command("reset").description("Reset local Air Jam development state");
|
|
438
|
-
resetCommand.command("local").description(
|
|
439
|
-
"Stop managed dev processes and stale known-port Air Jam local listeners"
|
|
440
|
-
).option("--dir <path>", "Project directory to reset").action(async (options) => {
|
|
441
|
-
const { resetLocalDev } = await import("./local-dev-state-QT7H5GUA.js");
|
|
442
|
-
const result = await resetLocalDev({ cwd: options.dir });
|
|
443
|
-
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
444
|
-
`);
|
|
445
|
-
});
|
|
446
|
-
program.command("dev").description("Run project-local Air Jam game development").argument("[passthrough...]", "Additional runtime flags").allowExcessArguments(true).allowUnknownOption(false).option("--secure", "Start secure local game dev", false).option(
|
|
447
|
-
"--secure-mode <mode>",
|
|
448
|
-
"Secure mode to use when --secure is enabled (local or tunnel)"
|
|
449
|
-
).option(
|
|
450
|
-
"--preview-managed",
|
|
451
|
-
"Advanced/internal: start foreground Vite with a background server",
|
|
452
|
-
false
|
|
453
|
-
).option("--web-only", "Start only the game app", false).option("--server-only", "Start only the local Air Jam server", false).option(
|
|
454
|
-
"--allow-existing-game",
|
|
455
|
-
"Reuse an already-running Vite server on the game port",
|
|
456
|
-
false
|
|
457
|
-
).action(async () => {
|
|
458
|
-
const { runGameDevCli } = await import("./game-dev-D3TEAHOD.js");
|
|
459
|
-
await runGameDevCli({
|
|
460
|
-
argv: normalizeProjectCliArgv(process.argv.slice(3))
|
|
461
|
-
});
|
|
462
|
-
});
|
|
463
|
-
program.command("secure:init").description("Initialize local secure Air Jam game development").argument("[passthrough...]", "Additional runtime flags").allowExcessArguments(true).allowUnknownOption(false).option("--mode <mode>", "Secure mode to configure (local or tunnel)").option("--hostname <hostname>", "Tunnel hostname for secure tunnel mode").option("--tunnel <name>", "Cloudflare tunnel name for secure tunnel mode").action(async () => {
|
|
464
|
-
const { runSecureInitCli } = await import("./secure-dev-HMOGLYVC.js");
|
|
465
|
-
await runSecureInitCli({
|
|
466
|
-
argv: normalizeProjectCliArgv(process.argv.slice(3))
|
|
467
|
-
});
|
|
468
|
-
});
|
|
469
|
-
program.command("topology").description(
|
|
470
|
-
"Print the resolved project runtime topology for the current game"
|
|
471
|
-
).allowUnknownOption(false).requiredOption(
|
|
472
|
-
"--mode <mode>",
|
|
473
|
-
"Topology mode to inspect (standalone-dev, self-hosted-production, hosted-release)"
|
|
474
|
-
).option(
|
|
475
|
-
"--secure",
|
|
476
|
-
"Resolve standalone local topology using trusted local HTTPS",
|
|
477
|
-
false
|
|
478
|
-
).action(async () => {
|
|
479
|
-
const { runProjectTopologyCli } = await import("./topology-PM3PI753.js");
|
|
480
|
-
await runProjectTopologyCli({
|
|
481
|
-
argv: normalizeProjectCliArgv(process.argv.slice(3))
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
402
|
return program;
|
|
485
403
|
};
|
|
486
404
|
var formatCliHelp = () => createServerCli().helpInformation();
|
|
487
405
|
var runServerCli = async () => {
|
|
488
|
-
loadWorkspaceEnv();
|
|
489
406
|
await createServerCli().parseAsync(normalizeCliArgv(process.argv));
|
|
490
407
|
const exitCode = process.exitCode;
|
|
491
408
|
if (typeof exitCode === "number") {
|