@xrystal/core 3.42.0 → 3.44.0

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,26 +3,26 @@
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.42.0` · [npm](https://www.npmjs.com/package/@xrystal/core)
6
+ **CLI:** `xry` · **Version:** `3.44.0` · [npm](https://www.npmjs.com/package/@xrystal/core)
7
7
 
8
8
  ---
9
9
 
10
- ## What's new in 3.42.0 / 3.42.0'da ne değişti
10
+ ## What's new in 3.44.0 / 3.44.0'da ne değişti
11
11
 
12
12
  | Change / Değişiklik | EN | TR |
13
13
  |---------------------|----|----|
14
- | **Single config pipeline** | Author `source/.../defaults.json` + `x/tmp.yml`; build embeds into CLI `.generated` | Source config → build embed |
15
- | **No helpers/defaults.json copy** | npm reads identity from generated seed bundle | Ayrı publish kopyası yok |
16
- | **No hardcodes** | packageName / layout / brand from config seed | Hardcode yok |
17
- | **CLI** | `xry` · `xry sync` | `xry` · `xry sync` |
14
+ | **Layout auto-sync** | Path changes in `tmp.yml` → tsconfig heals live (and on any `xry` entry) | Klasör/path değişince tsconfig otomatik |
15
+ | **`xry sync`** | Force / dry-run / CI — not a daily ritual | Elle force; günlük zorunluluk değil |
16
+ | **CLI banner** | Leads with `@xrystal/core` (bin still `xry`) | Banner paket adıyla açılır |
17
+ | **Runtime coverage** | bun + node runners / bundler `auto` tested | Her iki runtime doğrulandı |
18
+
19
+ Carried from **3.43.0:** `configs.global.runtime` (`bun`\|`node`), `configs.global.vars`, `build.bundler` (`auto`\|`bun`\|`tsc`\|`esbuild`).
18
20
 
19
21
  ```bash
20
- npx xry sync # apply tmp.yml → tsconfig / bunfig aliases
22
+ npx xry sync # force-apply tmp.yml → tsconfig (usually auto)
21
23
  npx xry sync --dry-run
22
24
  ```
23
25
 
24
- **Breaking / Kırıcı:** replace scripts and docs that called `xcore`, `xrystal`, or the old `tmp` bin with `xry`.
25
-
26
26
  ---
27
27
 
28
28
  ## Why / Neden
@@ -35,7 +35,7 @@ npx xry sync --dry-run
35
35
  # EN: existing project — kernel only · TR: mevcut proje — sadece kernel
36
36
  bun add @xrystal/core
37
37
  npx xry tmp # seed x/tmp.yml into YOUR layout
38
- npx xry sync # align tsconfig paths with tmp.yml
38
+ # tsconfig paths auto-heal from tmp.yml (xry sync = force / CI)
39
39
  # wire coreLoader + dtoMiddleware in your entry file
40
40
  ```
41
41
 
@@ -73,7 +73,7 @@ mkdir my-api && cd my-api
73
73
  bun init -y
74
74
  bun add @xrystal/core elysia
75
75
  npx xry tmp # EN: create x/tmp.yml from seed if missing · TR: yoksa seed'den oluşturur
76
- npx xry sync # EN: tsconfig from tmp.yml · TR: tmp.yml → tsconfig
76
+ npx xry doctor # EN: optional health check · TR: isteğe bağlı sağlık kontrolü
77
77
  ```
78
78
 
79
79
  `package.json`:
@@ -81,7 +81,7 @@ npx xry sync # EN: tsconfig from tmp.yml · TR: tmp.yml → tsconfig
81
81
  ```json
82
82
  {
83
83
  "dependencies": {
84
- "@xrystal/core": "^3.42.0",
84
+ "@xrystal/core": "^3.44.0",
85
85
  "elysia": "^1.4.19"
86
86
  },
87
87
  "scripts": {
@@ -115,14 +115,16 @@ my-api/
115
115
 
116
116
  | File / Dosya | Owns / Sahip olduğu |
117
117
  |--------------|---------------------|
118
- | `x/tmp.yml` | Service paths, loaders, protocols, build flags · layout seed |
119
- | `tsconfig.json` | Compiler language options; path layout via `xry sync` |
120
- | Package defaults (internal) | CLI name (`xry`), package identity — not project layout |
118
+ | `x/tmp.yml` | Service paths, loaders, protocols, runtime, bundler · layout seed |
119
+ | `tsconfig.json` | Compiler language options; path layout auto-heals from `tmp.yml` |
120
+ | Package defaults (internal) | Package identity (`@xrystal/core`) + CLI bin (`xry`) — not project layout |
121
121
 
122
122
  ### Minimal `x/tmp.yml`
123
123
 
124
124
  ```yaml
125
125
  configs:
126
+ global:
127
+ runtime: bun # bun | node
126
128
  service:
127
129
  name: my-api
128
130
  framework: elysia # express | elysia | node | fetch
@@ -130,6 +132,8 @@ configs:
130
132
  root: ./x
131
133
  source: ./source
132
134
  protocols: [http]
135
+ build:
136
+ bundler: auto # auto | bun | tsc | esbuild
133
137
  loaders:
134
138
  dto: { withDefaultHeaders: true }
135
139
  loggers: { logLevel: info }
@@ -174,7 +178,7 @@ bun run dev
174
178
  |-----------------|----|----|
175
179
  | `xry create [name] [path]` | Start project from template + `tmp.yml` | Template + `tmp.yml` ile proje başlat |
176
180
  | `xry tmp` | Create `tmp.yml` from seed if missing | `tmp.yml` yoksa seed'den oluştur |
177
- | `xry sync` | Sync `tsconfig` / aliases from `tmp.yml` | `tmp.yml` → `tsconfig` / alias |
181
+ | `xry sync` | Force-sync `tsconfig` from `tmp.yml` (auto-heals otherwise) | Force sync (normalde otomatik) |
178
182
  | `xry dev` | Watch `source/index.ts` + dev env | `source/index.ts` watch + dev env |
179
183
  | `xry build` | Output → `x/dist` | Çıktı → `x/dist` |
180
184
  | `xry start` | Run `x/dist` + prod env | `x/dist` + prod env |
@@ -192,7 +196,7 @@ bun run dev
192
196
  | Feature / Özellik | EN | TR | Example / Örnek |
193
197
  |-------------------|----|----|-----------------|
194
198
  | **Boot / DI** | Awilix loaders: System, Logger, Kafka, Dto, i18n, … | Awilix loader'lar | `await coreLoader({})` |
195
- | **Live `tmp.yml`** | Edit file → loaders re-sync without restart | Dosya değişince loader sync | `logLevel: debug` → save → logger updates |
199
+ | **Live `tmp.yml`** | Edit file → loaders re-sync; path changes heal tsconfig | Dosya → loader sync; path → tsconfig heal | `paths.source` rename → tsconfig updates |
196
200
  | **`ctr()` pipeline** | `checks → logic → response`, no `res.json()` | Endpoint pipeline | `list = this.ctr({ logic: async () => ({ data: [] }) })` |
197
201
  | **DTO responses** | Standard API shape via `@xrystal/dto` | Standart API cevabı | `return { data: [], message: '@successfully user' }` |
198
202
  | **Trace** | `requestId` per request/job (ALS) | İstek/job trace id | `req.requestId` · `runWithTrace('job-1', fn)` |
@@ -542,13 +546,13 @@ Details / detay: [`@xrystal/dto`](https://www.npmjs.com/package/@xrystal/dto)
542
546
 
543
547
  ```
544
548
  1. Your repo + bun add @xrystal/core + xry tmp (or xry create for greenfield)
545
- 2. xry sync → tsconfig include / outDir / @/* from tmp.yml
546
- 3. tmp.yml → framework, loaders, paths
547
- 4. coreLoader() → once at top of YOUR index.ts
548
- 5. Controller → ctr() per endpoint
549
- 6. Framework → dtoMiddleware + routes
550
- 7. xry dev → develop
551
- 8. xry build → start → production
549
+ 2. tmp.yml → framework, runtime, loaders, paths (tsconfig auto-heals)
550
+ 3. coreLoader() → once at top of YOUR index.ts
551
+ 4. Controller → ctr() per endpoint
552
+ 5. Framework → dtoMiddleware + routes
553
+ 6. xry dev → develop
554
+ 7. xry build → start → production
555
+ 8. xry sync → only when you need a force / dry-run / CI pin
552
556
  ```
553
557
 
554
558
  ### Express — end-to-end / uçtan uca
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.42.0",
4
+ "version": "3.44.0",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -11,7 +11,10 @@ import {
11
11
  resolveDevEntry,
12
12
  resolveDistEntryAbs,
13
13
  resolveEnvFiles,
14
+ resolvePackageScriptRunner,
15
+ resolveRuntimeRunner,
14
16
  resolveServiceBuildSteps,
17
+ resolveTestCommand,
15
18
  shouldDelegatePackageBuild,
16
19
  summarizeBuildPlan,
17
20
  } from '../helpers/build-config.mjs'
@@ -41,39 +44,45 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
41
44
  .description('Watch source/index.ts with dev env files')
42
45
  .action(() => {
43
46
  const root = getProjectRoot()
44
- const { layout } = readTmpBuildContext(root)
47
+ const { layout, runtime } = readTmpBuildContext(root)
45
48
  const entry = resolveDevEntry(root, layout)
46
49
  const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.dev.env'])
47
50
  const envArgs = envFiles.map((file) => `--env-file=${file}`).join(' ')
51
+ const runner = resolveRuntimeRunner(runtime)
48
52
 
49
53
  printCommandHeader({ cliName, command: 'dev', version: readCliPackageJson().version })
50
54
  console.log(chalk.gray(` root: ${root}`))
55
+ console.log(chalk.gray(` runtime: ${runtime}`))
51
56
  console.log(chalk.gray(` entry: ${entry} (.ts)\n`))
52
- runInProject(root, `bun --watch ${envArgs} ${entry}`.trim())
57
+ runInProject(root, `${runner} --watch ${envArgs} ${entry}`.trim())
53
58
  })
54
59
 
55
60
  cli
56
61
  .command('build')
57
- .description('Bundle to dist/ (Bun + optional tsc)')
62
+ .description('Bundle to dist/ (bundler from tmp.yml)')
58
63
  .action(() => {
59
64
  const root = getProjectRoot()
60
65
  ensureProjectArtifacts(root, { writeToolchain: true, writeManifest: true })
61
66
  const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
67
+ const { layout, build, runtime, bundler } = readTmpBuildContext(root)
62
68
 
63
69
  printCommandHeader({ cliName, command: 'build', version: readCliPackageJson().version })
64
70
  console.log(chalk.gray(` root: ${root}`))
65
71
 
66
72
  if (shouldDelegatePackageBuild(pkg)) {
67
- runInProject(root, 'bun run build')
73
+ runInProject(root, `${resolvePackageScriptRunner(runtime)} build`)
68
74
  return
69
75
  }
70
76
 
71
- const { layout, build } = readTmpBuildContext(root)
72
- const plan = summarizeBuildPlan(root, layout, build)
77
+ const plan = summarizeBuildPlan(root, layout, build, runtime)
73
78
  const steps = isCorePackageName(pkg.name)
74
79
  ? resolveCoreBuildSteps(root, plan.distRel, build)
75
- : resolveServiceBuildSteps(root, layout, build)
80
+ : resolveServiceBuildSteps(root, layout, build, runtime)
76
81
  console.log(chalk.gray(` mode: ${isCorePackageName(pkg.name) ? 'core entries' : 'service tsconfig + tmp overrides'}`))
82
+ console.log(chalk.gray(` runtime: ${runtime}`))
83
+ if (!isCorePackageName(pkg.name)) {
84
+ console.log(chalk.gray(` bundler: ${plan.bundler || bundler}`))
85
+ }
77
86
  if (plan.tsconfigRel) {
78
87
  console.log(chalk.gray(` tsconfig: ${plan.tsconfigRel}`))
79
88
  }
@@ -94,7 +103,7 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
94
103
  .description('Run dist/index.js with prod env files')
95
104
  .action(() => {
96
105
  const root = getProjectRoot()
97
- const { layout, build } = readTmpBuildContext(root)
106
+ const { layout, build, runtime } = readTmpBuildContext(root)
98
107
  const entryAbs = resolveDistEntryAbs(root, layout, build)
99
108
 
100
109
  if (!fs.existsSync(entryAbs)) {
@@ -106,11 +115,13 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
106
115
  const entry = relativeFromRoot(root, entryAbs)
107
116
  const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.prod.env'])
108
117
  const envArgs = envFiles.map((file) => `--env-file=${file}`).join(' ')
118
+ const runner = resolveRuntimeRunner(runtime)
109
119
 
110
120
  printCommandHeader({ cliName, command: 'start', version: readCliPackageJson().version })
111
121
  console.log(chalk.gray(` root: ${root}`))
122
+ console.log(chalk.gray(` runtime: ${runtime}`))
112
123
  console.log(chalk.gray(` entry: ${entry} (.js)\n`))
113
- runInProject(root, `bun ${envArgs} ${entry}`.trim())
124
+ runInProject(root, `${runner} ${envArgs} ${entry}`.trim())
114
125
  })
115
126
 
116
127
  cli
@@ -118,10 +129,12 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
118
129
  .description('Run tests from tmp.yml paths')
119
130
  .action(() => {
120
131
  const root = getProjectRoot()
132
+ const { runtime } = readTmpBuildContext(root)
121
133
  const target = resolveTestTarget(root)
122
134
 
123
135
  printCommandHeader({ cliName, command: 'test', version: readCliPackageJson().version })
136
+ console.log(chalk.gray(` runtime: ${runtime}`))
124
137
  console.log(chalk.gray(` target: ${target}\n`))
125
- runInProject(root, `bun test ${target}`)
138
+ runInProject(root, resolveTestCommand(runtime, target))
126
139
  })
127
140
  }
@@ -42,7 +42,7 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
42
42
  cli
43
43
  .command('sync')
44
44
  .alias('sync-toolchain')
45
- .description('Sync tsconfig paths from tmp.yml')
45
+ .description('Force-sync tsconfig from tmp.yml (also auto-heals on layout path change / CLI entry)')
46
46
  .option('--dry-run', 'Preview without writing')
47
47
  .action(run)
48
48
  }
@@ -122,24 +122,81 @@ function loadSeedFromBundledTmp(tmpFilePath) {
122
122
  }
123
123
  var seedFromTmp = loadSeedFromBundledTmp();
124
124
 
125
- // source/utils/helpers/tmp/tmp-schema.ts
125
+ // source/utils/helpers/tmp/tmp-interpolate.ts
126
+ import Handlebars from "handlebars";
126
127
  function isRecord(value) {
127
128
  return typeof value === "object" && value !== null && !Array.isArray(value);
128
129
  }
130
+ function interpolateWithContext(value, context) {
131
+ if (typeof value === "string") {
132
+ if (!value.includes("{{"))
133
+ return value;
134
+ return Handlebars.compile(value)(context);
135
+ }
136
+ if (Array.isArray(value)) {
137
+ return value.map((item) => interpolateWithContext(item, context));
138
+ }
139
+ if (isRecord(value)) {
140
+ const next = {};
141
+ for (const [key, child] of Object.entries(value)) {
142
+ next[key] = interpolateWithContext(child, context);
143
+ }
144
+ return next;
145
+ }
146
+ return value;
147
+ }
148
+
149
+ // source/utils/helpers/tmp/tmp-schema.ts
150
+ function isRecord2(value) {
151
+ return typeof value === "object" && value !== null && !Array.isArray(value);
152
+ }
129
153
  function readWatchIntervalValue(raw) {
130
154
  if (typeof raw === "number" || typeof raw === "string")
131
155
  return raw;
132
156
  return;
133
157
  }
158
+ function normalizeRuntime(value) {
159
+ const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
160
+ if (raw === "node" /* NODE */)
161
+ return "node" /* NODE */;
162
+ if (raw === "bun" /* BUN */)
163
+ return "bun" /* BUN */;
164
+ return "bun" /* BUN */;
165
+ }
166
+ function normalizeBundler(value) {
167
+ const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
168
+ if (raw === "tsc" /* TSC */)
169
+ return "tsc" /* TSC */;
170
+ if (raw === "esbuild" /* ESBUILD */)
171
+ return "esbuild" /* ESBUILD */;
172
+ if (raw === "bun" /* BUN */)
173
+ return "bun" /* BUN */;
174
+ if (raw === "auto" /* AUTO */)
175
+ return "auto" /* AUTO */;
176
+ return "auto" /* AUTO */;
177
+ }
178
+ function resolveEffectiveBundler(bundler, runtime) {
179
+ if (bundler !== "auto" /* AUTO */)
180
+ return bundler;
181
+ return runtime === "node" /* NODE */ ? "tsc" /* TSC */ : "bun" /* BUN */;
182
+ }
134
183
  function normalizeRootFolder2(value) {
135
184
  return normalizeRootFolder(value, defaults_default.packageRootFolder);
136
185
  }
137
186
  function normalizeSourceFolder2(value) {
138
187
  return normalizeSourceFolder(value, seedFromTmp.sourceFolder);
139
188
  }
189
+ function readTmpGlobalBlock(configs) {
190
+ const global = isRecord2(configs?.global) ? configs.global : {};
191
+ const varsRaw = isRecord2(global.vars) ? global.vars : {};
192
+ return {
193
+ runtime: normalizeRuntime(global.runtime),
194
+ vars: { ...varsRaw }
195
+ };
196
+ }
140
197
  function readTmpCoreBlock(configs) {
141
- const core = isRecord(configs?.core) ? configs.core : {};
142
- const tmp = isRecord(core.tmp) ? core.tmp : {};
198
+ const core = isRecord2(configs?.core) ? configs.core : {};
199
+ const tmp = isRecord2(core.tmp) ? core.tmp : {};
143
200
  return {
144
201
  tmp: {
145
202
  fileWatchIntervalMs: readWatchIntervalValue(tmp.fileWatchIntervalMs)
@@ -147,15 +204,15 @@ function readTmpCoreBlock(configs) {
147
204
  };
148
205
  }
149
206
  function readTmpServiceBlock(configs) {
150
- const service = isRecord(configs?.service) ? configs.service : {};
151
- const pathsRaw = isRecord(service.paths) ? service.paths : {};
152
- const special = isRecord(pathsRaw.special) ? pathsRaw.special : {};
153
- let loaders = isRecord(service.loaders) ? { ...service.loaders } : undefined;
154
- let build = isRecord(service.build) ? service.build : undefined;
155
- if (loaders && isRecord(loaders.build)) {
207
+ const service = isRecord2(configs?.service) ? configs.service : {};
208
+ const pathsRaw = isRecord2(service.paths) ? service.paths : {};
209
+ const special = isRecord2(pathsRaw.special) ? pathsRaw.special : {};
210
+ let loaders = isRecord2(service.loaders) ? { ...service.loaders } : undefined;
211
+ let build = isRecord2(service.build) ? service.build : undefined;
212
+ if (loaders && isRecord2(loaders.build)) {
156
213
  const { build: nestedBuild, ...rest } = loaders;
157
214
  loaders = rest;
158
- if (!build && isRecord(nestedBuild)) {
215
+ if (!build && isRecord2(nestedBuild)) {
159
216
  build = nestedBuild;
160
217
  }
161
218
  }
@@ -201,29 +258,50 @@ function buildNormalizedCore(core) {
201
258
  }
202
259
  };
203
260
  }
261
+ function buildTmpVarContext(global) {
262
+ return {
263
+ ...global.vars,
264
+ runtime: global.runtime,
265
+ global
266
+ };
267
+ }
268
+ function applyTmpGlobalVars(tmp) {
269
+ const configs = isRecord2(tmp.configs) ? tmp.configs : {};
270
+ const global = readTmpGlobalBlock(configs);
271
+ return interpolateWithContext(tmp, buildTmpVarContext(global));
272
+ }
204
273
  function resolveTmpRuntimeConfigs(tmp) {
205
- const configs = isRecord(tmp?.configs) ? tmp.configs : {};
274
+ const configs = isRecord2(tmp?.configs) ? tmp.configs : {};
275
+ const global = readTmpGlobalBlock(configs);
206
276
  const service = readTmpServiceBlock(configs);
207
277
  const core = readTmpCoreBlock(configs);
208
278
  const normalizedService = buildNormalizedService(service);
209
279
  return {
280
+ global,
210
281
  service: normalizedService,
211
282
  core: buildNormalizedCore(core),
212
283
  rootFolderPath: normalizeRootFolder2(normalizedService.paths.root)
213
284
  };
214
285
  }
215
286
  function normalizeTmpDocument(tmp) {
287
+ const interpolated = applyTmpGlobalVars(tmp);
216
288
  return {
217
- ...tmp,
218
- configs: resolveTmpRuntimeConfigs(tmp)
289
+ ...interpolated,
290
+ configs: resolveTmpRuntimeConfigs(interpolated)
219
291
  };
220
292
  }
221
293
  export {
222
294
  resolveTmpRuntimeConfigs,
223
295
  resolveServiceLayoutPaths,
296
+ resolveEffectiveBundler,
224
297
  readTmpServiceBlock,
298
+ readTmpGlobalBlock,
225
299
  readTmpCoreBlock,
226
300
  normalizeTmpDocument,
227
301
  normalizeSourceFolder2 as normalizeSourceFolder,
228
- normalizeRootFolder2 as normalizeRootFolder
302
+ normalizeRuntime,
303
+ normalizeRootFolder2 as normalizeRootFolder,
304
+ normalizeBundler,
305
+ buildTmpVarContext,
306
+ applyTmpGlobalVars
229
307
  };
@@ -2,7 +2,6 @@ import chalk from 'chalk'
2
2
 
3
3
  import {
4
4
  CLI_BIN_NAMES,
5
- CLI_PRIMARY_NAME,
6
5
  packageDefaults,
7
6
  } from './package-defaults.mjs'
8
7
 
@@ -45,8 +44,7 @@ export function brandTitle() {
45
44
  return `${chalk.bold.white(`${primary} `)}${chalk.bold.magenta(secondary)}`
46
45
  }
47
46
 
48
- export function printBanner({ version, runtimeName, invokedAs } = {}) {
49
- const bin = invokedAs && invokedAs !== 'main-cli.js' ? invokedAs : CLI_PRIMARY_NAME
47
+ export function printBanner({ version, runtimeName, invokedAs: _invokedAs } = {}) {
50
48
  const versionLabel = version ? chalk.bold.green(`v${version}`) : chalk.gray('v?')
51
49
  const runtimeLabel = runtimeName ? chalk.bold.white(runtimeName) : ''
52
50
  const { tagline, capabilities } = brand()
@@ -57,19 +55,21 @@ export function printBanner({ version, runtimeName, invokedAs } = {}) {
57
55
  console.log(chalk.bold.gray(` ${tagline}`))
58
56
  console.log('')
59
57
  console.log(
60
- ` ${chalk.bold.cyan(bin)} ${chalk.gray('·')} ${chalk.bold(packageDefaults.packageName)} ${versionLabel}${runtimeLabel ? ` ${chalk.gray('·')} ${runtimeLabel}` : ''}`,
58
+ ` ${chalk.bold.cyan(packageDefaults.packageName)} ${versionLabel}${runtimeLabel ? ` ${chalk.gray('·')} ${runtimeLabel}` : ''}`,
61
59
  )
62
60
  console.log(chalk.bold.gray(` ${capabilities}`))
63
61
  console.log(chalk.dim(` cli: ${BIN_ALIASES_LABEL}`))
64
62
  console.log('')
65
63
  }
66
64
 
67
- export function printCommandHeader({ cliName, command, version } = {}) {
68
- const label = cliName || CLI_PRIMARY_NAME
65
+ export function printCommandHeader({ cliName: _cliName, command, version } = {}) {
69
66
  const versionLabel = version ? chalk.green(`v${version}`) : ''
67
+ const title = command
68
+ ? `${packageDefaults.packageName} ${command}`
69
+ : packageDefaults.packageName
70
70
  console.log('')
71
71
  console.log(
72
- `${chalk.bold.cyan(`${label} ${command}`)} ${chalk.gray('·')} ${brandTitle()} ${versionLabel}`.trim(),
72
+ `${chalk.bold.cyan(title)} ${chalk.gray('·')} ${brandTitle()} ${versionLabel}`.trim(),
73
73
  )
74
74
  }
75
75
 
@@ -4,7 +4,13 @@ import yaml from 'yaml'
4
4
 
5
5
  import { packageDefaults } from '../paths.mjs'
6
6
  import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
7
- import { normalizeTmpDocument, readTmpServiceBlock } from './tmp-schema.mjs'
7
+ import {
8
+ normalizeTmpDocument,
9
+ readTmpServiceBlock,
10
+ readTmpGlobalBlock,
11
+ normalizeBundler,
12
+ resolveEffectiveBundler,
13
+ } from './tmp-schema.mjs'
8
14
 
9
15
  import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
10
16
 
@@ -36,7 +42,9 @@ export function readTmpBuildContext(root) {
36
42
  const tmp = normalizeTmpDocument(yaml.parse(fs.readFileSync(ensured.tmpFilePath, 'utf8')))
37
43
  const configs = tmp.configs ?? {}
38
44
  const build = readTmpServiceBlock(configs).build ?? {}
39
- return { layout: ensured.layout, configs, build }
45
+ const global = readTmpGlobalBlock(configs)
46
+ const bundler = resolveEffectiveBundler(normalizeBundler(build.bundler), global.runtime)
47
+ return { layout: ensured.layout, configs, build, global, runtime: global.runtime, bundler }
40
48
  }
41
49
 
42
50
  export function normalizeMainFolder(mainFolderPath = packageDefaults.mainSourceFolder) {
@@ -225,24 +233,28 @@ export function resolveSourcemapFlag(buildConfig = {}, tsconfig = null) {
225
233
  return ''
226
234
  }
227
235
 
228
- function withTscProject(root, buildConfig, extraArgs) {
236
+ function resolveTscBin(runtime = 'bun') {
237
+ return runtime === 'node' ? 'npx tsc' : 'bunx tsc'
238
+ }
239
+
240
+ function withTscProject(root, buildConfig, extraArgs, runtime = 'bun') {
229
241
  const tsconfigRel = resolveTsconfigRel(root, buildConfig)
230
242
  const projectFlag = tsconfigRel ? `--project ${tsconfigRel} ` : ''
231
- return `bunx tsc ${projectFlag}${extraArgs}`.replace(/\s+/g, ' ').trim()
243
+ return `${resolveTscBin(runtime)} ${projectFlag}${extraArgs}`.replace(/\s+/g, ' ').trim()
232
244
  }
233
245
 
234
- export function resolveTypecheckCommand(root, buildConfig = {}) {
246
+ export function resolveTypecheckCommand(root, buildConfig = {}, runtime = 'bun') {
235
247
  const tsconfigRel = resolveTsconfigRel(root, buildConfig)
236
248
  if (!tsconfigRel) {
237
249
  throw new Error(
238
250
  'build.typecheck is enabled but tsconfig was not found. Set build.tsconfig or add tsconfig.json.',
239
251
  )
240
252
  }
241
- return withTscProject(root, buildConfig, '--noEmit')
253
+ return withTscProject(root, buildConfig, '--noEmit', runtime)
242
254
  }
243
255
 
244
- export function resolveTscCommand(root, distRel, buildConfig = {}) {
245
- const cmd = withTscProject(root, buildConfig, `--emitDeclarationOnly --declaration --outDir ${distRel}`)
256
+ export function resolveTscCommand(root, distRel, buildConfig = {}, runtime = 'bun') {
257
+ const cmd = withTscProject(root, buildConfig, `--emitDeclarationOnly --declaration --outDir ${distRel}`, runtime)
246
258
  return buildConfig.tscLenient ? `${cmd} || true` : cmd
247
259
  }
248
260
 
@@ -253,16 +265,42 @@ export function resolveBunBuildCommand(entryGlobs, distRel, buildConfig = {}, ts
253
265
  return `bun build ${entryGlobs.join(' ')} ${flags.join(' ')}`.replace(/\s+/g, ' ').trim()
254
266
  }
255
267
 
256
- export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}) {
268
+ export function resolveTscBuildCommand(root, distRel, buildConfig = {}, runtime = 'bun') {
269
+ return withTscProject(root, buildConfig, `--outDir ${distRel}`, runtime)
270
+ }
271
+
272
+ export function resolveEsbuildBuildCommand(entryGlobs, distRel, buildConfig = {}, tsconfig = null, runtime = 'bun') {
273
+ const minify = resolveMinifyEnabled(buildConfig) ? ' --minify' : ''
274
+ const sourcemapFlag = resolveSourcemapFlag(buildConfig, tsconfig)
275
+ const sourcemap = sourcemapFlag ? ' --sourcemap' : ''
276
+ const bin = runtime === 'node' ? 'npx esbuild' : 'bunx esbuild'
277
+ const entries = entryGlobs.join(' ')
278
+ return `${bin} ${entries} --bundle --platform=node --packages=external --outdir=${distRel}${minify}${sourcemap}`.replace(/\s+/g, ' ').trim()
279
+ }
280
+
281
+ export function resolveServiceBundleCommand(root, plan, buildConfig = {}, runtime = 'bun', bundler = 'bun') {
282
+ if (bundler === 'tsc') {
283
+ return resolveTscBuildCommand(root, plan.distRel, buildConfig, runtime)
284
+ }
285
+ if (bundler === 'esbuild') {
286
+ return resolveEsbuildBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig, runtime)
287
+ }
288
+ return resolveBunBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig)
289
+ }
290
+
291
+ export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}, runtime = 'bun') {
257
292
  const tsconfig = readTsconfigJson(root, buildConfig)
258
293
  const distRel = resolveDistRelWithTsconfig(root, layout, buildConfig, tsconfig)
259
294
  const entryGlobs = resolveBuildEntryGlobs(layout.mainFolderPath, buildConfig, tsconfig)
295
+ const bundler = resolveEffectiveBundler(normalizeBundler(buildConfig.bundler), runtime)
260
296
 
261
297
  return {
262
298
  tsconfig,
263
299
  tsconfigRel: tsconfig?.rel ?? null,
264
300
  distRel,
265
301
  entryGlobs,
302
+ runtime,
303
+ bundler,
266
304
  typecheck: resolveTypecheckEnabled(buildConfig),
267
305
  declarations: resolveDeclarationsEnabled(buildConfig, tsconfig),
268
306
  sourcemap: resolveSourcemapFlag(buildConfig, tsconfig) || 'false',
@@ -302,32 +340,34 @@ export function resolveCoreBuildSteps(root, distRel, buildConfig = {}) {
302
340
  return steps
303
341
  }
304
342
 
305
- export function resolveServiceBuildSteps(root, layout, buildConfig = {}) {
306
- const plan = resolveEffectiveBuildOptions(root, layout, buildConfig)
343
+ export function resolveServiceBuildSteps(root, layout, buildConfig = {}, runtime = 'bun') {
344
+ const plan = resolveEffectiveBuildOptions(root, layout, buildConfig, runtime)
307
345
  const steps = []
308
346
 
309
347
  if (plan.typecheck) {
310
- steps.push(resolveTypecheckCommand(root, buildConfig))
348
+ steps.push(resolveTypecheckCommand(root, buildConfig, runtime))
311
349
  }
312
350
 
313
351
  steps.push(
314
352
  `rm -rf ${plan.distRel}`,
315
- resolveBunBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig),
353
+ resolveServiceBundleCommand(root, plan, buildConfig, runtime, plan.bundler),
316
354
  )
317
355
 
318
- if (plan.declarations) {
319
- steps.push(resolveTscCommand(root, plan.distRel, buildConfig))
356
+ if (plan.declarations && plan.bundler !== 'tsc') {
357
+ steps.push(resolveTscCommand(root, plan.distRel, buildConfig, runtime))
320
358
  }
321
359
 
322
360
  return steps
323
361
  }
324
362
 
325
- export function summarizeBuildPlan(root, layout, buildConfig = {}) {
326
- const plan = resolveEffectiveBuildOptions(root, layout, buildConfig)
363
+ export function summarizeBuildPlan(root, layout, buildConfig = {}, runtime = 'bun') {
364
+ const plan = resolveEffectiveBuildOptions(root, layout, buildConfig, runtime)
327
365
  return {
328
366
  distRel: plan.distRel,
329
367
  entryGlobs: plan.entryGlobs,
330
368
  tsconfigRel: plan.tsconfigRel,
369
+ runtime: plan.runtime,
370
+ bundler: plan.bundler,
331
371
  typecheck: plan.typecheck,
332
372
  declarations: plan.declarations,
333
373
  sourcemap: plan.sourcemap,
@@ -352,3 +392,17 @@ export function resolveEnvFiles(envDir, names) {
352
392
  .map((name) => path.join(envDir, name))
353
393
  .filter((file) => fs.existsSync(file))
354
394
  }
395
+
396
+
397
+ export function resolveRuntimeRunner(runtime = 'bun') {
398
+ return runtime === 'node' ? 'node' : 'bun'
399
+ }
400
+
401
+ export function resolvePackageScriptRunner(runtime = 'bun') {
402
+ return runtime === 'node' ? 'npm run' : 'bun run'
403
+ }
404
+
405
+ export function resolveTestCommand(runtime = 'bun', target) {
406
+ if (runtime === 'node') return `node --test ${target}`
407
+ return `bun test ${target}`
408
+ }
@@ -4,7 +4,7 @@ import path from 'node:path'
4
4
  import { fileURLToPath } from 'node:url'
5
5
 
6
6
  import { isCorePackageName } from './build-config.mjs'
7
- import { syncProjectToolchain } from './toolchain-config.mjs'
7
+ import { auditTsconfigAlignment, syncProjectToolchain } from './toolchain-config.mjs'
8
8
  import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
9
9
  import { packageDefaults } from './package-defaults.mjs'
10
10
 
@@ -142,7 +142,7 @@ export function syncCliGeneratedModules(root = process.cwd(), { force = false }
142
142
  }
143
143
 
144
144
  execSync(
145
- `bun build "${srcAbs}" --outfile "${mod.outfile}" --target node --format esm --external yaml`,
145
+ `bun build "${srcAbs}" --outfile "${mod.outfile}" --target node --format esm --external yaml --external handlebars`,
146
146
  { cwd: root, stdio: 'pipe' },
147
147
  )
148
148
  results.push({ source: mod.source, synced: true, out: mod.outfile })
@@ -195,7 +195,7 @@ export function syncPackageManifest(root = process.cwd(), { write = true } = {})
195
195
  return { synced: true, wrote: write && changed, distPrefix, distRel, changed }
196
196
  }
197
197
 
198
- /** tmp.yml → toolchain + CLI schema (+ core package exports on build/release). */
198
+ /** tmp.yml → toolchain (+ CLI schema / package exports). Heals tsconfig when layout drifts. */
199
199
  export function ensureProjectArtifacts(root = process.cwd(), options = {}) {
200
200
  const {
201
201
  writeToolchain = false,
@@ -204,7 +204,16 @@ export function ensureProjectArtifacts(root = process.cwd(), options = {}) {
204
204
  } = options
205
205
 
206
206
  const { generated, defaults } = syncCliRuntime(root, { force: forceSchema })
207
- const toolchain = syncProjectToolchain(root, { write: writeToolchain })
207
+ const audit = auditTsconfigAlignment(root)
208
+ const shouldWriteToolchain = writeToolchain || !audit.ok
209
+ const toolchain = syncProjectToolchain(root, { write: shouldWriteToolchain })
210
+ if (shouldWriteToolchain && !writeToolchain && !audit.ok) {
211
+ toolchain.healed = true
212
+ toolchain.healNotes = audit.notes
213
+ if (process.env.XRY_QUIET !== '1') {
214
+ console.info(`[${packageDefaults.packageName}] toolchain auto-synced (tsconfig) — layout drift`)
215
+ }
216
+ }
208
217
  let manifest = { synced: false, reason: 'skipped' }
209
218
 
210
219
  const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
@@ -212,5 +221,5 @@ export function ensureProjectArtifacts(root = process.cwd(), options = {}) {
212
221
  manifest = syncPackageManifest(root, { write: true })
213
222
  }
214
223
 
215
- return { generated, defaults, toolchain, manifest }
224
+ return { generated, defaults, toolchain, manifest, audit }
216
225
  }
@@ -2,8 +2,13 @@ export {
2
2
  normalizeRootFolder,
3
3
  normalizeSourceFolder,
4
4
  normalizeTmpDocument,
5
+ normalizeRuntime,
6
+ normalizeBundler,
7
+ resolveEffectiveBundler,
5
8
  readTmpCoreBlock,
6
9
  readTmpServiceBlock,
10
+ readTmpGlobalBlock,
11
+ applyTmpGlobalVars,
7
12
  resolveServiceLayoutPaths,
8
13
  resolveTmpRuntimeConfigs,
9
14
  } from './.generated/tmp-schema.mjs'
@@ -142,7 +142,7 @@ export function auditTsconfigAlignment(root, options = null) {
142
142
  const recommended = resolveRecommendedTsconfig(resolvedOptions)
143
143
  const onDisk = readProjectTsconfig(root)
144
144
  if (!onDisk) {
145
- return { ok: false, missing: true, notes: [`tsconfig.json not found — run ${CLI_PRIMARY_NAME} sync`] }
145
+ return { ok: false, missing: true, notes: [`tsconfig.json not found — auto-healed on layout change, next ${CLI_PRIMARY_NAME} command, or ${CLI_PRIMARY_NAME} sync`] }
146
146
  }
147
147
 
148
148
  const notes = []
@@ -2,6 +2,7 @@ export { setRuntimeTmpConfigs, getRuntimeTmpConfigs, onRuntimeTmpChange, notifyR
2
2
  export { getTmpLoader, getTmpLoaderPath, getTmpSnapshot, onTmpReload, resetTmpLoaderForTests, stopTmpLoader, } from '../../../utils/helpers/tmp/tmp-loader';
3
3
  export { bindLoaderTmpSync, type ITmpSyncLoader, } from '../../../utils/helpers/tmp/loader-tmp-sync';
4
4
  export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch';
5
- export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, readTmpCoreBlock, readTmpServiceBlock, resolveServiceLayoutPaths, resolveTmpRuntimeConfigs, } from '../../../utils/helpers/tmp/tmp-schema';
5
+ export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, normalizeRuntime, normalizeBundler, resolveEffectiveBundler, readTmpCoreBlock, readTmpServiceBlock, readTmpGlobalBlock, applyTmpGlobalVars, resolveServiceLayoutPaths, resolveTmpRuntimeConfigs, } from '../../../utils/helpers/tmp/tmp-schema';
6
6
  export { loadSeedFromBundledTmp, seedFromTmp, type SeedFromTmp, type SeedLayoutPaths, } from '../../../utils/helpers/tmp/seed-from-tmp';
7
7
  export { normalizeLayoutPaths, type LayoutPaths, } from '../../../utils/helpers/tmp/path-normalize';
8
+ export { healToolchainIfLayoutNeedsSync, layoutFingerprint, layoutOptionsFromRuntimeConfigs, resetToolchainHealState, writeTsconfigFromLayout, auditTsconfigAgainstLayout, type ToolchainHealResult, type ToolchainLayoutOptions, } from '../../../utils/helpers/tmp/toolchain-heal';
@@ -1 +1 @@
1
- export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";export{loadSeedFromBundledTmp,seedFromTmp}from"../../../utils/helpers/tmp/seed-from-tmp";export{normalizeLayoutPaths}from"../../../utils/helpers/tmp/path-normalize";
1
+ export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,normalizeRuntime,normalizeBundler,resolveEffectiveBundler,readTmpCoreBlock,readTmpServiceBlock,readTmpGlobalBlock,applyTmpGlobalVars,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";export{loadSeedFromBundledTmp,seedFromTmp}from"../../../utils/helpers/tmp/seed-from-tmp";export{normalizeLayoutPaths}from"../../../utils/helpers/tmp/path-normalize";export{healToolchainIfLayoutNeedsSync,layoutFingerprint,layoutOptionsFromRuntimeConfigs,resetToolchainHealState,writeTsconfigFromLayout,auditTsconfigAgainstLayout}from"../../../utils/helpers/tmp/toolchain-heal";
@@ -1 +1 @@
1
- let e;const i=[];export function setRuntimeTmpConfigs(n){e=n}export function getRuntimeTmpConfigs(){return e}export function onRuntimeTmpChange(n){i.push(n);return()=>{const t=i.indexOf(n);if(t>=0)i.splice(t,1)}}export async function notifyRuntimeTmpChange(n){if(n)e=n;const t=e;if(!t)return;for(const o of i)await o(t)}export function clearRuntimeTmpConfigs(){e=void 0;i.length=0}
1
+ import{healToolchainIfLayoutNeedsSync as z,resetToolchainHealState as A}from"../../../utils/helpers/tmp/toolchain-heal";let q;const v=[];export function setRuntimeTmpConfigs(j){q=j}export function getRuntimeTmpConfigs(){return q}export function onRuntimeTmpChange(j){v.push(j);return()=>{const b=v.indexOf(j);if(b>=0)v.splice(b,1)}}export async function notifyRuntimeTmpChange(j){if(j)q=j;const b=q;if(!b)return;if(b.rootFolderPath&&b.service?.paths)try{z(process.cwd(),b)}catch(k){const w=k instanceof Error?k.message:String(k);console.warn(`[xrystal] toolchain auto-sync skipped: ${w}`)}for(const k of v)await k(b)}export function clearRuntimeTmpConfigs(){q=void 0;v.length=0;A()}
@@ -0,0 +1 @@
1
+ export declare function interpolateWithContext<T>(value: T, context: Record<string, unknown>): T;
@@ -0,0 +1 @@
1
+ import f from"handlebars";function e(r){return typeof r==="object"&&r!==null&&!Array.isArray(r)}export function interpolateWithContext(r,n){if(typeof r==="string"){if(!r.includes("{{"))return r;return f.compile(r)(n)}if(Array.isArray(r))return r.map((t)=>interpolateWithContext(t,n));if(e(r)){const t={};for(const[i,o]of Object.entries(r))t[i]=interpolateWithContext(o,n);return t}return r}
@@ -1,3 +1,4 @@
1
+ import { BundlerEnum, RuntimeEnum } from '../../../utils/models/enums';
1
2
  export type TmpServiceSpecialPaths = {
2
3
  tests?: string;
3
4
  environments?: string;
@@ -21,12 +22,17 @@ export type TmpCoreBlock = {
21
22
  fileWatchIntervalMs?: number | string;
22
23
  };
23
24
  };
25
+ export type TmpGlobalBlock = {
26
+ runtime: RuntimeEnum;
27
+ vars: Record<string, unknown>;
28
+ };
24
29
  export type TmpLayoutPathsFlat = {
25
30
  tests: string;
26
31
  environments: string;
27
32
  dist: string;
28
33
  };
29
34
  export type TmpRuntimeConfigs = {
35
+ global: TmpGlobalBlock;
30
36
  service: TmpServiceBlock & {
31
37
  paths: Required<Pick<TmpServicePathsBlock, 'root' | 'source'>> & {
32
38
  special: TmpLayoutPathsFlat;
@@ -35,10 +41,16 @@ export type TmpRuntimeConfigs = {
35
41
  core: TmpCoreBlock;
36
42
  rootFolderPath: string;
37
43
  };
44
+ export declare function normalizeRuntime(value: unknown): RuntimeEnum;
45
+ export declare function normalizeBundler(value: unknown): BundlerEnum;
46
+ export declare function resolveEffectiveBundler(bundler: BundlerEnum, runtime: RuntimeEnum): Exclude<BundlerEnum, BundlerEnum.AUTO>;
38
47
  export declare function normalizeRootFolder(value?: string): string;
39
48
  export declare function normalizeSourceFolder(value?: string): string;
49
+ export declare function readTmpGlobalBlock(configs?: Record<string, unknown>): TmpGlobalBlock;
40
50
  export declare function readTmpCoreBlock(configs?: Record<string, unknown>): TmpCoreBlock;
41
51
  export declare function readTmpServiceBlock(configs?: Record<string, unknown>): TmpServiceBlock;
42
52
  export declare function resolveServiceLayoutPaths(service: TmpServiceBlock): TmpLayoutPathsFlat;
53
+ export declare function buildTmpVarContext(global: TmpGlobalBlock): Record<string, unknown>;
54
+ export declare function applyTmpGlobalVars(tmp: Record<string, unknown>): Record<string, unknown>;
43
55
  export declare function resolveTmpRuntimeConfigs(tmp?: Record<string, unknown> | null): TmpRuntimeConfigs;
44
56
  export declare function normalizeTmpDocument(tmp: Record<string, unknown>): Record<string, unknown>;
@@ -1 +1 @@
1
- import K from"../../../utils/constants/defaults.json" with { type: 'json' };import{seedFromTmp as G}from"../../../utils/helpers/tmp/seed-from-tmp";import{normalizeLayoutPaths as O,normalizeRootFolder as Q,normalizeSourceFolder as U}from"../../../utils/helpers/tmp/path-normalize";function A(j){return typeof j==="object"&&j!==null&&!Array.isArray(j)}function X(j){if(typeof j==="number"||typeof j==="string")return j;return}export function normalizeRootFolder(j){return Q(j,K.packageRootFolder)}export function normalizeSourceFolder(j){return U(j,G.sourceFolder)}export function readTmpCoreBlock(j){const q=A(j?.core)?j.core:{},x=A(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:X(x.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=A(j?.service)?j.service:{},x=A(q.paths)?q.paths:{},D=A(x.special)?x.special:{};let E=A(q.loaders)?{...q.loaders}:void 0,H=A(q.build)?q.build:void 0;if(E&&A(E.build)){const{build:J,...M}=E;E=M;if(!H&&A(J))H=J}return{name:typeof q.name==="string"?q.name:void 0,framework:typeof q.framework==="string"?q.framework:void 0,paths:{root:typeof x.root==="string"?x.root:void 0,source:typeof x.source==="string"?x.source:void 0,special:{tests:typeof D.tests==="string"?D.tests:void 0,environments:typeof D.environments==="string"?D.environments:void 0,dist:typeof D.dist==="string"?D.dist:void 0}},protocols:q.protocols,loaders:E,build:H}}export function resolveServiceLayoutPaths(j){return O(j.paths?.special,G.layout)}function Y(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??G.framework,paths:{root:j.paths?.root??K.packageRootFolder,source:j.paths?.source??G.sourceFolder,special:q},protocols:j.protocols,loaders:j.loaders,build:j.build}}function Z(j){return{tmp:{fileWatchIntervalMs:j.tmp?.fileWatchIntervalMs}}}export function resolveTmpRuntimeConfigs(j){const q=A(j?.configs)?j.configs:{},x=readTmpServiceBlock(q),D=readTmpCoreBlock(q),E=Y(x);return{service:E,core:Z(D),rootFolderPath:normalizeRootFolder(E.paths.root)}}export function normalizeTmpDocument(j){return{...j,configs:resolveTmpRuntimeConfigs(j)}}
1
+ import X from"../../../utils/constants/defaults.json" with { type: 'json' };import{BundlerEnum as H,RuntimeEnum as O}from"../../../utils/models/enums";import{seedFromTmp as Q}from"../../../utils/helpers/tmp/seed-from-tmp";import{interpolateWithContext as Z}from"../../../utils/helpers/tmp/tmp-interpolate";import{normalizeLayoutPaths as _,normalizeRootFolder as $,normalizeSourceFolder as I}from"../../../utils/helpers/tmp/path-normalize";function D(j){return typeof j==="object"&&j!==null&&!Array.isArray(j)}function x(j){if(typeof j==="number"||typeof j==="string")return j;return}export function normalizeRuntime(j){const q=typeof j==="string"?j.trim().toLowerCase():"";if(q===O.NODE)return O.NODE;if(q===O.BUN)return O.BUN;return O.BUN}export function normalizeBundler(j){const q=typeof j==="string"?j.trim().toLowerCase():"";if(q===H.TSC)return H.TSC;if(q===H.ESBUILD)return H.ESBUILD;if(q===H.BUN)return H.BUN;if(q===H.AUTO)return H.AUTO;return H.AUTO}export function resolveEffectiveBundler(j,q){if(j!==H.AUTO)return j;return q===O.NODE?H.TSC:H.BUN}export function normalizeRootFolder(j){return $(j,X.packageRootFolder)}export function normalizeSourceFolder(j){return I(j,Q.sourceFolder)}export function readTmpGlobalBlock(j){const q=D(j?.global)?j.global:{},A=D(q.vars)?q.vars:{};return{runtime:normalizeRuntime(q.runtime),vars:{...A}}}export function readTmpCoreBlock(j){const q=D(j?.core)?j.core:{},A=D(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:x(A.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=D(j?.service)?j.service:{},A=D(q.paths)?q.paths:{},J=D(A.special)?A.special:{};let K=D(q.loaders)?{...q.loaders}:void 0,M=D(q.build)?q.build:void 0;if(K&&D(K.build)){const{build:U,...Y}=K;K=Y;if(!M&&D(U))M=U}return{name:typeof q.name==="string"?q.name:void 0,framework:typeof q.framework==="string"?q.framework:void 0,paths:{root:typeof A.root==="string"?A.root:void 0,source:typeof A.source==="string"?A.source:void 0,special:{tests:typeof J.tests==="string"?J.tests:void 0,environments:typeof J.environments==="string"?J.environments:void 0,dist:typeof J.dist==="string"?J.dist:void 0}},protocols:q.protocols,loaders:K,build:M}}export function resolveServiceLayoutPaths(j){return _(j.paths?.special,Q.layout)}function L(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??Q.framework,paths:{root:j.paths?.root??X.packageRootFolder,source:j.paths?.source??Q.sourceFolder,special:q},protocols:j.protocols,loaders:j.loaders,build:j.build}}function N(j){return{tmp:{fileWatchIntervalMs:j.tmp?.fileWatchIntervalMs}}}export function buildTmpVarContext(j){return{...j.vars,runtime:j.runtime,global:j}}export function applyTmpGlobalVars(j){const q=D(j.configs)?j.configs:{},A=readTmpGlobalBlock(q);return Z(j,buildTmpVarContext(A))}export function resolveTmpRuntimeConfigs(j){const q=D(j?.configs)?j.configs:{},A=readTmpGlobalBlock(q),J=readTmpServiceBlock(q),K=readTmpCoreBlock(q),M=L(J);return{global:A,service:M,core:N(K),rootFolderPath:normalizeRootFolder(M.paths.root)}}export function normalizeTmpDocument(j){const q=applyTmpGlobalVars(j);return{...q,configs:resolveTmpRuntimeConfigs(q)}}
@@ -0,0 +1,46 @@
1
+ import type { TmpRuntimeConfigs } from '../../../utils/helpers/tmp/tmp-schema';
2
+ export type ToolchainLayoutOptions = {
3
+ rootFolderPath: string;
4
+ mainFolderPath: string;
5
+ pathsDist: string;
6
+ pathsTests: string;
7
+ };
8
+ export type ToolchainHealResult = {
9
+ healed: boolean;
10
+ reason?: 'bootstrap' | 'layout-changed';
11
+ tsconfigRel: string;
12
+ fingerprint: string;
13
+ };
14
+ export declare function layoutOptionsFromRuntimeConfigs(configs: TmpRuntimeConfigs): ToolchainLayoutOptions;
15
+ export declare function layoutFingerprint(options: ToolchainLayoutOptions): string;
16
+ export declare function resolveRecommendedTsconfig(options: ToolchainLayoutOptions): {
17
+ include: string[];
18
+ exclude: string[];
19
+ compilerOptions: {
20
+ baseUrl: string;
21
+ paths: {
22
+ [x: string]: string[];
23
+ };
24
+ rootDir: string;
25
+ outDir: string;
26
+ };
27
+ };
28
+ export declare function auditTsconfigAgainstLayout(root: string, options: ToolchainLayoutOptions, tsconfigRel?: string): {
29
+ ok: boolean;
30
+ missing: boolean;
31
+ notes: string[];
32
+ };
33
+ export declare function writeTsconfigFromLayout(root: string, options: ToolchainLayoutOptions, tsconfigRel?: string): {
34
+ wrote: boolean;
35
+ created: boolean;
36
+ abs: string;
37
+ };
38
+ /** Test/reset helper — clears in-memory layout fingerprint. */
39
+ export declare function resetToolchainHealState(): void;
40
+ /**
41
+ * Live pulse: sync tsconfig only when layout paths change, or once on bootstrap if already drifted.
42
+ * Non-path tmp edits do not rewrite toolchain files.
43
+ */
44
+ export declare function healToolchainIfLayoutNeedsSync(root: string, configs: TmpRuntimeConfigs, options?: {
45
+ quiet?: boolean;
46
+ }): ToolchainHealResult;
@@ -0,0 +1,2 @@
1
+ import N from"node:fs";import X from"node:path";import{packageDefaults as J}from"../../../utils/constants";import{normalizeSourceFolder as $}from"../../../utils/helpers/tmp/path-normalize";function Y(j){return String(j).replace(/^\.\//,"")}export function layoutOptionsFromRuntimeConfigs(j){const q=j.service?.paths,B=q?.special;return{rootFolderPath:j.rootFolderPath||J.packageRootFolder,mainFolderPath:$(q?.source,J.mainSourceFolder),pathsDist:B?.dist||J.layoutPaths.dist,pathsTests:B?.tests||J.layoutPaths.tests}}export function layoutFingerprint(j){return[j.rootFolderPath,Y(j.mainFolderPath),j.pathsDist,j.pathsTests].join("\x00")}export function resolveRecommendedTsconfig(j){const q=Y(j.mainFolderPath),B=j.rootFolderPath,H=J.pathAliasKey;return{include:[q],exclude:[`${B}/${j.pathsTests}`],compilerOptions:{baseUrl:".",paths:{[H]:[`${q}/*`]},rootDir:`./${q}`,outDir:`./${B}/${j.pathsDist}`}}}function A(j){const q=X.join(j,"package.json");if(!N.existsSync(q))return`${J.packageName}/tsconfig.base.json`;try{if(JSON.parse(N.readFileSync(q,"utf8")).name===J.packageName)return"./tsconfig.base.json"}catch{}return`${J.packageName}/tsconfig.base.json`}function C(j,q,B){const H=q.compilerOptions??{};return{...q,extends:q.extends??B,include:j.include,exclude:j.exclude,compilerOptions:{...H,baseUrl:j.compilerOptions.baseUrl,paths:j.compilerOptions.paths,rootDir:j.compilerOptions.rootDir,outDir:j.compilerOptions.outDir}}}export function auditTsconfigAgainstLayout(j,q,B=J.buildDefaults?.tsconfig??"tsconfig.json"){const H=X.join(j,B);if(!N.existsSync(H))return{ok:!1,missing:!0,notes:[`${B} missing`]};let I;try{I=JSON.parse(N.readFileSync(H,"utf8"))}catch{return{ok:!1,missing:!1,notes:[`${B} unreadable`]}}const G=resolveRecommendedTsconfig(q),M=[],U=I.compilerOptions??{},V=J.pathAliasKey;if(U.outDir!==G.compilerOptions.outDir)M.push("outDir drift");if(!(Array.isArray(I.include)?I.include.map(String):[]).some((_)=>Y(_)===G.include[0]))M.push("include drift");const Z=U.paths?.[V];if(JSON.stringify(Z)!==JSON.stringify(G.compilerOptions.paths[V]))M.push(`paths ${V} drift`);return{ok:M.length===0,missing:!1,notes:M}}export function writeTsconfigFromLayout(j,q,B=J.buildDefaults?.tsconfig??"tsconfig.json"){const H=X.join(j,B),I=!N.existsSync(H);let G={};if(!I)try{G=JSON.parse(N.readFileSync(H,"utf8"))}catch{G={}}const M=resolveRecommendedTsconfig(q),U=C(M,G,A(j));N.writeFileSync(H,`${JSON.stringify(U,null,2)}
2
+ `,"utf8");return{wrote:!0,created:I,abs:H}}let Q=null;export function resetToolchainHealState(){Q=null}export function healToolchainIfLayoutNeedsSync(j,q,B={}){const H=layoutOptionsFromRuntimeConfigs(q),I=layoutFingerprint(H),G=J.buildDefaults?.tsconfig??"tsconfig.json",M=auditTsconfigAgainstLayout(j,H,G);if(Q===null){Q=I;if(M.ok)return{healed:!1,tsconfigRel:G,fingerprint:I};writeTsconfigFromLayout(j,H,G);if(!B.quiet)console.info(`[${J.packageName}] toolchain auto-synced (${G}) — bootstrap layout drift`);return{healed:!0,reason:"bootstrap",tsconfigRel:G,fingerprint:I}}if(I===Q)return{healed:!1,tsconfigRel:G,fingerprint:I};Q=I;writeTsconfigFromLayout(j,H,G);if(!B.quiet)console.info(`[${J.packageName}] toolchain auto-synced (${G}) — tmp layout paths changed`);return{healed:!0,reason:"layout-changed",tsconfigRel:G,fingerprint:I}}
@@ -18,6 +18,16 @@ export declare enum FrameworkEnum {
18
18
  WEBSOCKET = "websocket",
19
19
  SOCKETIO = "socketio"
20
20
  }
21
+ export declare enum RuntimeEnum {
22
+ BUN = "bun",
23
+ NODE = "node"
24
+ }
25
+ export declare enum BundlerEnum {
26
+ AUTO = "auto",
27
+ BUN = "bun",
28
+ TSC = "tsc",
29
+ ESBUILD = "esbuild"
30
+ }
21
31
  export declare enum PolarityTypeEnum {
22
32
  NOTR = 0,
23
33
  POSITIVE = 1,
@@ -1 +1 @@
1
- export var NodeEnvEnum;(function(N){N.DEV="dev";N.TEST="test";N.PROD="prod"})(NodeEnvEnum||(NodeEnvEnum={}));export var ProtocolEnum;(function(N){N.HTTP="http";N.HTTPS="https";N.WEBSOCKET="ws";N.SOCKETIO="socketio";N.NONE="none"})(ProtocolEnum||(ProtocolEnum={}));export var FrameworkEnum;(function(N){N.EXPRESS="express";N.ELYSIA="elysia";N.NODE="node";N.FETCH="fetch";N.WEBSOCKET="websocket";N.SOCKETIO="socketio"})(FrameworkEnum||(FrameworkEnum={}));export var PolarityTypeEnum;(function(N){N[N.NOTR=0]="NOTR";N[N.POSITIVE=1]="POSITIVE";N[N.NEGATIVE=-1]="NEGATIVE"})(PolarityTypeEnum||(PolarityTypeEnum={}));export var LoggerLayerEnum;(function(N){N[N.CRITICAL=0]="CRITICAL";N[N.ERROR=1]="ERROR";N[N.WARN=2]="WARN";N[N.INFO=3]="INFO";N[N.HTTP=4]="HTTP";N[N.DEBUG=5]="DEBUG"})(LoggerLayerEnum||(LoggerLayerEnum={}));export var CountryCodeEnum;(function(N){N.EN="en";N.TR="tr"})(CountryCodeEnum||(CountryCodeEnum={}));export var CurrencyCodeEnum;(function(N){N.USD="usd";N.EUR="eur";N.TRY="try"})(CurrencyCodeEnum||(CurrencyCodeEnum={}));export var HttpMethodEnum;(function(N){N.POST="post";N.GET="get";N.PUT="put";N.DELETE="delete"})(HttpMethodEnum||(HttpMethodEnum={}));export var ContentTypeEnum;(function(N){N.applicationJson="application/json";N.applicationXWwwFormUrlencoded="application/x-www-form-urlencoded"})(ContentTypeEnum||(ContentTypeEnum={}));export var DeviceStatusEnum;(function(N){N[N.PENDING=0]="PENDING";N[N.OFFLINE=1]="OFFLINE";N[N.ONLINE=2]="ONLINE";N[N.CONNECTING=3]="CONNECTING";N[N.CONNECTED=4]="CONNECTED"})(DeviceStatusEnum||(DeviceStatusEnum={}));export var DevicePlatformEnum;(function(N){N.WEB="web";N.NATIVE="native";N.OTHER="other"})(DevicePlatformEnum||(DevicePlatformEnum={}));export var DeviceOSEnum;(function(N){N.ANDROID="android";N.IOS="ios";N.WINDOWS="windows";N.MACOS="macos";N.MACOSX="macosx";N.OTHER="other"})(DeviceOSEnum||(DeviceOSEnum={}));export var PriorityEnum;(function(N){N[N.HIGH=0]="HIGH";N[N.MEDIUM=1]="MEDIUM";N[N.LOW=2]="LOW"})(PriorityEnum||(PriorityEnum={}));export var PrivacyEnum;(function(N){N[N.PRIVATE=0]="PRIVATE";N[N.PUBLIC=1]="PUBLIC";N[N.ONLY_FRIENDS=2]="ONLY_FRIENDS"})(PrivacyEnum||(PrivacyEnum={}));export var TimezoneEnum;(function(N){N.UTC="UTC";N.EtcUTC="Etc/UTC";N.EtcGMT="Etc/GMT"})(TimezoneEnum||(TimezoneEnum={}));export var ModeEnum;(function(N){N.MONOLITIC="monolitic";N.MICRO_SERVICE="micro_service"})(ModeEnum||(ModeEnum={}));export var TokensEnum;(function(N){N.INTERNAL_API_TOKEN="internal_api_key";N.CSRF_TOKEN="csrf_token";N.ACCESS_TOKEN="access_token";N.REFRESH_TOKEN="refresh_token";N.REFERENCE_TOKEN="reference_token";N.PERSONAL_ACCESS_TOKEN="personal_access_token"})(TokensEnum||(TokensEnum={}));export var CoreClientsEnum;(function(N){N.BASE_API_CLIENT="base_client_name";N.SOAP_API_CLIENT="soap_api_client"})(CoreClientsEnum||(CoreClientsEnum={}));export var GStoreScopeEnum;(function(N){N.GLOBAL="global";N.RUN="run";N.CONTROLLER="controller"})(GStoreScopeEnum||(GStoreScopeEnum={}));export var EndpointResourceEnum;(function(N){N.EXAMPLE="example";N.FULL="full";N.SYSTEM="system";N.CLIENTS="clients";N.AUTH="auth";N.ACCOUNTS="accounts";N.USERS="users";N.TRANSACTIONS="transactions";N.NOTIFICATIONS="notifications";N.ADDRESSES="addresses";N.PAYMENTS="payments";N.COMMISSIONS_AND_TAXES="commissions-and-taxes";N.SUPPORTS="supports";N.INVOICES="invoices";N.FILES="files";N.TOKENS="tokens";N.WEBHOOKS="webhooks";N.OTHERS="others"})(EndpointResourceEnum||(EndpointResourceEnum={}));
1
+ export var NodeEnvEnum;(function(N){N.DEV="dev";N.TEST="test";N.PROD="prod"})(NodeEnvEnum||(NodeEnvEnum={}));export var ProtocolEnum;(function(N){N.HTTP="http";N.HTTPS="https";N.WEBSOCKET="ws";N.SOCKETIO="socketio";N.NONE="none"})(ProtocolEnum||(ProtocolEnum={}));export var FrameworkEnum;(function(N){N.EXPRESS="express";N.ELYSIA="elysia";N.NODE="node";N.FETCH="fetch";N.WEBSOCKET="websocket";N.SOCKETIO="socketio"})(FrameworkEnum||(FrameworkEnum={}));export var RuntimeEnum;(function(N){N.BUN="bun";N.NODE="node"})(RuntimeEnum||(RuntimeEnum={}));export var BundlerEnum;(function(N){N.AUTO="auto";N.BUN="bun";N.TSC="tsc";N.ESBUILD="esbuild"})(BundlerEnum||(BundlerEnum={}));export var PolarityTypeEnum;(function(N){N[N.NOTR=0]="NOTR";N[N.POSITIVE=1]="POSITIVE";N[N.NEGATIVE=-1]="NEGATIVE"})(PolarityTypeEnum||(PolarityTypeEnum={}));export var LoggerLayerEnum;(function(N){N[N.CRITICAL=0]="CRITICAL";N[N.ERROR=1]="ERROR";N[N.WARN=2]="WARN";N[N.INFO=3]="INFO";N[N.HTTP=4]="HTTP";N[N.DEBUG=5]="DEBUG"})(LoggerLayerEnum||(LoggerLayerEnum={}));export var CountryCodeEnum;(function(N){N.EN="en";N.TR="tr"})(CountryCodeEnum||(CountryCodeEnum={}));export var CurrencyCodeEnum;(function(N){N.USD="usd";N.EUR="eur";N.TRY="try"})(CurrencyCodeEnum||(CurrencyCodeEnum={}));export var HttpMethodEnum;(function(N){N.POST="post";N.GET="get";N.PUT="put";N.DELETE="delete"})(HttpMethodEnum||(HttpMethodEnum={}));export var ContentTypeEnum;(function(N){N.applicationJson="application/json";N.applicationXWwwFormUrlencoded="application/x-www-form-urlencoded"})(ContentTypeEnum||(ContentTypeEnum={}));export var DeviceStatusEnum;(function(N){N[N.PENDING=0]="PENDING";N[N.OFFLINE=1]="OFFLINE";N[N.ONLINE=2]="ONLINE";N[N.CONNECTING=3]="CONNECTING";N[N.CONNECTED=4]="CONNECTED"})(DeviceStatusEnum||(DeviceStatusEnum={}));export var DevicePlatformEnum;(function(N){N.WEB="web";N.NATIVE="native";N.OTHER="other"})(DevicePlatformEnum||(DevicePlatformEnum={}));export var DeviceOSEnum;(function(N){N.ANDROID="android";N.IOS="ios";N.WINDOWS="windows";N.MACOS="macos";N.MACOSX="macosx";N.OTHER="other"})(DeviceOSEnum||(DeviceOSEnum={}));export var PriorityEnum;(function(N){N[N.HIGH=0]="HIGH";N[N.MEDIUM=1]="MEDIUM";N[N.LOW=2]="LOW"})(PriorityEnum||(PriorityEnum={}));export var PrivacyEnum;(function(N){N[N.PRIVATE=0]="PRIVATE";N[N.PUBLIC=1]="PUBLIC";N[N.ONLY_FRIENDS=2]="ONLY_FRIENDS"})(PrivacyEnum||(PrivacyEnum={}));export var TimezoneEnum;(function(N){N.UTC="UTC";N.EtcUTC="Etc/UTC";N.EtcGMT="Etc/GMT"})(TimezoneEnum||(TimezoneEnum={}));export var ModeEnum;(function(N){N.MONOLITIC="monolitic";N.MICRO_SERVICE="micro_service"})(ModeEnum||(ModeEnum={}));export var TokensEnum;(function(N){N.INTERNAL_API_TOKEN="internal_api_key";N.CSRF_TOKEN="csrf_token";N.ACCESS_TOKEN="access_token";N.REFRESH_TOKEN="refresh_token";N.REFERENCE_TOKEN="reference_token";N.PERSONAL_ACCESS_TOKEN="personal_access_token"})(TokensEnum||(TokensEnum={}));export var CoreClientsEnum;(function(N){N.BASE_API_CLIENT="base_client_name";N.SOAP_API_CLIENT="soap_api_client"})(CoreClientsEnum||(CoreClientsEnum={}));export var GStoreScopeEnum;(function(N){N.GLOBAL="global";N.RUN="run";N.CONTROLLER="controller"})(GStoreScopeEnum||(GStoreScopeEnum={}));export var EndpointResourceEnum;(function(N){N.EXAMPLE="example";N.FULL="full";N.SYSTEM="system";N.CLIENTS="clients";N.AUTH="auth";N.ACCOUNTS="accounts";N.USERS="users";N.TRANSACTIONS="transactions";N.NOTIFICATIONS="notifications";N.ADDRESSES="addresses";N.PAYMENTS="payments";N.COMMISSIONS_AND_TAXES="commissions-and-taxes";N.SUPPORTS="supports";N.INVOICES="invoices";N.FILES="files";N.TOKENS="tokens";N.WEBHOOKS="webhooks";N.OTHERS="others"})(EndpointResourceEnum||(EndpointResourceEnum={}));
package/x/tmp.yml CHANGED
@@ -2,8 +2,13 @@ project:
2
2
  name: x
3
3
 
4
4
  configs:
5
+ global:
6
+ runtime: bun
7
+ vars:
8
+ xry: xry
9
+
5
10
  service:
6
- name: example-service
11
+ name: "{{xry}}-service"
7
12
  framework: elysia
8
13
 
9
14
  paths:
@@ -47,6 +52,7 @@ configs:
47
52
  controller:
48
53
 
49
54
  build:
55
+ bundler: auto
50
56
  typecheck: true
51
57
  minify: true
52
58