@xrystal/core 3.55.13 → 3.55.18

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/README.md CHANGED
@@ -257,9 +257,14 @@ bun run dev
257
257
  | `xry dev` | Watch `source/index.ts` + dev env | `source/index.ts` watch + dev env |
258
258
  | `xry build` | `tsc` full tree → dist (auto default) + alias/fix post-steps | `tsc` ile tüm `source/` → dist |
259
259
  | `xry start` | Run `x/dist` + prod env | `x/dist` + prod env |
260
+ ### Runtime env (k8s / Docker) — since 3.55.18
261
+
262
+ **EN:** `x/environments/.global.env` and `.dev.env` are for **local dev** and **Telepresence** only. They must not be copied into container images. In k8s, inject the same keys via Secret (`envFrom`); `xry start` / `Configs` read **`process.env`** only (detects `KUBERNETES_SERVICE_HOST`, `/.dockerenv`, or `XRY_RUNTIME=container`). Docker Compose: use `env_file:` at compose level — not `COPY x/environments` in the Dockerfile.
263
+
264
+ **TR:** `x/environments/*` yalnızca lokal dev + Telepresence. Image'a gömme. Cluster'da Secret inject; runtime dosya okumaz.
260
265
  | `xry test` | Run `x/tests` | `x/tests` çalıştır |
261
266
  | `xry doctor` | CLI, runtime, package health | CLI, runtime, paket uyumu |
262
- | `xry tag` | Core release: tag + npm publish | Core release tag + npm |
267
+ | `xry tag` | **This repo only** — tag + npm publish (`@xrystal/core`) | **Sadece core** — servislerde çalışmaz / git tag yok |
263
268
 
264
269
  ---
265
270
 
@@ -870,4 +875,7 @@ class ChatController extends Controller {
870
875
 
871
876
  **EN:** This repo is the `@xrystal/core` source. Bump `package.json` → commit → `xry tag` (runs prepare + pushes `vX.Y.Z`; GitHub Publish workflow releases to npm). Consumers only need `bun add @xrystal/core`.
872
877
 
878
+
879
+ **npm CI (`E401` / invalid token):** GitHub → repo **Settings → Environments → NPM** → secret **`TOKEN`** = [npm Granular Access Token](https://www.npmjs.com/settings/~youruser/tokens) with **Publish** on package `@xrystal/core` (or whole `@xrystal` scope). Classic automation tokens that bypass 2FA are being restricted — prefer **Granular** + **Publish**. After rotate: re-run failed **Publish Core Library NPM** workflow or push empty commit / re-tag. Stage flow: workflow runs `npm stage publish` → approve on npmjs.com (`npm stage list` / Approve with 2FA).
880
+
873
881
  **TR:** Bu repo `@xrystal/core` kaynağıdır. `package.json` bump → commit → `xry tag` (prepare + `vX.Y.Z` push; GitHub Publish → npm). Tüketici için sadece `bun add @xrystal/core` yeter.
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.13",
4
+ "version": "3.55.18",
5
5
  "description": "Runtime framework and CLI for API services, frontends, and multi-repo workspaces",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -123,4 +123,4 @@
123
123
  "typescript": "~5.9.3",
124
124
  "typescript-eslint": "^8.62.1"
125
125
  }
126
- }
126
+ }
@@ -11,9 +11,10 @@ import {
11
11
  buildRuntimeStartArgv,
12
12
  buildRuntimeWatchArgv,
13
13
  resolveDevEntry,
14
- resolveDevEnvFileNames,
14
+ resolveDevRunnerEnvFiles,
15
15
  resolveDistEntryAbs,
16
- resolveEnvFiles,
16
+ isProcessEnvInjectedRuntime,
17
+ resolveStartEnvFiles,
17
18
  resolvePackageScriptRunner,
18
19
  resolveRuntimeRunner,
19
20
  resolveServiceBuildSteps,
@@ -55,10 +56,7 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
55
56
  runWithServiceRoot((root) => {
56
57
  const { layout, runtime } = readTmpBuildContext(root)
57
58
  const entry = resolveDevEntry(root, layout)
58
- const envFiles = resolveEnvFiles(
59
- layout.pathsAbs.environments,
60
- resolveDevEnvFileNames(layout.pathsAbs.environments),
61
- )
59
+ const envFiles = resolveDevRunnerEnvFiles(layout.pathsAbs.environments)
62
60
  const { runner, argv } = buildRuntimeWatchArgv(runtime, entry, envFiles)
63
61
 
64
62
  printCommandHeader({ cliName, command: 'dev', version: readCliPackageJson().version })
@@ -67,6 +65,8 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
67
65
  console.log(chalk.gray(` entry: ${entry} (.ts)`))
68
66
  if (envFiles.length) {
69
67
  console.log(chalk.gray(` env: ${envFiles.map((f) => path.relative(root, f)).join(' · ')}\n`))
68
+ } else if (isProcessEnvInjectedRuntime()) {
69
+ console.log(chalk.gray(' env: process environment (injected runtime)\n'))
70
70
  } else {
71
71
  console.log('')
72
72
  }
@@ -131,13 +131,18 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
131
131
  }
132
132
 
133
133
  const entry = relativeFromRoot(root, entryAbs)
134
- const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.prod.env'])
134
+ const envFiles = resolveStartEnvFiles(layout.pathsAbs.environments)
135
135
  const { runner, argv } = buildRuntimeStartArgv(runtime, entry, envFiles)
136
136
 
137
137
  printCommandHeader({ cliName, command: 'start', version: readCliPackageJson().version })
138
138
  console.log(chalk.gray(` root: ${root}`))
139
139
  console.log(chalk.gray(` runtime: ${runtime}`))
140
- console.log(chalk.gray(` entry: ${entry} (.js)\n`))
140
+ console.log(chalk.gray(` entry: ${entry} (.js)`))
141
+ if (envFiles.length) {
142
+ console.log(chalk.gray(` env: ${envFiles.map((f) => path.relative(root, f)).join(' · ')}\n`))
143
+ } else {
144
+ console.log(chalk.gray(' env: process environment (no --env-file)\n'))
145
+ }
141
146
  runRunner(root, runner, argv)
142
147
  }, { cliName, command: 'start' })
143
148
  })
@@ -1,20 +1,33 @@
1
1
  import chalk from 'chalk'
2
2
  import { readCliPackageJson, readProjectPackageJson } from '../helpers/project-root.mjs'
3
- import { requireServiceRoot, exitOnCliContextError } from '../helpers/cli-context-guard.mjs'
3
+ import { requireServiceRoot, exitOnCliContextError, CliContextError } from '../helpers/cli-context-guard.mjs'
4
4
  import { compareSemver, getVersionState, resolveVersionBaseline, runTagRelease } from '../scripts/version-check.mjs'
5
- import { CLI_PRIMARY_NAME, PACKAGE_NAME } from '../helpers/cli-identity.mjs'
5
+ import { isCorePackageProject } from '../scripts/release-prepare.mjs'
6
6
  import { packageDefaults } from '../helpers/package-defaults.mjs'
7
+ import { CLI_PRIMARY_NAME, PACKAGE_NAME } from '../helpers/cli-identity.mjs'
7
8
 
8
9
  export function registerTagCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
9
10
  cli
10
11
  .command('tag')
11
- .description('Git tag from package.json (+ npm publish for core)')
12
+ .description(`Git tag + npm publish (${packageDefaults.packageName} repo only)`)
12
13
  .option('--dry-run', 'Print commands without executing')
13
14
  .option('--strict-clean', 'Require fully clean working tree (default: only package.json must be committed)')
14
15
  .option('--skip-prepare', 'Skip lint, test, and build:prod (core only)')
15
16
  .action(async (options) => {
16
17
  try {
17
18
  const { root } = requireServiceRoot(process.cwd(), { cliName, command: 'tag' })
19
+ if (!isCorePackageProject(root)) {
20
+ throw new CliContextError(
21
+ `\`xry tag\` is only for ${packageDefaults.packageName} (library). Services do not create git tags here.`,
22
+ {
23
+ hints: [
24
+ 'cd to -xrystal-core and bump package.json → commit → xry tag',
25
+ 'Service images: CalVer via platform release (see infra versioning.mdc)',
26
+ `${cliName} version — check package.json in this repo`,
27
+ ],
28
+ },
29
+ )
30
+ }
18
31
  await runTagRelease({
19
32
  dryRun: options.dryRun,
20
33
  requireClean: options.strictClean,
@@ -52,7 +65,12 @@ export function registerVersionCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
52
65
  console.log(` name: ${chalk.bold(projectPkg.name)}`)
53
66
  console.log(` package.json (disk): ${chalk.bold(state.disk.version)}`)
54
67
  console.log(` package.json (HEAD): ${chalk.bold(state.committed.version)}`)
55
- console.log(` git tag name: ${chalk.bold(`v${state.committed.version}`)}`)
68
+ const isCore = isCorePackageProject(root)
69
+ if (isCore) {
70
+ console.log(` git tag name: ${chalk.bold(`v${state.committed.version}`)}`)
71
+ } else {
72
+ console.log(` service image tag: ${chalk.gray('N/A — CalVer via platform CI (infra versioning.mdc)')}`)
73
+ }
56
74
  console.log(` branch: ${state.branch}`)
57
75
  console.log(` version match: ${state.versionMatch ? chalk.green('yes') : chalk.red('no')}`)
58
76
  console.log(` package.json committed: ${state.isPackageJsonClean ? chalk.green('yes') : chalk.red('no')}`)
@@ -463,6 +463,33 @@ export function resolveEnvFiles(envDir, names) {
463
463
  .filter((file) => fs.existsSync(file))
464
464
  }
465
465
 
466
+ /** k8s Secret / Compose env_file / Docker inject — do not pass bun --env-file for baked x/environments. */
467
+ export function isProcessEnvInjectedRuntime() {
468
+ const explicit = (process.env.XRY_RUNTIME ?? '').trim().toLowerCase()
469
+ if (['container', 'k8s', 'kubernetes', 'docker'].includes(explicit)) return true
470
+ if (process.env.KUBERNETES_SERVICE_HOST) return true
471
+ try {
472
+ if (fs.existsSync('/.dockerenv')) return true
473
+ } catch {
474
+ /* ignore */
475
+ }
476
+ return false
477
+ }
478
+
479
+ /** Prod dist run: local uses x/environments/*.env; containers use process env only. */
480
+ export function resolveStartEnvFiles(envDir) {
481
+ if (isProcessEnvInjectedRuntime()) return []
482
+ const files = resolveEnvFiles(envDir, ['.global.env', '.prod.env'])
483
+ if (files.length === 0 && (process.env.PORT ?? '').trim()) return []
484
+ return files
485
+ }
486
+
487
+ /** Dev watch: optional file env when not in injected runtime. */
488
+ export function resolveDevRunnerEnvFiles(envDir) {
489
+ if (isProcessEnvInjectedRuntime()) return []
490
+ return resolveEnvFiles(envDir, resolveDevEnvFileNames(envDir))
491
+ }
492
+
466
493
  /** Dev env load order — telepresence cluster env last when present. */
467
494
  export function resolveDevEnvFileNames(envDir) {
468
495
  const names = ['.global.env', '.dev.env']
@@ -0,0 +1,7 @@
1
+ import { type RedisClientType } from 'redis';
2
+ export type ConnectRedisOptions = {
3
+ uri: string;
4
+ sentinelMaster?: string;
5
+ isRedisSentinel?: boolean;
6
+ };
7
+ export declare function connectRedisClient(options: ConnectRedisOptions): Promise<RedisClientType>;
@@ -0,0 +1,57 @@
1
+ import { createClient, createSentinel } from 'redis';
2
+ import { parseRedisUri, standaloneRedisUrl } from './parse-uri.js';
3
+ import { resolveRedisSocketOptions } from './resolve-socket.js';
4
+ function parseSentinelRootNodes(csv) {
5
+ return csv
6
+ .split(',')
7
+ .map((part) => part.trim())
8
+ .filter(Boolean)
9
+ .map((part) => {
10
+ const colon = part.lastIndexOf(':');
11
+ if (colon === -1) {
12
+ return { host: part, port: 26379 };
13
+ }
14
+ const host = part.slice(0, colon);
15
+ const port = Number.parseInt(part.slice(colon + 1), 10);
16
+ return { host, port: Number.isFinite(port) ? port : 26379 };
17
+ })
18
+ .filter((n) => n.host.length > 0);
19
+ }
20
+ export async function connectRedisClient(options) {
21
+ const uri = options.uri?.trim();
22
+ if (!uri) {
23
+ throw new Error('Redis URI is required');
24
+ }
25
+ const parsed = parseRedisUri(uri);
26
+ const socketOpts = resolveRedisSocketOptions(uri);
27
+ const sentinelMaster = options.sentinelMaster?.trim() ||
28
+ process.env.REDIS_SENTINEL_MASTER?.trim() ||
29
+ 'mymaster';
30
+ const envSentinelHosts = process.env.REDIS_SENTINEL_HOSTS?.trim();
31
+ const preferSentinel = options.isRedisSentinel !== false &&
32
+ (envSentinelHosts ? true : parsed.useSentinel);
33
+ if (preferSentinel) {
34
+ const rootNodes = envSentinelHosts
35
+ ? parseSentinelRootNodes(envSentinelHosts)
36
+ : parsed.endpoints.map((e) => ({ host: e.host, port: e.port }));
37
+ if (rootNodes.length === 0) {
38
+ throw new Error('Redis Sentinel mode requires at least one sentinel endpoint');
39
+ }
40
+ return (await createSentinel({
41
+ name: sentinelMaster,
42
+ sentinelRootNodes: rootNodes,
43
+ nodeClientOptions: {
44
+ ...parsed.creds,
45
+ socket: socketOpts,
46
+ },
47
+ sentinelClientOptions: {
48
+ socket: socketOpts,
49
+ },
50
+ }).connect());
51
+ }
52
+ const standaloneUrl = standaloneRedisUrl(uri, parsed.endpoints);
53
+ return (await createClient({
54
+ url: standaloneUrl,
55
+ socket: socketOpts,
56
+ }).connect());
57
+ }
@@ -1,6 +1,7 @@
1
1
  export { resolveRedisSocketOptions } from './resolve-socket';
2
2
  export { parseRedisUri, standaloneRedisUrl } from './parse-uri';
3
- import { type RedisClientType } from 'redis';
3
+ export { connectRedisClient, type ConnectRedisOptions } from './connect';
4
+ import type { RedisClientType } from 'redis';
4
5
  import Configs from '../../loader/configs';
5
6
  import System from '../../loader/system';
6
7
  import { IProvide } from '../../utils/models/classes/class.interfaces';
@@ -1,22 +1,10 @@
1
1
  export { resolveRedisSocketOptions } from './resolve-socket.js';
2
2
  export { parseRedisUri, standaloneRedisUrl } from './parse-uri.js';
3
- import { createClient, createSentinel } from 'redis';
3
+ export { connectRedisClient } from './connect.js';
4
4
  import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
5
5
  import { readInfraLoaderEnabled } from '../../utils/helpers/loader-options/index.js';
6
6
  import { InfraLoaderEnum } from '../../utils/models/enums/index.js';
7
- import { parseRedisUri, standaloneRedisUrl } from './parse-uri.js';
8
- import { resolveRedisSocketOptions } from './resolve-socket.js';
9
- function parseSentinelRootNodes(csv) {
10
- return csv
11
- .split(',')
12
- .map((part) => part.trim())
13
- .filter(Boolean)
14
- .map((part) => {
15
- const [host, port] = part.split(':');
16
- return { host: host.trim(), port: Number.parseInt(port || '26379', 10) };
17
- })
18
- .filter((n) => n.host.length > 0);
19
- }
7
+ import { connectRedisClient } from './connect.js';
20
8
  export default class RedisForCore {
21
9
  #client = null;
22
10
  #system;
@@ -39,7 +27,7 @@ export default class RedisForCore {
39
27
  syncFromTmp = async () => {
40
28
  await this.teardown();
41
29
  const loaders = this.#resolveDependsLoaders();
42
- if (!readInfraLoaderEnabled(loaders, InfraLoaderEnum.REDIS, true)) {
30
+ if (!readInfraLoaderEnabled(loaders, InfraLoaderEnum.REDIS, false)) {
43
31
  return;
44
32
  }
45
33
  if (this.#configs.all.isRedisPassive) {
@@ -49,41 +37,11 @@ export default class RedisForCore {
49
37
  if (!uri) {
50
38
  return;
51
39
  }
52
- const parsed = parseRedisUri(uri);
53
- const socketOpts = resolveRedisSocketOptions(uri);
54
- const sentinelMaster = process.env.REDIS_SENTINEL_MASTER?.trim() ||
55
- this.#configs.all.redisSentinelMaster?.trim() ||
56
- 'mymaster';
57
- const envSentinelHosts = process.env.REDIS_SENTINEL_HOSTS?.trim();
58
- const preferSentinel = this.#configs.all.isRedisSentinel !== false &&
59
- (envSentinelHosts ? true : parsed.useSentinel);
60
- let client;
61
- if (preferSentinel) {
62
- const rootNodes = envSentinelHosts
63
- ? parseSentinelRootNodes(envSentinelHosts)
64
- : parsed.endpoints.map((e) => ({ host: e.host, port: e.port }));
65
- if (rootNodes.length === 0) {
66
- throw new Error('Redis Sentinel mode requires at least one sentinel endpoint');
67
- }
68
- client = (await createSentinel({
69
- name: sentinelMaster,
70
- sentinelRootNodes: rootNodes,
71
- nodeClientOptions: {
72
- ...parsed.creds,
73
- socket: socketOpts,
74
- },
75
- sentinelClientOptions: {
76
- socket: socketOpts,
77
- },
78
- }).connect());
79
- }
80
- else {
81
- const standaloneUrl = standaloneRedisUrl(uri, parsed.endpoints);
82
- client = (await createClient({
83
- url: standaloneUrl,
84
- socket: socketOpts,
85
- }).connect());
86
- }
40
+ const client = await connectRedisClient({
41
+ uri,
42
+ sentinelMaster: this.#configs.all.redisSentinelMaster,
43
+ isRedisSentinel: this.#configs.all.isRedisSentinel,
44
+ });
87
45
  client.on('error', (err) => {
88
46
  console.error(`Redis ${err}`);
89
47
  });