@xrystal/core 3.45.0 → 3.45.2

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
@@ -3,19 +3,25 @@
3
3
  > **EN** — Microservice runtime: Express or Elysia HTTP, DI loaders, live `tmp.yml`, standardized API responses.
4
4
  > **TR** — Microservice runtime: Express veya Elysia HTTP, DI loader'lar, canlı `tmp.yml`, standart API cevapları.
5
5
 
6
- **CLI:** `xry` · **Version:** `3.45.0` · [npm](https://www.npmjs.com/package/@xrystal/core)
6
+ **CLI:** `xry` · **Version:** `3.45.2` · [npm](https://www.npmjs.com/package/@xrystal/core)
7
7
 
8
8
  ---
9
9
 
10
- ## What's new in 3.45.0 / 3.45.0'da ne değişti
10
+ ## What's new in 3.45.2 / 3.45.2'da ne değişti
11
11
 
12
12
  | Change / Değişiklik | EN | TR |
13
13
  |---------------------|----|----|
14
- | **CLI identity** | Commander / help / logs lead with `@xrystal/core` | Kimlik = paket adı |
15
- | **No brand hardcodes** | Errors use `packageName`; invoke bin stays `xry` | Hardcode temizliği |
16
- | **Publish helpers** | Source/dist paths from defaults + tmp seed | Publish path SSOT |
14
+ | **Runtime SSOT** | `defaults.runtimes` + `RuntimeEnum`; no Bun/Node hardcodes in CLI | Runtime hardcode kalktı |
15
+ | **tmp.global.runtime** | Banner/project runtime from tmp.yml | Proje runtime tmp'den |
17
16
 
18
- Carried from **3.44.0:** layout auto-sync, banner package name, bun/node runtime coverage.
17
+ ## What's new in 3.45.1 / 3.45.1'da ne değişti
18
+
19
+ | Change / Değişiklik | EN | TR |
20
+ |---------------------|----|----|
21
+ | **No silent fallbacks** | Missing `cliBinFile` / `paths.source` throws | Eksikse uyarır, sessiz fallback yok |
22
+ | **Doctor labels** | Uses `paths.*` keys from tmp | Klasör adı hardcode değil |
23
+
24
+ Carried from **3.45.0:** CLI identity = `@xrystal/core`, brand hardcode cleanup, publish path SSOT.
19
25
 
20
26
  ```bash
21
27
  npx xry sync # force-apply tmp.yml → tsconfig (usually auto)
@@ -80,7 +86,7 @@ npx xry doctor # EN: optional health check · TR: isteğe bağlı sağlı
80
86
  ```json
81
87
  {
82
88
  "dependencies": {
83
- "@xrystal/core": "^3.45.0",
89
+ "@xrystal/core": "^3.45.2",
84
90
  "elysia": "^1.4.19"
85
91
  },
86
92
  "scripts": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.45.0",
4
+ "version": "3.45.2",
5
5
  "description": "microservice runtime library",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -73,11 +73,12 @@ export function registerDoctorCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
73
73
  printSection('Project')
74
74
  console.log(` ${'root'.padEnd(18)}${chalk.bold(root)}`)
75
75
  if (distLayout) {
76
- console.log(` ${'tmp root'.padEnd(18)}${chalk.bold(distLayout.rootFolderPath)} ${chalk.gray('(paths.root)')}`)
77
- console.log(` ${'source'.padEnd(18)}${chalk.bold(distLayout.layout.mainFolderPath)} ${chalk.gray('(paths.source)')}`)
78
- console.log(` ${'dist'.padEnd(18)}${chalk.bold(distLayout.distPrefix)} ${chalk.gray('(paths.special.dist)')}`)
76
+ const layout = distLayout.layout
77
+ console.log(` ${'paths.root'.padEnd(18)}${chalk.bold(distLayout.rootFolderPath)}`)
78
+ console.log(` ${'paths.source'.padEnd(18)}${chalk.bold(layout.mainFolderPath)}`)
79
+ console.log(` ${'paths.special.dist'.padEnd(18)}${chalk.bold(distLayout.distPrefix)}`)
79
80
  } else {
80
- console.log(chalk.yellow(` layout: tmp.yml not resolved — run ${CLI_PRIMARY_NAME} tmp`))
81
+ console.log(chalk.yellow(` layout: tmp.yml not resolved — run ${CLI_PRIMARY_NAME} tmp (then sync heals tsconfig)`))
81
82
  }
82
83
 
83
84
  printSection('CLI (tool)')
@@ -143,15 +144,15 @@ export function registerDoctorCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
143
144
 
144
145
  printSection('Toolchain')
145
146
  const toolchain = resolveToolchainPathsFromProject(root)
146
- console.log(` ${'source'.padEnd(18)}${chalk.bold(toolchain.mainSourceRel)}`)
147
- console.log(` ${'outDir'.padEnd(18)}${chalk.bold(toolchain.outDir)}`)
147
+ console.log(` ${'paths.source'.padEnd(18)}${chalk.bold(toolchain.mainSourceRel)}`)
148
+ console.log(` ${'outDir'.padEnd(18)}${chalk.bold(toolchain.outDir)} ${chalk.gray('(← paths.special.dist)')}`)
148
149
  const tsAudit = auditTsconfigAlignment(root)
149
150
  if (tsAudit.missing) {
150
- console.log(chalk.yellow(` ${'tsconfig'.padEnd(18)}missing · run ${CLI_PRIMARY_NAME} sync`))
151
+ console.log(chalk.yellow(` ${'tsconfig'.padEnd(18)}missing — will auto-heal on next command / ${CLI_PRIMARY_NAME} sync`))
151
152
  } else if (tsAudit.ok) {
152
153
  console.log(chalk.green(` ${'tsconfig'.padEnd(18)}aligned with tmp.yml`))
153
154
  } else {
154
- console.log(chalk.yellow(` ${'tsconfig'.padEnd(18)}drift from tmp.yml`))
155
+ console.log(chalk.yellow(` ${'tsconfig'.padEnd(18)}drift — auto-heal on next command / ${CLI_PRIMARY_NAME} sync`))
155
156
  for (const note of tsAudit.notes) console.log(chalk.gray(` · ${note}`))
156
157
  }
157
158
  console.log(` ${'eslint'.padEnd(18)}${toolchain.eslintFiles.join(', ')}`)
@@ -25,6 +25,36 @@ var defaults_default = {
25
25
  tagline: "microservice runtime library",
26
26
  capabilities: "loaders · tmp.yml · dto · i18n · multi-protocol · scaffold"
27
27
  },
28
+ runtimes: {
29
+ bun: {
30
+ label: "Bun",
31
+ packageManager: "bun",
32
+ installCommand: "bun install",
33
+ scriptRunner: "bun run",
34
+ binRunner: "bun",
35
+ testRunner: "bun test",
36
+ tscBin: "bunx tsc",
37
+ esbuildBin: "bunx esbuild",
38
+ devInvoker: null
39
+ },
40
+ node: {
41
+ label: "Node.js",
42
+ packageManager: "npm",
43
+ installCommand: "npm install",
44
+ scriptRunner: "npm run",
45
+ binRunner: "node",
46
+ testRunner: "node --test",
47
+ tscBin: "npx tsc",
48
+ esbuildBin: "npx esbuild",
49
+ devInvoker: "npx"
50
+ }
51
+ },
52
+ bundlers: [
53
+ "auto",
54
+ "bun",
55
+ "tsc",
56
+ "esbuild"
57
+ ],
28
58
  tmpWatchDefaults: {
29
59
  intervalMs: 500,
30
60
  minIntervalMs: 100,
@@ -20,6 +20,36 @@ var defaults_default = {
20
20
  tagline: "microservice runtime library",
21
21
  capabilities: "loaders · tmp.yml · dto · i18n · multi-protocol · scaffold"
22
22
  },
23
+ runtimes: {
24
+ bun: {
25
+ label: "Bun",
26
+ packageManager: "bun",
27
+ installCommand: "bun install",
28
+ scriptRunner: "bun run",
29
+ binRunner: "bun",
30
+ testRunner: "bun test",
31
+ tscBin: "bunx tsc",
32
+ esbuildBin: "bunx esbuild",
33
+ devInvoker: null
34
+ },
35
+ node: {
36
+ label: "Node.js",
37
+ packageManager: "npm",
38
+ installCommand: "npm install",
39
+ scriptRunner: "npm run",
40
+ binRunner: "node",
41
+ testRunner: "node --test",
42
+ tscBin: "npx tsc",
43
+ esbuildBin: "npx esbuild",
44
+ devInvoker: "npx"
45
+ }
46
+ },
47
+ bundlers: [
48
+ "auto",
49
+ "bun",
50
+ "tsc",
51
+ "esbuild"
52
+ ],
23
53
  tmpWatchDefaults: {
24
54
  intervalMs: 500,
25
55
  minIntervalMs: 100,
@@ -3,6 +3,7 @@ import path from 'node:path'
3
3
  import yaml from 'yaml'
4
4
 
5
5
  import { packageDefaults } from '../paths.mjs'
6
+ import { getRuntimeTooling, RuntimeEnum, BundlerEnum, detectCliHostRuntime } from './cli-runtime.mjs'
6
7
  import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
7
8
  import {
8
9
  normalizeTmpDocument,
@@ -233,17 +234,17 @@ export function resolveSourcemapFlag(buildConfig = {}, tsconfig = null) {
233
234
  return ''
234
235
  }
235
236
 
236
- function resolveTscBin(runtime = 'bun') {
237
- return runtime === 'node' ? 'npx tsc' : 'bunx tsc'
237
+ function resolveTscBin(runtime = detectCliHostRuntime()) {
238
+ return getRuntimeTooling(runtime).tscBin
238
239
  }
239
240
 
240
- function withTscProject(root, buildConfig, extraArgs, runtime = 'bun') {
241
+ function withTscProject(root, buildConfig, extraArgs, runtime = detectCliHostRuntime()) {
241
242
  const tsconfigRel = resolveTsconfigRel(root, buildConfig)
242
243
  const projectFlag = tsconfigRel ? `--project ${tsconfigRel} ` : ''
243
244
  return `${resolveTscBin(runtime)} ${projectFlag}${extraArgs}`.replace(/\s+/g, ' ').trim()
244
245
  }
245
246
 
246
- export function resolveTypecheckCommand(root, buildConfig = {}, runtime = 'bun') {
247
+ export function resolveTypecheckCommand(root, buildConfig = {}, runtime = detectCliHostRuntime()) {
247
248
  const tsconfigRel = resolveTsconfigRel(root, buildConfig)
248
249
  if (!tsconfigRel) {
249
250
  throw new Error(
@@ -253,7 +254,7 @@ export function resolveTypecheckCommand(root, buildConfig = {}, runtime = 'bun')
253
254
  return withTscProject(root, buildConfig, '--noEmit', runtime)
254
255
  }
255
256
 
256
- export function resolveTscCommand(root, distRel, buildConfig = {}, runtime = 'bun') {
257
+ export function resolveTscCommand(root, distRel, buildConfig = {}, runtime = detectCliHostRuntime()) {
257
258
  const cmd = withTscProject(root, buildConfig, `--emitDeclarationOnly --declaration --outDir ${distRel}`, runtime)
258
259
  return buildConfig.tscLenient ? `${cmd} || true` : cmd
259
260
  }
@@ -265,30 +266,30 @@ export function resolveBunBuildCommand(entryGlobs, distRel, buildConfig = {}, ts
265
266
  return `bun build ${entryGlobs.join(' ')} ${flags.join(' ')}`.replace(/\s+/g, ' ').trim()
266
267
  }
267
268
 
268
- export function resolveTscBuildCommand(root, distRel, buildConfig = {}, runtime = 'bun') {
269
+ export function resolveTscBuildCommand(root, distRel, buildConfig = {}, runtime = detectCliHostRuntime()) {
269
270
  return withTscProject(root, buildConfig, `--outDir ${distRel}`, runtime)
270
271
  }
271
272
 
272
- export function resolveEsbuildBuildCommand(entryGlobs, distRel, buildConfig = {}, tsconfig = null, runtime = 'bun') {
273
+ export function resolveEsbuildBuildCommand(entryGlobs, distRel, buildConfig = {}, tsconfig = null, runtime = detectCliHostRuntime()) {
273
274
  const minify = resolveMinifyEnabled(buildConfig) ? ' --minify' : ''
274
275
  const sourcemapFlag = resolveSourcemapFlag(buildConfig, tsconfig)
275
276
  const sourcemap = sourcemapFlag ? ' --sourcemap' : ''
276
- const bin = runtime === 'node' ? 'npx esbuild' : 'bunx esbuild'
277
+ const bin = getRuntimeTooling(runtime).esbuildBin
277
278
  const entries = entryGlobs.join(' ')
278
279
  return `${bin} ${entries} --bundle --platform=node --packages=external --outdir=${distRel}${minify}${sourcemap}`.replace(/\s+/g, ' ').trim()
279
280
  }
280
281
 
281
- export function resolveServiceBundleCommand(root, plan, buildConfig = {}, runtime = 'bun', bundler = 'bun') {
282
- if (bundler === 'tsc') {
282
+ export function resolveServiceBundleCommand(root, plan, buildConfig = {}, runtime = detectCliHostRuntime(), bundler = normalizeBundler('bun')) {
283
+ if (bundler === BundlerEnum.TSC) {
283
284
  return resolveTscBuildCommand(root, plan.distRel, buildConfig, runtime)
284
285
  }
285
- if (bundler === 'esbuild') {
286
+ if (bundler === BundlerEnum.ESBUILD) {
286
287
  return resolveEsbuildBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig, runtime)
287
288
  }
288
289
  return resolveBunBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig)
289
290
  }
290
291
 
291
- export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}, runtime = 'bun') {
292
+ export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}, runtime = detectCliHostRuntime()) {
292
293
  const tsconfig = readTsconfigJson(root, buildConfig)
293
294
  const distRel = resolveDistRelWithTsconfig(root, layout, buildConfig, tsconfig)
294
295
  const entryGlobs = resolveBuildEntryGlobs(layout.mainFolderPath, buildConfig, tsconfig)
@@ -340,7 +341,7 @@ export function resolveCoreBuildSteps(root, distRel, buildConfig = {}) {
340
341
  return steps
341
342
  }
342
343
 
343
- export function resolveServiceBuildSteps(root, layout, buildConfig = {}, runtime = 'bun') {
344
+ export function resolveServiceBuildSteps(root, layout, buildConfig = {}, runtime = detectCliHostRuntime()) {
344
345
  const plan = resolveEffectiveBuildOptions(root, layout, buildConfig, runtime)
345
346
  const steps = []
346
347
 
@@ -360,7 +361,7 @@ export function resolveServiceBuildSteps(root, layout, buildConfig = {}, runtime
360
361
  return steps
361
362
  }
362
363
 
363
- export function summarizeBuildPlan(root, layout, buildConfig = {}, runtime = 'bun') {
364
+ export function summarizeBuildPlan(root, layout, buildConfig = {}, runtime = detectCliHostRuntime()) {
364
365
  const plan = resolveEffectiveBuildOptions(root, layout, buildConfig, runtime)
365
366
  return {
366
367
  distRel: plan.distRel,
@@ -394,15 +395,16 @@ export function resolveEnvFiles(envDir, names) {
394
395
  }
395
396
 
396
397
 
397
- export function resolveRuntimeRunner(runtime = 'bun') {
398
- return runtime === 'node' ? 'node' : 'bun'
398
+ export function resolveRuntimeRunner(runtime = detectCliHostRuntime()) {
399
+ return getRuntimeTooling(runtime).binRunner
399
400
  }
400
401
 
401
- export function resolvePackageScriptRunner(runtime = 'bun') {
402
- return runtime === 'node' ? 'npm run' : 'bun run'
402
+ export function resolvePackageScriptRunner(runtime = detectCliHostRuntime()) {
403
+ return getRuntimeTooling(runtime).scriptRunner
403
404
  }
404
405
 
405
- export function resolveTestCommand(runtime = 'bun', target) {
406
- if (runtime === 'node') return `node --test ${target}`
407
- return `bun test ${target}`
406
+ export function resolveTestCommand(runtime = detectCliHostRuntime(), target) {
407
+ return `${getRuntimeTooling(runtime).testRunner} ${target}`.trim()
408
408
  }
409
+
410
+ export { RuntimeEnum, detectCliHostRuntime, getRuntimeTooling }
@@ -0,0 +1,84 @@
1
+ import fs from 'node:fs'
2
+ import yaml from 'yaml'
3
+
4
+ import { packageDefaults, PACKAGE_NAME } from './package-defaults.mjs'
5
+ import { normalizeRuntime, normalizeTmpDocument, readTmpGlobalBlock } from './tmp-schema.mjs'
6
+ import { ensureTmpFile } from './tmp-layout.mjs'
7
+
8
+ /** Runtime ids = keys of defaults.runtimes (aligned with RuntimeEnum). */
9
+ export const RuntimeEnum = Object.freeze(
10
+ Object.fromEntries(
11
+ Object.keys(packageDefaults.runtimes).map((key) => [key.toUpperCase(), key]),
12
+ ),
13
+ )
14
+
15
+ /** Bundler ids = defaults.bundlers (aligned with BundlerEnum). */
16
+ export const BundlerEnum = Object.freeze(
17
+ Object.fromEntries(
18
+ packageDefaults.bundlers.map((key) => [String(key).toUpperCase(), key]),
19
+ ),
20
+ )
21
+
22
+ export function detectCliHostRuntime() {
23
+ const bunKey = RuntimeEnum.BUN
24
+ const nodeKey = RuntimeEnum.NODE
25
+ if (!bunKey || !nodeKey) {
26
+ throw new Error(`${PACKAGE_NAME}: defaults.runtimes must define bun and node`)
27
+ }
28
+ return process.versions.bun ? bunKey : nodeKey
29
+ }
30
+
31
+ export function getRuntimeTooling(runtime) {
32
+ const key = normalizeRuntime(runtime)
33
+ const tooling = packageDefaults.runtimes?.[key]
34
+ if (!tooling) {
35
+ throw new Error(
36
+ `${PACKAGE_NAME}: defaults.runtimes.${key} missing — add it to defaults.json`,
37
+ )
38
+ }
39
+ return tooling
40
+ }
41
+
42
+ /** Project runtime from tmp.yml configs.global.runtime. */
43
+ export function resolveProjectRuntime(root = process.cwd()) {
44
+ const { tmpFilePath } = ensureTmpFile(root)
45
+ const raw = yaml.parse(fs.readFileSync(tmpFilePath, 'utf8'))
46
+ const normalized = normalizeTmpDocument(raw)
47
+ const global = readTmpGlobalBlock(normalized.configs)
48
+ return normalizeRuntime(global.runtime)
49
+ }
50
+
51
+ export function resolveDevCommand(cliName, runtime = detectCliHostRuntime()) {
52
+ const tooling = getRuntimeTooling(runtime)
53
+ if (tooling.devInvoker) return `${tooling.devInvoker} ${cliName} dev`
54
+ return `${cliName} dev`
55
+ }
56
+
57
+ /**
58
+ * CLI UX context: banner/project runtime from tmp; install tooling from host process.
59
+ */
60
+ export function resolveCliContext({ cliName, root = process.cwd() } = {}) {
61
+ const hostRuntime = detectCliHostRuntime()
62
+ const hostTooling = getRuntimeTooling(hostRuntime)
63
+
64
+ let projectRuntime = hostRuntime
65
+ let projectTooling = hostTooling
66
+ try {
67
+ projectRuntime = resolveProjectRuntime(root)
68
+ projectTooling = getRuntimeTooling(projectRuntime)
69
+ } catch {
70
+ // create / pre-tmp flows: host only until tmp.yml exists
71
+ }
72
+
73
+ return {
74
+ cliName,
75
+ runtime: projectRuntime,
76
+ hostRuntime,
77
+ runtimeName: projectTooling.label,
78
+ packageManager: hostTooling.packageManager,
79
+ installCommand: hostTooling.installCommand,
80
+ devCommand: resolveDevCommand(cliName, hostRuntime),
81
+ tooling: projectTooling,
82
+ hostTooling,
83
+ }
84
+ }
@@ -10,22 +10,102 @@ import {
10
10
  const here = path.dirname(fileURLToPath(import.meta.url))
11
11
  const packageRoot = path.resolve(here, '..', '..', '..')
12
12
 
13
- const AUTHORED_DEFAULTS = path.join(packageRoot, 'source', 'utils', 'constants', 'defaults.json')
13
+ const REQUIRED_IDENTITY_KEYS = [
14
+ 'packageName',
15
+ 'packageRootFolder',
16
+ 'cliName',
17
+ 'cliBinFile',
18
+ ]
19
+
20
+ function findAuthoredDefaultsPath(root) {
21
+ const matches = []
22
+
23
+ function walk(dir, depth = 0) {
24
+ if (depth > 6 || !fs.existsSync(dir)) return
25
+ let entries
26
+ try {
27
+ entries = fs.readdirSync(dir, { withFileTypes: true })
28
+ } catch {
29
+ return
30
+ }
31
+ for (const entry of entries) {
32
+ if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'x') continue
33
+ const full = path.join(dir, entry.name)
34
+ if (entry.isDirectory()) {
35
+ walk(full, depth + 1)
36
+ continue
37
+ }
38
+ if (entry.name === 'defaults.json' && full.replace(/\\/g, '/').endsWith('utils/constants/defaults.json')) {
39
+ matches.push(full)
40
+ }
41
+ }
42
+ }
43
+
44
+ walk(root)
45
+ return matches[0] ?? null
46
+ }
47
+
48
+ function assertIdentityDefaults(raw, sourceLabel) {
49
+ const missing = REQUIRED_IDENTITY_KEYS.filter((key) => {
50
+ const value = raw?.[key]
51
+ return value == null || String(value).trim() === ''
52
+ })
53
+ if (missing.length > 0) {
54
+ throw new Error(
55
+ `package defaults incomplete (${sourceLabel}): missing ${missing.join(', ')}`,
56
+ )
57
+ }
58
+ if (!Array.isArray(raw.cliBinNames) || raw.cliBinNames.length === 0) {
59
+ if (!raw.cliName) {
60
+ throw new Error(`package defaults incomplete (${sourceLabel}): cliBinNames or cliName required`)
61
+ }
62
+ }
63
+ const runtimes = raw.runtimes
64
+ if (!runtimes || typeof runtimes !== 'object') {
65
+ throw new Error(`package defaults incomplete (${sourceLabel}): runtimes map required`)
66
+ }
67
+ for (const key of Object.keys(runtimes)) {
68
+ const entry = runtimes[key]
69
+ for (const field of ['label', 'packageManager', 'installCommand', 'scriptRunner', 'binRunner', 'testRunner', 'tscBin', 'esbuildBin']) {
70
+ if (entry?.[field] == null || String(entry[field]).trim() === '') {
71
+ throw new Error(`package defaults incomplete (${sourceLabel}): runtimes.${key}.${field}`)
72
+ }
73
+ }
74
+ }
75
+ if (!Array.isArray(raw.bundlers) || raw.bundlers.length === 0) {
76
+ throw new Error(`package defaults incomplete (${sourceLabel}): bundlers list required`)
77
+ }
78
+ }
14
79
 
15
80
  function loadRawDefaults() {
16
- if (fs.existsSync(AUTHORED_DEFAULTS)) {
17
- return JSON.parse(fs.readFileSync(AUTHORED_DEFAULTS, 'utf8'))
81
+ const authoredPath = findAuthoredDefaultsPath(packageRoot)
82
+ if (authoredPath && fs.existsSync(authoredPath)) {
83
+ const raw = JSON.parse(fs.readFileSync(authoredPath, 'utf8'))
84
+ assertIdentityDefaults(raw, authoredPath)
85
+ return raw
18
86
  }
19
87
  if (packageIdentityDefaults && typeof packageIdentityDefaults === 'object') {
88
+ assertIdentityDefaults(packageIdentityDefaults, 'embedded packageIdentityDefaults')
20
89
  return packageIdentityDefaults
21
90
  }
22
91
  throw new Error(
23
- `package defaults missing. Expected authored ${AUTHORED_DEFAULTS} or embedded packageIdentityDefaults`,
92
+ 'package defaults missing. Expected utils/constants/defaults.json in package root or embedded packageIdentityDefaults',
24
93
  )
25
94
  }
26
95
 
27
96
  const raw = loadRawDefaults()
28
97
  const seed = loadSeedLayoutFromBundledTmp(packageRoot, raw)
98
+ if (!seed?.mainSourceFolder || !String(seed.mainSourceFolder).trim()) {
99
+ throw new Error(
100
+ `${raw.packageName}: bundled tmp seed missing paths.source — cannot resolve main source folder`,
101
+ )
102
+ }
103
+
104
+ const frozenRuntimes = Object.freeze(
105
+ Object.fromEntries(
106
+ Object.entries(raw.runtimes).map(([key, value]) => [key, Object.freeze({ ...value })]),
107
+ ),
108
+ )
29
109
 
30
110
  export const packageDefaults = Object.freeze({
31
111
  ...raw,
@@ -33,6 +113,8 @@ export const packageDefaults = Object.freeze({
33
113
  framework: seed.framework,
34
114
  layoutPaths: seed.layoutPaths,
35
115
  brand: Object.freeze({ ...(raw.brand ?? {}) }),
116
+ runtimes: frozenRuntimes,
117
+ bundlers: Object.freeze([...raw.bundlers]),
36
118
  buildDefaults: Object.freeze({ ...(raw.buildDefaults ?? {}) }),
37
119
  tmpWatchDefaults: Object.freeze({ ...(raw.tmpWatchDefaults ?? {}) }),
38
120
  cliBinNames: Object.freeze([...(raw.cliBinNames ?? [raw.cliName])]),
@@ -46,7 +128,7 @@ export const semverVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9
46
128
  export const PACKAGE_NAME = packageDefaults.packageName
47
129
  export const CLI_PRIMARY_NAME = packageDefaults.cliName
48
130
  export const CLI_BIN_NAMES = packageDefaults.cliBinNames
49
- export const CLI_BIN_FILE = packageDefaults.cliBinFile ?? 'main-cli.js'
131
+ export const CLI_BIN_FILE = packageDefaults.cliBinFile
50
132
 
51
133
  /** Commander / banner description from brand SSOT. */
52
134
  export function packageCliDescription() {
@@ -54,7 +136,10 @@ export function packageCliDescription() {
54
136
  const title = [brand.primary, brand.secondary].filter(Boolean).join(' ')
55
137
  const tagline = brand.tagline ? String(brand.tagline) : ''
56
138
  if (title && tagline) return `${title} — ${tagline}`
57
- return tagline || PACKAGE_NAME
139
+ if (!tagline) {
140
+ throw new Error(`${PACKAGE_NAME}: brand.tagline missing in defaults`)
141
+ }
142
+ return tagline
58
143
  }
59
144
 
60
145
  /** Log / error prefix: always the npm package name. */
@@ -64,12 +149,19 @@ export function packageLogTag() {
64
149
 
65
150
  /** Relative bin entry for package.json / manifests. */
66
151
  export function resolveCliBinEntry() {
152
+ if (!packageDefaults.packageRootFolder || !CLI_BIN_FILE) {
153
+ throw new Error(`${PACKAGE_NAME}: packageRootFolder/cliBinFile missing — check defaults.json`)
154
+ }
67
155
  return `./${packageDefaults.packageRootFolder}/bin/${CLI_BIN_FILE}`
68
156
  }
69
157
 
70
- /** Authored main source folder segment without ./ */
158
+ /** Main source folder segment from tmp seed (no silent fallback). */
71
159
  export function resolveMainSourceRel() {
72
- return String(packageDefaults.mainSourceFolder ?? 'source').replace(/^\.\//, '')
160
+ const folder = packageDefaults.mainSourceFolder
161
+ if (!folder || !String(folder).trim()) {
162
+ throw new Error(`${PACKAGE_NAME}: paths.source missing from tmp seed — run sync / fix tmp.yml`)
163
+ }
164
+ return String(folder).replace(/^\.\//, '')
73
165
  }
74
166
 
75
167
  export function resolveInvokedAs(argv = process.argv) {
@@ -1,12 +1,21 @@
1
+ import { packageDefaults } from './package-defaults.mjs'
1
2
  import { execSync } from 'node:child_process'
2
3
  import fs from 'node:fs'
3
4
  import os from 'node:os'
4
5
  import path from 'node:path'
5
6
 
7
+ function runtimeExecutable(key) {
8
+ const tooling = packageDefaults.runtimes?.[key]
9
+ if (!tooling) {
10
+ throw new Error(`defaults.runtimes.${key} missing`)
11
+ }
12
+ return { key, label: tooling.label, cmd: tooling.binRunner }
13
+ }
14
+
6
15
  const EXECUTABLES = [
7
- { key: 'node', label: 'Node.js', cmd: 'node' },
8
- { key: 'bun', label: 'Bun', cmd: 'bun' },
9
- { key: 'npm', label: 'npm', cmd: 'npm' },
16
+ runtimeExecutable('node'),
17
+ runtimeExecutable('bun'),
18
+ { key: packageDefaults.runtimes.node.packageManager, label: packageDefaults.runtimes.node.packageManager, cmd: packageDefaults.runtimes.node.packageManager },
10
19
  { key: 'pnpm', label: 'pnpm', cmd: 'pnpm' },
11
20
  { key: 'yarn', label: 'Yarn', cmd: 'yarn' },
12
21
  { key: 'deno', label: 'Deno', cmd: 'deno' },
@@ -130,7 +139,7 @@ export function detectPackageManager(root = process.cwd()) {
130
139
  export function resolveRuntimeInfo(root = process.cwd()) {
131
140
  const bunEmbedded = process.versions.bun
132
141
  const cliHost = bunEmbedded ? 'bun' : 'node'
133
- const cliHostLabel = bunEmbedded ? 'Bun' : 'Node.js'
142
+ const cliHostLabel = bunEmbedded ? packageDefaults.runtimes.bun.label : packageDefaults.runtimes.node.label
134
143
  const cliHostVersion = bunEmbedded
135
144
  ? normalizeSemver(bunEmbedded)
136
145
  : normalizeSemver(process.version.replace(/^v/, ''))
package/x/bin/main-cli.js CHANGED
@@ -19,25 +19,21 @@ import {
19
19
  } from './helpers/cli-identity.mjs'
20
20
  import { readCliPackageJson, getProjectRoot } from './helpers/project-root.mjs'
21
21
  import { ensureProjectArtifacts } from './helpers/project-artifacts.mjs'
22
+ import { resolveCliContext } from './helpers/cli-runtime.mjs'
22
23
 
23
24
  const pkg = readCliPackageJson()
25
+ const projectRoot = getProjectRoot()
24
26
 
25
27
  try {
26
- ensureProjectArtifacts(getProjectRoot(), { writeToolchain: false, writeManifest: false })
28
+ ensureProjectArtifacts(projectRoot, { writeToolchain: false, writeManifest: false })
27
29
  } catch {
28
30
  }
29
31
 
30
32
  const cliName = resolveInvokedAs()
31
-
32
- const isBun = !!process.versions.bun
33
- const runtimeName = isBun ? 'Bun' : 'Node.js'
34
- const packageManager = isBun ? 'bun' : 'npm'
35
- const installCommand = isBun ? 'bun install' : 'npm install'
36
- const devCommand = isBun ? `${cliName} dev` : `npx ${cliName} dev`
37
- const cliContext = { cliName, runtimeName, packageManager, installCommand, devCommand }
33
+ const cliContext = resolveCliContext({ cliName, root: projectRoot })
38
34
 
39
35
  if (shouldShowBanner()) {
40
- printBanner({ version: pkg.version, runtimeName, invokedAs: cliName })
36
+ printBanner({ version: pkg.version, runtimeName: cliContext.runtimeName, invokedAs: cliName })
41
37
  }
42
38
 
43
39
  if (isRootHelpRequest()) {
@@ -19,6 +19,36 @@
19
19
  "tagline": "microservice runtime library",
20
20
  "capabilities": "loaders \u00b7 tmp.yml \u00b7 dto \u00b7 i18n \u00b7 multi-protocol \u00b7 scaffold"
21
21
  },
22
+ "runtimes": {
23
+ "bun": {
24
+ "label": "Bun",
25
+ "packageManager": "bun",
26
+ "installCommand": "bun install",
27
+ "scriptRunner": "bun run",
28
+ "binRunner": "bun",
29
+ "testRunner": "bun test",
30
+ "tscBin": "bunx tsc",
31
+ "esbuildBin": "bunx esbuild",
32
+ "devInvoker": null
33
+ },
34
+ "node": {
35
+ "label": "Node.js",
36
+ "packageManager": "npm",
37
+ "installCommand": "npm install",
38
+ "scriptRunner": "npm run",
39
+ "binRunner": "node",
40
+ "testRunner": "node --test",
41
+ "tscBin": "npx tsc",
42
+ "esbuildBin": "npx esbuild",
43
+ "devInvoker": "npx"
44
+ }
45
+ },
46
+ "bundlers": [
47
+ "auto",
48
+ "bun",
49
+ "tsc",
50
+ "esbuild"
51
+ ],
22
52
  "tmpWatchDefaults": {
23
53
  "intervalMs": 500,
24
54
  "minIntervalMs": 100,
@@ -1 +1 @@
1
- import n from"node:path";import{packageRootDir as q}from"../../utils/package-root";import b from"./defaults.json" with { type: 'json' };import{seedFromTmp as j}from"../../utils/helpers/tmp/seed-from-tmp";export const packageDefaults=Object.freeze({...b,mainSourceFolder:j.sourceFolder,framework:j.framework,layoutPaths:Object.freeze({...j.layout}),brand:Object.freeze({...b.brand}),buildDefaults:Object.freeze({...b.buildDefaults}),tmpWatchDefaults:Object.freeze({...b.tmpWatchDefaults}),cliBinNames:Object.freeze([...b.cliBinNames??[b.cliName]])}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const v=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static cliName=packageDefaults.cliName;static cliBinNames=packageDefaults.cliBinNames;static pathAliasKey=packageDefaults.pathAliasKey;static brand=packageDefaults.brand;static mainSourceFolder=packageDefaults.mainSourceFolder;static framework=packageDefaults.framework;static layoutPaths=packageDefaults.layoutPaths;static cliBinFile=packageDefaults.cliBinFile??"main-cli.js";static logTag=packageDefaults.packageName;static bundledCoreTmpPath=n.join(q,packageDefaults.packageRootFolder,v)}export{seedFromTmp,loadSeedFromBundledTmp}from"../../utils/helpers/tmp/seed-from-tmp";
1
+ import w from"node:path";import{packageRootDir as x}from"../../utils/package-root";import b from"./defaults.json" with { type: 'json' };import{seedFromTmp as j}from"../../utils/helpers/tmp/seed-from-tmp";export const packageDefaults=Object.freeze({...b,mainSourceFolder:j.sourceFolder,framework:j.framework,layoutPaths:Object.freeze({...j.layout}),brand:Object.freeze({...b.brand}),runtimes:Object.freeze(Object.fromEntries(Object.entries(b.runtimes).map(([n,q])=>[n,Object.freeze({...q})]))),bundlers:Object.freeze([...b.bundlers]),buildDefaults:Object.freeze({...b.buildDefaults}),tmpWatchDefaults:Object.freeze({...b.tmpWatchDefaults}),cliBinNames:Object.freeze([...b.cliBinNames??[b.cliName]])}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const z=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static cliName=packageDefaults.cliName;static cliBinNames=packageDefaults.cliBinNames;static pathAliasKey=packageDefaults.pathAliasKey;static brand=packageDefaults.brand;static mainSourceFolder=packageDefaults.mainSourceFolder;static framework=packageDefaults.framework;static layoutPaths=packageDefaults.layoutPaths;static cliBinFile=packageDefaults.cliBinFile;static logTag=packageDefaults.packageName;static bundledCoreTmpPath=w.join(x,packageDefaults.packageRootFolder,z)}export{seedFromTmp,loadSeedFromBundledTmp}from"../../utils/helpers/tmp/seed-from-tmp";