@xrystal/core 3.55.5 → 3.55.7
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 +1 -1
- package/x/bin/commands/project.mjs +24 -9
- package/x/bin/commands/telepresence.mjs +1 -1
- package/x/bin/helpers/.generated/tmp-schema.mjs +9 -0
- package/x/bin/helpers/build-config.mjs +30 -0
- package/x/dist/loader/configs/index.js +16 -6
- package/x/dist/loader/events/index.d.ts +1 -0
- package/x/dist/loader/events/index.js +11 -2
- package/x/dist/loader/localizations/index.js +2 -1
- package/x/dist/loader/logger/index.js +3 -2
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +8 -0
- package/x/dist/utils/models/classes/class.x.js +2 -2
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execSync } from 'node:child_process'
|
|
1
|
+
import { execSync, spawnSync } from 'node:child_process'
|
|
2
2
|
import fs from 'node:fs'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import chalk from 'chalk'
|
|
@@ -8,7 +8,10 @@ import {
|
|
|
8
8
|
isCorePackageName,
|
|
9
9
|
readTmpBuildContext,
|
|
10
10
|
resolveCoreBuildSteps,
|
|
11
|
+
buildRuntimeStartArgv,
|
|
12
|
+
buildRuntimeWatchArgv,
|
|
11
13
|
resolveDevEntry,
|
|
14
|
+
resolveDevEnvFileNames,
|
|
12
15
|
resolveDistEntryAbs,
|
|
13
16
|
resolveEnvFiles,
|
|
14
17
|
resolvePackageScriptRunner,
|
|
@@ -28,6 +31,12 @@ function runInProject(root, command) {
|
|
|
28
31
|
execSync(command, { cwd: root, stdio: 'inherit', env: process.env })
|
|
29
32
|
}
|
|
30
33
|
|
|
34
|
+
function runRunner(root, runner, argv) {
|
|
35
|
+
const result = spawnSync(runner, argv, { cwd: root, stdio: 'inherit', env: process.env })
|
|
36
|
+
if (result.error) throw result.error
|
|
37
|
+
if (result.status !== 0) process.exit(result.status ?? 1)
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
function resolveTestTarget(root) {
|
|
32
41
|
const layout = ensureTmpFile(root).layout
|
|
33
42
|
if (fs.existsSync(layout.pathsAbs.tests)) {
|
|
@@ -46,15 +55,22 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
46
55
|
runWithServiceRoot((root) => {
|
|
47
56
|
const { layout, runtime } = readTmpBuildContext(root)
|
|
48
57
|
const entry = resolveDevEntry(root, layout)
|
|
49
|
-
const envFiles = resolveEnvFiles(
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
const envFiles = resolveEnvFiles(
|
|
59
|
+
layout.pathsAbs.environments,
|
|
60
|
+
resolveDevEnvFileNames(layout.pathsAbs.environments),
|
|
61
|
+
)
|
|
62
|
+
const { runner, argv } = buildRuntimeWatchArgv(runtime, entry, envFiles)
|
|
52
63
|
|
|
53
64
|
printCommandHeader({ cliName, command: 'dev', version: readCliPackageJson().version })
|
|
54
65
|
console.log(chalk.gray(` root: ${root}`))
|
|
55
66
|
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
56
|
-
console.log(chalk.gray(` entry: ${entry} (.ts)
|
|
57
|
-
|
|
67
|
+
console.log(chalk.gray(` entry: ${entry} (.ts)`))
|
|
68
|
+
if (envFiles.length) {
|
|
69
|
+
console.log(chalk.gray(` env: ${envFiles.map((f) => path.relative(root, f)).join(' · ')}\n`))
|
|
70
|
+
} else {
|
|
71
|
+
console.log('')
|
|
72
|
+
}
|
|
73
|
+
runRunner(root, runner, argv)
|
|
58
74
|
}, { cliName, command: 'dev' })
|
|
59
75
|
})
|
|
60
76
|
|
|
@@ -116,14 +132,13 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
116
132
|
|
|
117
133
|
const entry = relativeFromRoot(root, entryAbs)
|
|
118
134
|
const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.prod.env'])
|
|
119
|
-
const
|
|
120
|
-
const runner = resolveRuntimeRunner(runtime)
|
|
135
|
+
const { runner, argv } = buildRuntimeStartArgv(runtime, entry, envFiles)
|
|
121
136
|
|
|
122
137
|
printCommandHeader({ cliName, command: 'start', version: readCliPackageJson().version })
|
|
123
138
|
console.log(chalk.gray(` root: ${root}`))
|
|
124
139
|
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
125
140
|
console.log(chalk.gray(` entry: ${entry} (.js)\n`))
|
|
126
|
-
|
|
141
|
+
runRunner(root, runner, argv)
|
|
127
142
|
}, { cliName, command: 'start' })
|
|
128
143
|
})
|
|
129
144
|
|
|
@@ -137,7 +137,7 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
|
|
|
137
137
|
|
|
138
138
|
const portArg = parsePort(port)
|
|
139
139
|
const rest = command.args.slice(/^\d+$/.test(String(port ?? '')) ? 2 : 1)
|
|
140
|
-
const localCmd = rest.length ? rest : ['
|
|
140
|
+
const localCmd = rest.length ? rest : ['xry', 'dev']
|
|
141
141
|
const args = [`NS=${ns}`, deployName, portArg, '--', ...localCmd]
|
|
142
142
|
|
|
143
143
|
runHelper(interceptScript, args, { cwd: svcDir })
|
|
@@ -362,6 +362,14 @@ function readTmpDependsBlock(configs) {
|
|
|
362
362
|
loaders
|
|
363
363
|
};
|
|
364
364
|
}
|
|
365
|
+
function resolveTmpLoaders(configs) {
|
|
366
|
+
const dependsLoaders = readTmpDependsBlock(configs).loaders;
|
|
367
|
+
if (dependsLoaders)
|
|
368
|
+
return dependsLoaders;
|
|
369
|
+
const service = isRecord2(configs?.service) ? configs.service : {};
|
|
370
|
+
const legacy = isRecord2(service.loaders) ? service.loaders : {};
|
|
371
|
+
return { ...legacy };
|
|
372
|
+
}
|
|
365
373
|
function resolveTmpDeploymentName(tmp) {
|
|
366
374
|
assertNoLegacyTmpKeys(isRecord2(tmp?.configs) ? tmp.configs : undefined);
|
|
367
375
|
const project = isRecord2(tmp?.project) ? tmp.project : {};
|
|
@@ -434,6 +442,7 @@ function resolveTmpAbsPath(projectRoot, configs) {
|
|
|
434
442
|
}
|
|
435
443
|
export {
|
|
436
444
|
resolveTmpRuntimeConfigs,
|
|
445
|
+
resolveTmpLoaders,
|
|
437
446
|
resolveTmpDeploymentName,
|
|
438
447
|
resolveTmpAbsPath,
|
|
439
448
|
resolveProjectRootFromTmpPath,
|
|
@@ -463,6 +463,36 @@ export function resolveEnvFiles(envDir, names) {
|
|
|
463
463
|
.filter((file) => fs.existsSync(file))
|
|
464
464
|
}
|
|
465
465
|
|
|
466
|
+
/** Dev env load order — telepresence cluster env last when present. */
|
|
467
|
+
export function resolveDevEnvFileNames(envDir) {
|
|
468
|
+
const names = ['.global.env', '.dev.env']
|
|
469
|
+
if (fs.existsSync(path.join(envDir, '.env.telepresence'))) {
|
|
470
|
+
names.push('.env.telepresence')
|
|
471
|
+
}
|
|
472
|
+
return names
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function appendEnvFileArgs(argv, envFiles) {
|
|
476
|
+
for (const file of envFiles) {
|
|
477
|
+
argv.push('--env-file', file)
|
|
478
|
+
}
|
|
479
|
+
return argv
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export function buildRuntimeWatchArgv(runtime, entry, envFiles) {
|
|
483
|
+
const runner = resolveRuntimeRunner(runtime)
|
|
484
|
+
const argv = appendEnvFileArgs(['--watch'], envFiles)
|
|
485
|
+
argv.push(entry)
|
|
486
|
+
return { runner, argv }
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export function buildRuntimeStartArgv(runtime, entry, envFiles) {
|
|
490
|
+
const runner = resolveRuntimeRunner(runtime)
|
|
491
|
+
const argv = appendEnvFileArgs([], envFiles)
|
|
492
|
+
argv.push(entry)
|
|
493
|
+
return { runner, argv }
|
|
494
|
+
}
|
|
495
|
+
|
|
466
496
|
|
|
467
497
|
export function resolveRuntimeRunner(runtime = detectCliHostRuntime()) {
|
|
468
498
|
return getRuntimeTooling(runtime).binRunner
|
|
@@ -6,6 +6,7 @@ import { resolveTmpLoadPath } from '../../utils/helpers/path/resolve-alias-path.
|
|
|
6
6
|
import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
|
|
7
7
|
import { normalizeNodeEnv } from '../../utils/helpers/node-env/index.js';
|
|
8
8
|
import { readKafkaLoaderOptions } from '../../utils/helpers/kafka-loader-options/index.js';
|
|
9
|
+
import { resolveTmpLoaders } from '../../utils/helpers/tmp/tmp-schema.js';
|
|
9
10
|
export default class Configs {
|
|
10
11
|
publicFolderName = Constants.publicFolderName;
|
|
11
12
|
kafkaLogsTopic = Constants.kafkaLogsTopic;
|
|
@@ -27,7 +28,16 @@ export default class Configs {
|
|
|
27
28
|
syncFromTmp = async () => {
|
|
28
29
|
const cwd = process.cwd();
|
|
29
30
|
const tmp = this.#system.tmp;
|
|
30
|
-
const
|
|
31
|
+
const runtimeConfigs = tmp.configs;
|
|
32
|
+
const rootFolderPath = runtimeConfigs.rootFolderPath ?? 'x';
|
|
33
|
+
const deploymentName = runtimeConfigs.deploymentName
|
|
34
|
+
?? (typeof tmp.project?.name === 'string' ? tmp.project.name : '')
|
|
35
|
+
?? '';
|
|
36
|
+
const loaders = resolveTmpLoaders(tmp.configs);
|
|
37
|
+
const extendConfigs = loaders.configs?.loadPath;
|
|
38
|
+
if (!extendConfigs) {
|
|
39
|
+
throw new Error(`${Constants.packageName}: configs.depends.loaders.configs.loadPath is required in tmp.yml`);
|
|
40
|
+
}
|
|
31
41
|
const fullPath = resolveTmpLoadPath(extendConfigs, tmp, cwd);
|
|
32
42
|
const fileUrl = pathToFileURL(fullPath).href;
|
|
33
43
|
const modulePromise = import(fileUrl);
|
|
@@ -40,16 +50,16 @@ export default class Configs {
|
|
|
40
50
|
httpsfileEncoding: process.env.ENCODING || 'utf8',
|
|
41
51
|
httpsCertfile: process.env.HTTPS_CERT_FILE ?? '',
|
|
42
52
|
httpsKeyfile: process.env.HTTPS_KEY_FILE ?? '',
|
|
43
|
-
rootFolderPath
|
|
53
|
+
rootFolderPath,
|
|
44
54
|
projectName: tmp.project.name,
|
|
45
|
-
serviceName:
|
|
55
|
+
serviceName: deploymentName,
|
|
46
56
|
projectNamePrefixEnv: process.env.PROJECT_NAME_PREFIX || '',
|
|
47
57
|
projectNameEnv: process.env.PROJECT_NAME || '',
|
|
48
58
|
projectNameSuffixEnv: process.env.PROJECT_NAME_SUFFIX || '',
|
|
49
|
-
systemStaticFolderPath: path.resolve(
|
|
59
|
+
systemStaticFolderPath: path.resolve(rootFolderPath, this.publicFolderName),
|
|
50
60
|
systemLoggerLayer: process.env.SYSTEM_LOGGER_LAYER ?? 'info',
|
|
51
|
-
isKafkaPassive: !readKafkaLoaderOptions(
|
|
52
|
-
kafkaClientId:
|
|
61
|
+
isKafkaPassive: !readKafkaLoaderOptions(loaders).enabled,
|
|
62
|
+
kafkaClientId: deploymentName,
|
|
53
63
|
kafkaBrokers: process.env.KAFKA_BROKERS ?? '',
|
|
54
64
|
kafkaUsername: process.env.KAFKA_USERNAME ?? '',
|
|
55
65
|
kafkaPassword: process.env.KAFKA_PASSWORD ?? '',
|
|
@@ -8,9 +8,18 @@ export default class Events {
|
|
|
8
8
|
this._globalLoader();
|
|
9
9
|
this._DILoader();
|
|
10
10
|
};
|
|
11
|
+
safeLog(params) {
|
|
12
|
+
try {
|
|
13
|
+
this.#logger.log(params);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
const msg = params?.message ?? 'unknown';
|
|
17
|
+
console.error('[events]', msg, params?.payload, error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
11
20
|
_globalLoader = () => {
|
|
12
21
|
process.on("uncaughtException", (error, origin) => {
|
|
13
|
-
this
|
|
22
|
+
this.safeLog({
|
|
14
23
|
level: LoggerLayerEnum.CRITICAL,
|
|
15
24
|
message: `Uncaught Exception: ${error.message}`,
|
|
16
25
|
payload: {
|
|
@@ -21,7 +30,7 @@ export default class Events {
|
|
|
21
30
|
});
|
|
22
31
|
process.on("unhandledRejection", (reason, promise) => {
|
|
23
32
|
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
24
|
-
this
|
|
33
|
+
this.safeLog({
|
|
25
34
|
level: LoggerLayerEnum.CRITICAL,
|
|
26
35
|
message: `Unhandled Rejection: ${error.message}`,
|
|
27
36
|
payload: {
|
|
@@ -3,6 +3,7 @@ import i18next from "i18next";
|
|
|
3
3
|
import Backend from 'i18next-fs-backend';
|
|
4
4
|
import * as middleware from 'i18next-http-middleware';
|
|
5
5
|
import { bindLoaderTmpSync } from '../../utils/index.js';
|
|
6
|
+
import { resolveTmpLoaders } from '../../utils/helpers/tmp/tmp-schema.js';
|
|
6
7
|
export default class Localizations {
|
|
7
8
|
_instance = null;
|
|
8
9
|
#system;
|
|
@@ -17,7 +18,7 @@ export default class Localizations {
|
|
|
17
18
|
};
|
|
18
19
|
syncFromTmp = async () => {
|
|
19
20
|
this._instance = null;
|
|
20
|
-
const localization = this.#system.tmp.configs.
|
|
21
|
+
const localization = resolveTmpLoaders(this.#system.tmp.configs).localization;
|
|
21
22
|
this.i18next({
|
|
22
23
|
loadPath: path.join(this.#system.tmp.configs.rootFolderPath, localization.loadPath),
|
|
23
24
|
fallbackLang: localization.fallbackLang,
|
|
@@ -4,6 +4,7 @@ import "winston-daily-rotate-file";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { Partitioners } from "kafkajs";
|
|
6
6
|
import { LoggerLayerEnum } from '../../utils/index.js';
|
|
7
|
+
import { normalizeNodeEnv } from '../../utils/helpers/node-env/index.js';
|
|
7
8
|
import { loggerLayerName, meetsLoggerLayerThreshold, normalizeLoggerLayer, } from '../../utils/helpers/logger-layer/index.js';
|
|
8
9
|
import { readKafkaLoaderOptions } from '../../utils/helpers/kafka-loader-options/index.js';
|
|
9
10
|
import { LogDTO } from "../../utils/index.js";
|
|
@@ -66,7 +67,7 @@ export default class Logger {
|
|
|
66
67
|
this.kafkaLogsTopic = this.#configs?.all?.kafkaLogsTopic;
|
|
67
68
|
winston.addColors(customColors);
|
|
68
69
|
const loggersConfigs = (loaders?.loggers ?? {});
|
|
69
|
-
const { kafkaBrokers } = this.#configs
|
|
70
|
+
const { kafkaBrokers } = this.#configs?.all ?? {};
|
|
70
71
|
const brokers = kafkaBrokers ? String(kafkaBrokers).split(',').map((b) => b.trim()) : [];
|
|
71
72
|
const kafkaOpts = readKafkaLoaderOptions(loaders);
|
|
72
73
|
const isKafkaLogEnabled = kafkaOpts.enabled && kafkaOpts.queueLogEnabled && brokers.length > 0;
|
|
@@ -184,7 +185,7 @@ export default class Logger {
|
|
|
184
185
|
code: params.code,
|
|
185
186
|
timestamp: params.timestamp ?? new Date().toISOString(),
|
|
186
187
|
id: params.id ?? getRequestId() ?? undefined,
|
|
187
|
-
env: this.#configs
|
|
188
|
+
env: (this.#configs?.all?.env ?? normalizeNodeEnv(process.env.NODE_ENV)),
|
|
188
189
|
}).build();
|
|
189
190
|
}
|
|
190
191
|
async logToKafka(info) {
|
|
@@ -59,6 +59,7 @@ export declare function assertNoLegacyTmpKeys(configs?: Record<string, unknown>)
|
|
|
59
59
|
/** Build options from configs.global.build only. */
|
|
60
60
|
export declare function readTmpBuildBlock(configs?: Record<string, unknown>): TmpBuildBlock;
|
|
61
61
|
export declare function readTmpDependsBlock(configs?: Record<string, unknown>): TmpDependsBlock;
|
|
62
|
+
export declare function resolveTmpLoaders(configs?: Record<string, unknown>): Record<string, unknown>;
|
|
62
63
|
export declare function resolveTmpDeploymentName(tmp?: Record<string, unknown> | null): string | undefined;
|
|
63
64
|
export declare function buildTmpVarContext(global: TmpGlobalBlock): Record<string, unknown>;
|
|
64
65
|
export declare function applyTmpGlobalVars(tmp: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -170,6 +170,14 @@ export function readTmpDependsBlock(configs) {
|
|
|
170
170
|
loaders,
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
|
+
export function resolveTmpLoaders(configs) {
|
|
174
|
+
const dependsLoaders = readTmpDependsBlock(configs).loaders;
|
|
175
|
+
if (dependsLoaders)
|
|
176
|
+
return dependsLoaders;
|
|
177
|
+
const service = isRecord(configs?.service) ? configs.service : {};
|
|
178
|
+
const legacy = isRecord(service.loaders) ? service.loaders : {};
|
|
179
|
+
return { ...legacy };
|
|
180
|
+
}
|
|
173
181
|
export function resolveTmpDeploymentName(tmp) {
|
|
174
182
|
assertNoLegacyTmpKeys(isRecord(tmp?.configs) ? tmp.configs : undefined);
|
|
175
183
|
const project = isRecord(tmp?.project) ? tmp.project : {};
|
|
@@ -113,8 +113,8 @@ class DIM extends X {
|
|
|
113
113
|
this.initializedNames.add(name);
|
|
114
114
|
}
|
|
115
115
|
catch (err) {
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
console.error(`[DI] Priority onInit Failed (${name}):`, err.message);
|
|
117
|
+
throw err;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
const allKeys = Object.keys(this.container.registrations);
|