@xrystal/core 3.55.62 → 3.55.63

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.55.62",
4
+ "version": "3.55.63",
5
5
  "description": "Runtime framework and CLI for API services, frontends, and multi-repo workspaces",
6
6
  "publishConfig": {
7
7
  "access": "public",
package/x/bin/main-cli.js CHANGED
@@ -98,7 +98,11 @@ registerTelepresenceCommand(cli, cliContext)
98
98
  registerProjectCommands(cli, cliContext)
99
99
 
100
100
  cli.parseAsync(process.argv).catch((error) => {
101
- console.error(chalk.red(`\n✗ ${error.message}\n`))
101
+ const message = error instanceof Error && error.message ? error.message : 'Command failed.'
102
+ if (error instanceof Error && error.name === 'InfraPreflightFailed') {
103
+ process.exit(1)
104
+ }
105
+ console.error(chalk.red(`\n✗ ${message}\n`))
102
106
  process.exit(1)
103
107
  })
104
108
 
@@ -7,6 +7,7 @@ import { getTmpSnapshot } from '../utils/helpers/tmp/tmp-loader.js';
7
7
  import { isInfraLoaderEnabled, resolveLoaderBootPlan } from '../utils/helpers/tmp/loader-boot-plan.js';
8
8
  import { InfraLoaderEnum } from '../utils/models/enums/index.js';
9
9
  import { resolveTmpRuntimeConfigs } from '../utils/helpers/tmp/tmp-schema.js';
10
+ import { InfraPreflightFailed } from '../utils/helpers/infra-preflight/index.js';
10
11
  export { ensureCoreTmpEntry, isCorePackageRoot } from '../utils/helpers/core/tmp-layout.js';
11
12
  export { getTmpSnapshot } from '../utils/helpers/tmp/tmp-loader.js';
12
13
  export { resolveLoaderBootPlan } from '../utils/helpers/tmp/loader-boot-plan.js';
@@ -52,6 +53,9 @@ const coreLoader = async (_params = {}) => {
52
53
  return core;
53
54
  }
54
55
  catch (error) {
56
+ if (error instanceof InfraPreflightFailed) {
57
+ process.exit(1);
58
+ }
55
59
  const errorMessage = error instanceof Error ? error.message : String(error);
56
60
  console.error(`[${Constants.packageName} core failure]: ${errorMessage}`);
57
61
  throw error;
@@ -22,9 +22,11 @@ type PreflightRow = {
22
22
  export type PreflightReportMeta = {
23
23
  atUtc: string;
24
24
  runtime: string;
25
+ runtimeDetect: string;
25
26
  host: string;
26
27
  namespace?: string;
27
28
  coreVersion: string;
29
+ serviceVersion?: string;
28
30
  probeTimeoutMs: number;
29
31
  tcpProbe: boolean;
30
32
  durationMs: number;
@@ -34,7 +36,11 @@ export declare function buildPreflightReportMeta(options: {
34
36
  tcpProbe: boolean;
35
37
  startedAtMs: number;
36
38
  }): PreflightReportMeta;
37
- /** Strict fail: one report on stderr, exit 1 — no Error stack (avoids duplicate lines + Bun SIGTERM noise in k8s). */
39
+ /** Thrown after report is printed — boot handler exits without extra CLI noise. */
40
+ export declare class InfraPreflightFailed extends Error {
41
+ constructor();
42
+ }
43
+ /** Strict fail: one report on stderr, then InfraPreflightFailed (no duplicate stack). */
38
44
  export declare function abortInfraPreflight(report: string): never;
39
45
  export declare function resolveProbeTimeoutMs(): number;
40
46
  /** Default: fail-fast. Set STRICT_INFRA_PREFLIGHT=0|false|no|off to warn only (local edge cases). */
@@ -1,5 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import net from 'node:net';
3
+ import { createRequire } from 'node:module';
4
+ const require = createRequire(import.meta.url);
3
5
  import { parseRedisUri } from '../../../loader/redis/parse-uri.js';
4
6
  import { InfraLoaderEnum } from '../../../utils/models/enums/index.js';
5
7
  import { isInfraLoaderEnabled, resolveLoaderBootPlan, } from '../../../utils/helpers/tmp/loader-boot-plan.js';
@@ -7,35 +9,62 @@ import { resolveTmpRuntimeConfigs } from '../../../utils/helpers/tmp/tmp-schema.
7
9
  import { getTmpSnapshot } from '../../../utils/helpers/tmp/tmp-loader.js';
8
10
  const DEFAULT_PROBE_TIMEOUT_MS = 500;
9
11
  const RULE = '─'.repeat(72);
12
+ function resolveInstalledCoreVersion() {
13
+ try {
14
+ const pkgPath = require.resolve('@xrystal/core/package.json');
15
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
16
+ return pkg.version?.trim() || 'unknown';
17
+ }
18
+ catch {
19
+ return 'unknown';
20
+ }
21
+ }
10
22
  function resolveRuntimeLabel() {
11
- if (process.env.KUBERNETES_SERVICE_HOST)
12
- return 'kubernetes';
23
+ if (process.env.KUBERNETES_SERVICE_HOST) {
24
+ return {
25
+ label: 'kubernetes',
26
+ detect: 'KUBERNETES_SERVICE_HOST (kubelet-injected)',
27
+ };
28
+ }
13
29
  try {
14
- if (fs.existsSync('/.dockerenv'))
15
- return 'docker';
30
+ if (fs.existsSync('/.dockerenv')) {
31
+ return { label: 'docker', detect: '/.dockerenv' };
32
+ }
16
33
  }
17
34
  catch {
18
35
  /* ignore */
19
36
  }
20
- return 'local';
37
+ return { label: 'local', detect: 'default' };
21
38
  }
22
39
  export function buildPreflightReportMeta(options) {
23
40
  const ns = (process.env.KUBERNETES_NAMESPACE ?? process.env.POD_NAMESPACE ?? '').trim();
41
+ const runtime = resolveRuntimeLabel();
42
+ const svcVer = (process.env.npm_package_version ?? '').trim();
43
+ const svcName = (process.env.npm_package_name ?? '').trim();
24
44
  return {
25
45
  atUtc: new Date().toISOString(),
26
- runtime: resolveRuntimeLabel(),
46
+ runtime: runtime.label,
47
+ runtimeDetect: runtime.detect,
27
48
  host: (process.env.HOSTNAME ?? process.env.HOST ?? 'unknown').trim() || 'unknown',
28
49
  namespace: ns || undefined,
29
- coreVersion: (process.env.npm_package_version ?? 'unknown').trim() || 'unknown',
50
+ coreVersion: resolveInstalledCoreVersion(),
51
+ serviceVersion: svcVer ? (svcName ? `${svcName} ${svcVer}` : svcVer) : undefined,
30
52
  probeTimeoutMs: options.probeTimeoutMs,
31
53
  tcpProbe: options.tcpProbe,
32
54
  durationMs: Math.max(0, Date.now() - options.startedAtMs),
33
55
  };
34
56
  }
35
- /** Strict fail: one report on stderr, exit 1 — no Error stack (avoids duplicate lines + Bun SIGTERM noise in k8s). */
57
+ /** Thrown after report is printed — boot handler exits without extra CLI noise. */
58
+ export class InfraPreflightFailed extends Error {
59
+ constructor() {
60
+ super('Infrastructure preflight failed');
61
+ this.name = 'InfraPreflightFailed';
62
+ }
63
+ }
64
+ /** Strict fail: one report on stderr, then InfraPreflightFailed (no duplicate stack). */
36
65
  export function abortInfraPreflight(report) {
37
66
  console.error(report);
38
- process.exit(1);
67
+ throw new InfraPreflightFailed();
39
68
  }
40
69
  export function resolveProbeTimeoutMs() {
41
70
  const raw = (process.env.INFRA_PREFLIGHT_TIMEOUT_MS ?? '').trim();
@@ -137,18 +166,18 @@ function probeTcp(host, port, timeoutMs) {
137
166
  return Promise.resolve({ ok: true });
138
167
  }
139
168
  return new Promise((resolve) => {
140
- const socket = net.connect({ host, port });
141
169
  let settled = false;
142
170
  const finish = (ok, error) => {
143
171
  if (settled)
144
172
  return;
145
173
  settled = true;
174
+ clearTimeout(hardTimer);
146
175
  socket.destroy();
147
176
  resolve({ ok, error });
148
177
  };
149
- socket.setTimeout(ms);
178
+ const socket = net.connect({ host, port });
179
+ const hardTimer = setTimeout(() => finish(false, 'connection timed out'), ms);
150
180
  socket.on('connect', () => finish(true));
151
- socket.on('timeout', () => finish(false, 'connection timed out'));
152
181
  socket.on('error', (err) => finish(false, err.code ?? err.message));
153
182
  });
154
183
  }
@@ -260,12 +289,15 @@ function pad(value, width) {
260
289
  function formatReportMeta(meta) {
261
290
  const lines = [
262
291
  `At ${meta.atUtc}`,
263
- `Runtime ${meta.runtime}`,
292
+ `Runtime ${meta.runtime} (${meta.runtimeDetect})`,
264
293
  `Host ${meta.host}`,
265
294
  ];
266
295
  if (meta.namespace)
267
296
  lines.push(`Namespace ${meta.namespace}`);
268
- lines.push(`Core @xrystal/core ${meta.coreVersion}`, `Probe timeout ${meta.probeTimeoutMs}ms · TCP ${meta.tcpProbe ? 'on' : 'off'} · elapsed ${meta.durationMs}ms`);
297
+ lines.push(`Core @xrystal/core ${meta.coreVersion}`);
298
+ if (meta.serviceVersion)
299
+ lines.push(`Service ${meta.serviceVersion}`);
300
+ lines.push(`Probe timeout ${meta.probeTimeoutMs}ms · TCP ${meta.tcpProbe ? 'on' : 'off'} · elapsed ${meta.durationMs}ms`);
269
301
  return lines;
270
302
  }
271
303
  function formatReport(outcome, rows, context, meta, action) {