@xrystal/core 3.55.62 → 3.55.64
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
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
|
-
|
|
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
|
|
package/x/dist/project/index.js
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
|
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:
|
|
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: (
|
|
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
|
-
/**
|
|
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
|
-
|
|
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.
|
|
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}
|
|
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) {
|
|
@@ -2,6 +2,7 @@ import { createContainer, asClass, asValue, InjectionMode, listModules, Lifetime
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import defaults from '../../../utils/constants/defaults.json' with { type: 'json' };
|
|
5
|
+
import { InfraPreflightFailed } from '../../../utils/helpers/infra-preflight/index.js';
|
|
5
6
|
export const xSymbol = Symbol.for(`${defaults.packageName}/di-container`);
|
|
6
7
|
class X {
|
|
7
8
|
checkRegistration(container, name) {
|
|
@@ -113,6 +114,9 @@ class DIM extends X {
|
|
|
113
114
|
this.initializedNames.add(name);
|
|
114
115
|
}
|
|
115
116
|
catch (err) {
|
|
117
|
+
if (err instanceof InfraPreflightFailed) {
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
116
120
|
console.error(`[DI] Priority onInit Failed (${name}):`, err.message);
|
|
117
121
|
throw err;
|
|
118
122
|
}
|