@xrystal/core 3.45.2 → 3.45.4

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,10 +3,17 @@
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.2` · [npm](https://www.npmjs.com/package/@xrystal/core)
6
+ **CLI:** `xry` · **Version:** `3.45.4` · [npm](https://www.npmjs.com/package/@xrystal/core)
7
7
 
8
8
  ---
9
9
 
10
+ ## What's new in 3.45.4 / 3.45.4'da ne değişti
11
+
12
+ | Change / Değişiklik | EN | TR |
13
+ |---------------------|----|----|
14
+ | **Strict normalize** | Missing/unknown `runtime` throws; unknown `bundler` throws | Sessiz fallback yok |
15
+ | **Path/bin SSOT** | Scripts use layout + `defaults.runtimes` (no `x/dist` / `bun` literals) | Hardcode temizliği |
16
+
10
17
  ## What's new in 3.45.2 / 3.45.2'da ne değişti
11
18
 
12
19
  | Change / Değişiklik | EN | TR |
@@ -86,7 +93,7 @@ npx xry doctor # EN: optional health check · TR: isteğe bağlı sağlı
86
93
  ```json
87
94
  {
88
95
  "dependencies": {
89
- "@xrystal/core": "^3.45.2",
96
+ "@xrystal/core": "^3.45.4",
90
97
  "elysia": "^1.4.19"
91
98
  },
92
99
  "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.2",
4
+ "version": "3.45.4",
5
5
  "description": "microservice runtime library",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -14,6 +14,7 @@ import { evaluateVersionBump, getVersionState, resolveCommitVersionHint, resolve
14
14
  import { auditTsconfigAlignment, resolveToolchainPathsFromProject } from '../helpers/toolchain-config.mjs'
15
15
  import { isGitHookInstalled } from '../scripts/install-git-hooks.mjs'
16
16
  import { packageDefaults } from '../helpers/package-defaults.mjs'
17
+ import { detectCliHostRuntime, getRuntimeTooling } from '../helpers/cli-runtime.mjs'
17
18
 
18
19
  function statusValue(value, okLabel = null) {
19
20
  if (value == null || value === '') return chalk.gray('—')
@@ -103,7 +104,7 @@ export function registerDoctorCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
103
104
  console.log(chalk.bold.red(' ⚠ CLI / node_modules version mismatch'))
104
105
  console.log(chalk.yellow(` CLI (this binary): ${cliPkg.version}`))
105
106
  console.log(chalk.yellow(` node_modules installed: ${core.installed}`))
106
- console.log(chalk.gray(` fix: bun add ${packageDefaults.packageName}@${cliPkg.version}`))
107
+ console.log(chalk.gray(` fix: ${getRuntimeTooling(detectCliHostRuntime()).packageManager} add ${packageDefaults.packageName}@${cliPkg.version}`))
107
108
  }
108
109
 
109
110
  printSection('Git')
@@ -18,7 +18,7 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
18
18
  console.log(chalk.gray(' from tmp.yml:'))
19
19
  console.log(chalk.gray(` paths.root: ${lo.rootFolderPath ?? '—'}`))
20
20
  console.log(chalk.gray(` paths.source: ${lo.mainFolderPath ?? '—'}`))
21
- console.log(chalk.gray(` paths.dist: ${lo.pathsDist ?? '—'}`))
21
+ console.log(chalk.gray(` paths.special.dist: ${lo.pathsDist ?? '—'}`))
22
22
 
23
23
  if (options.dryRun) {
24
24
  const preview = syncProjectToolchain(root, { write: false })
@@ -65,6 +65,20 @@ var defaults_default = {
65
65
  }
66
66
  };
67
67
 
68
+ // source/utils/models/enums/index.ts
69
+ var RuntimeEnum;
70
+ ((RuntimeEnum2) => {
71
+ RuntimeEnum2["BUN"] = "bun";
72
+ RuntimeEnum2["NODE"] = "node";
73
+ })(RuntimeEnum ||= {});
74
+ var BundlerEnum;
75
+ ((BundlerEnum2) => {
76
+ BundlerEnum2["AUTO"] = "auto";
77
+ BundlerEnum2["BUN"] = "bun";
78
+ BundlerEnum2["TSC"] = "tsc";
79
+ BundlerEnum2["ESBUILD"] = "esbuild";
80
+ })(BundlerEnum ||= {});
81
+
68
82
  // source/utils/helpers/tmp/seed-from-tmp.ts
69
83
  import fs from "node:fs";
70
84
  import path from "node:path";
@@ -192,10 +206,15 @@ function normalizeRuntime(value) {
192
206
  return "node" /* NODE */;
193
207
  if (raw === "bun" /* BUN */)
194
208
  return "bun" /* BUN */;
195
- return "bun" /* BUN */;
209
+ if (!raw) {
210
+ throw new Error(`${defaults_default.packageName}: configs.global.runtime is required (${Object.values(RuntimeEnum).join("|")})`);
211
+ }
212
+ throw new Error(`${defaults_default.packageName}: unknown configs.global.runtime "${String(value)}" (expected ${Object.values(RuntimeEnum).join("|")})`);
196
213
  }
197
214
  function normalizeBundler(value) {
198
215
  const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
216
+ if (!raw)
217
+ return "auto" /* AUTO */;
199
218
  if (raw === "tsc" /* TSC */)
200
219
  return "tsc" /* TSC */;
201
220
  if (raw === "esbuild" /* ESBUILD */)
@@ -204,7 +223,7 @@ function normalizeBundler(value) {
204
223
  return "bun" /* BUN */;
205
224
  if (raw === "auto" /* AUTO */)
206
225
  return "auto" /* AUTO */;
207
- return "auto" /* AUTO */;
226
+ throw new Error(`${defaults_default.packageName}: unknown build.bundler "${String(value)}" (expected ${Object.values(BundlerEnum).join("|")})`);
208
227
  }
209
228
  function resolveEffectiveBundler(bundler, runtime) {
210
229
  if (bundler !== "auto" /* AUTO */)
@@ -26,6 +26,14 @@ export const CLI_BUILD_SCRIPT_RE = new RegExp(
26
26
 
27
27
  const BUILD_DEFAULTS = packageDefaults.buildDefaults ?? {}
28
28
 
29
+ function requireBuildTsconfig() {
30
+ const rel = BUILD_DEFAULTS.tsconfig
31
+ if (!rel || !String(rel).trim()) {
32
+ throw new Error(`${packageDefaults.packageName}: buildDefaults.tsconfig missing in defaults.json`)
33
+ }
34
+ return String(rel)
35
+ }
36
+
29
37
  export function isCorePackageName(name) {
30
38
  return name === packageDefaults.packageName
31
39
  }
@@ -58,7 +66,7 @@ export function resolveTsconfigRel(root, buildConfig = {}) {
58
66
  const configured =
59
67
  typeof buildConfig.tsconfig === 'string' && buildConfig.tsconfig.trim()
60
68
  ? buildConfig.tsconfig.trim()
61
- : BUILD_DEFAULTS.tsconfig ?? 'tsconfig.json'
69
+ : requireBuildTsconfig()
62
70
 
63
71
  const abs = path.isAbsolute(configured) ? configured : path.join(root, configured)
64
72
  if (!fs.existsSync(abs)) return null
@@ -263,7 +271,7 @@ export function resolveBunBuildCommand(entryGlobs, distRel, buildConfig = {}, ts
263
271
  const sourcemapFlag = resolveSourcemapFlag(buildConfig, tsconfig)
264
272
  const minifyFlags = resolveMinifyFlags(buildConfig)
265
273
  const flags = [...minifyFlags, ...(sourcemapFlag ? [sourcemapFlag] : []), '--outdir', distRel, '--target', 'node', "--external", "'*'"]
266
- return `bun build ${entryGlobs.join(' ')} ${flags.join(' ')}`.replace(/\s+/g, ' ').trim()
274
+ return `${getRuntimeTooling(RuntimeEnum.BUN).binRunner} build ${entryGlobs.join(' ')} ${flags.join(' ')}`.replace(/\s+/g, ' ').trim()
267
275
  }
268
276
 
269
277
  export function resolveTscBuildCommand(root, distRel, buildConfig = {}, runtime = detectCliHostRuntime()) {
@@ -324,20 +332,27 @@ export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}, run
324
332
  }
325
333
 
326
334
  export function resolveCoreBuildSteps(root, distRel, buildConfig = {}) {
327
- const tsconfigRel = resolveTsconfigRel(root, buildConfig) ?? packageDefaults.buildDefaults.tsconfig
328
- const scripts = `node ${packageDefaults.packageRootFolder}/bin/scripts`
335
+ const resolvedTsconfig = resolveTsconfigRel(root, buildConfig)
336
+ ?? packageDefaults.buildDefaults?.tsconfig
337
+ if (!resolvedTsconfig) {
338
+ throw new Error(`${packageDefaults.packageName}: buildDefaults.tsconfig missing`)
339
+ }
340
+ const host = getRuntimeTooling(detectCliHostRuntime())
341
+ const xBin = host.tscBin.trim().split(/\s+/)[0] // bunx | npx
342
+ const scriptsBase = `node ${packageDefaults.packageRootFolder}/bin/scripts`
329
343
  const steps = [
330
- `${scripts}/sync-cli-defaults.mjs`,
344
+ `${scriptsBase}/sync-cli-defaults.mjs`,
331
345
  `rm -rf ${distRel}`,
332
- `bun run tsc --project ${tsconfigRel}`,
333
- `bunx tsc-alias -p ${tsconfigRel}`,
346
+ `${host.tscBin} --project ${resolvedTsconfig}`,
347
+ `${xBin} tsc-alias -p ${resolvedTsconfig}`,
334
348
  ]
349
+
335
350
  if (resolveMinifyEnabled(buildConfig)) {
336
- steps.push(`${scripts}/minify-dist.mjs`)
351
+ steps.push(`${scriptsBase}/minify-dist.mjs`)
337
352
  }
338
- steps.push(`${scripts}/fix-dist-imports.mjs`)
339
- steps.push(`${scripts}/clean-dist-tests.mjs`)
340
- steps.push(`${scripts}/clean-source-types.mjs`)
353
+ steps.push(`${scriptsBase}/fix-dist-imports.mjs`)
354
+ steps.push(`${scriptsBase}/clean-dist-tests.mjs`)
355
+ steps.push(`${scriptsBase}/clean-source-types.mjs`)
341
356
  return steps
342
357
  }
343
358
 
@@ -29,7 +29,13 @@ function findAuthoredDefaultsPath(root) {
29
29
  return
30
30
  }
31
31
  for (const entry of entries) {
32
- if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'x') continue
32
+ if (entry.name.startsWith('.') || entry.name === 'node_modules') continue
33
+ if (
34
+ packageIdentityDefaults?.packageRootFolder
35
+ && entry.name === packageIdentityDefaults.packageRootFolder
36
+ ) {
37
+ continue
38
+ }
33
39
  const full = path.join(dir, entry.name)
34
40
  if (entry.isDirectory()) {
35
41
  walk(full, depth + 1)
@@ -6,21 +6,25 @@ import { fileURLToPath } from 'node:url'
6
6
  import { isCorePackageName } from './build-config.mjs'
7
7
  import { auditTsconfigAlignment, syncProjectToolchain } from './toolchain-config.mjs'
8
8
  import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
9
- import { packageDefaults, resolveCliBinEntry } from './package-defaults.mjs'
9
+ import { packageDefaults, resolveCliBinEntry, resolveMainSourceRel } from './package-defaults.mjs'
10
+ import { RuntimeEnum, getRuntimeTooling } from './cli-runtime.mjs'
10
11
 
11
12
  const CLI_BIN_DIR = path.dirname(fileURLToPath(import.meta.url))
12
13
  const CLI_GENERATED_DIR = path.join(CLI_BIN_DIR, '.generated')
13
14
 
14
- const CLI_GENERATED_MODULES = [
15
- {
16
- source: 'source/utils/helpers/tmp/tmp-schema.ts',
17
- outfile: path.join(CLI_GENERATED_DIR, 'tmp-schema.mjs'),
18
- },
19
- {
20
- source: 'source/utils/helpers/tmp/seed-from-tmp.ts',
21
- outfile: path.join(CLI_GENERATED_DIR, 'seed-from-tmp.mjs'),
22
- },
23
- ]
15
+ function cliGeneratedModules() {
16
+ const main = resolveMainSourceRel()
17
+ return [
18
+ {
19
+ source: `${main}/utils/helpers/tmp/tmp-schema.ts`,
20
+ outfile: path.join(CLI_GENERATED_DIR, 'tmp-schema.mjs'),
21
+ },
22
+ {
23
+ source: `${main}/utils/helpers/tmp/seed-from-tmp.ts`,
24
+ outfile: path.join(CLI_GENERATED_DIR, 'seed-from-tmp.mjs'),
25
+ },
26
+ ]
27
+ }
24
28
 
25
29
  const CORE_EXPORT_SUBPATHS = [
26
30
  'utils',
@@ -97,12 +101,12 @@ function stablePackageShape(pkg) {
97
101
 
98
102
 
99
103
  /**
100
- * Defaults identity is authored at source/utils/constants/defaults.json.
101
- * npm has no source/ — defaults are embedded into .generated/seed-from-tmp.mjs via bun build.
104
+ * Defaults identity is authored at <mainSource>/utils/constants/defaults.json.
105
+ * npm has no source tree — defaults are embedded into .generated/seed-from-tmp.mjs via host bundler.
102
106
  * This sync rebuilds generated CLI modules when authored defaults/seed sources change.
103
107
  */
104
108
  export function syncCliDefaults(root = process.cwd(), { force = false } = {}) {
105
- const authored = path.join(root, 'source/utils/constants/defaults.json')
109
+ const authored = path.join(root, resolveMainSourceRel(), 'utils/constants/defaults.json')
106
110
  const seedOut = path.join(CLI_GENERATED_DIR, 'seed-from-tmp.mjs')
107
111
  const needs = force
108
112
  || !fs.existsSync(seedOut)
@@ -124,8 +128,9 @@ export function syncCliDefaults(root = process.cwd(), { force = false } = {}) {
124
128
  export function syncCliGeneratedModules(root = process.cwd(), { force = false } = {}) {
125
129
  const results = []
126
130
  fs.mkdirSync(CLI_GENERATED_DIR, { recursive: true })
131
+ const bun = getRuntimeTooling(RuntimeEnum.BUN)
127
132
 
128
- for (const mod of CLI_GENERATED_MODULES) {
133
+ for (const mod of cliGeneratedModules()) {
129
134
  const srcAbs = path.join(root, mod.source)
130
135
  if (!fs.existsSync(srcAbs)) {
131
136
  results.push({ source: mod.source, synced: false, reason: 'missing source' })
@@ -142,13 +147,13 @@ export function syncCliGeneratedModules(root = process.cwd(), { force = false }
142
147
  }
143
148
 
144
149
  execSync(
145
- `bun build "${srcAbs}" --outfile "${mod.outfile}" --target node --format esm --external yaml --external handlebars`,
150
+ `${bun.binRunner} build "${srcAbs}" --outfile "${mod.outfile}" --target node --format esm --external yaml --external handlebars`,
146
151
  { cwd: root, stdio: 'pipe' },
147
152
  )
148
153
  results.push({ source: mod.source, synced: true, out: mod.outfile })
149
154
  }
150
155
 
151
- const fromLines = CLI_GENERATED_MODULES.map((m) => m.source).join('\n')
156
+ const fromLines = cliGeneratedModules().map((m) => m.source).join('\n')
152
157
  fs.writeFileSync(path.join(CLI_GENERATED_DIR, '.generated-from'), `${fromLines}\n`)
153
158
  return { synced: results.some((r) => r.synced), results }
154
159
  }
@@ -1,4 +1,13 @@
1
- import { CLI_PRIMARY_NAME } from './cli-identity.mjs'
1
+ import { CLI_PRIMARY_NAME, PACKAGE_NAME } from './cli-identity.mjs'
2
+
3
+ function requireTsconfigRel() {
4
+ const rel = packageDefaults.buildDefaults?.tsconfig
5
+ if (!rel || !String(rel).trim()) {
6
+ throw new Error(`${PACKAGE_NAME}: buildDefaults.tsconfig missing in defaults.json`)
7
+ }
8
+ return String(rel)
9
+ }
10
+
2
11
  import fs from 'node:fs'
3
12
  import path from 'node:path'
4
13
 
@@ -94,7 +103,7 @@ export function mergeTsconfigWithLayout(recommended, existing = {}, extendsPath)
94
103
  return merged
95
104
  }
96
105
 
97
- export function readProjectTsconfig(root, tsconfigRel = packageDefaults.buildDefaults?.tsconfig ?? 'tsconfig.json') {
106
+ export function readProjectTsconfig(root, tsconfigRel = requireTsconfigRel()) {
98
107
  const abs = path.isAbsolute(tsconfigRel) ? tsconfigRel : path.join(root, tsconfigRel)
99
108
  if (!fs.existsSync(abs)) return null
100
109
 
@@ -105,7 +114,7 @@ export function readProjectTsconfig(root, tsconfigRel = packageDefaults.buildDef
105
114
  }
106
115
  }
107
116
 
108
- export function syncProjectToolchain(root = process.cwd(), { write = true, tsconfigRel = 'tsconfig.json' } = {}) {
117
+ export function syncProjectToolchain(root = process.cwd(), { write = true, tsconfigRel = requireTsconfigRel() } = {}) {
109
118
  const layout = resolveTmpLayoutOrDefaults(root)
110
119
  const options = layoutToToolchainOptions(layout)
111
120
  const recommended = resolveRecommendedTsconfig(options)
@@ -142,7 +151,7 @@ export function auditTsconfigAlignment(root, options = null) {
142
151
  const recommended = resolveRecommendedTsconfig(resolvedOptions)
143
152
  const onDisk = readProjectTsconfig(root)
144
153
  if (!onDisk) {
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`] }
154
+ return { ok: false, missing: true, notes: [`${requireTsconfigRel()} not found — auto-healed on layout change, next ${CLI_PRIMARY_NAME} command, or ${CLI_PRIMARY_NAME} sync`] }
146
155
  }
147
156
 
148
157
  const notes = []
@@ -169,7 +178,10 @@ export function auditTsconfigAlignment(root, options = null) {
169
178
 
170
179
  export function createEslintConfigFromProject(root = process.cwd(), tseslint) {
171
180
  const paths = resolveToolchainPathsFromProject(root)
172
- const depth = packageDefaults.eslintRestrictedImportDepth ?? 2
181
+ const depth = packageDefaults.eslintRestrictedImportDepth
182
+ if (typeof depth !== 'number') {
183
+ throw new Error(`${PACKAGE_NAME}: eslintRestrictedImportDepth missing in defaults.json`)
184
+ }
173
185
  const deepRelative = '../'.repeat(depth + 1)
174
186
 
175
187
  return tseslint.config(
@@ -1,7 +1,13 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
- const distRoot = path.join(process.cwd(), 'x', 'dist')
4
+ import { packageDefaults } from '../helpers/package-defaults.mjs'
5
+
6
+ const distRoot = path.join(
7
+ process.cwd(),
8
+ packageDefaults.packageRootFolder,
9
+ packageDefaults.layoutPaths.dist,
10
+ )
5
11
  const TEST_FILE_RE = /\.test\.(js|d\.ts)$/
6
12
 
7
13
  export function cleanDistTests(distDir = distRoot) {
@@ -1,7 +1,12 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
+ import { packageDefaults } from '../helpers/package-defaults.mjs'
3
4
 
4
- const distRoot = path.join(process.cwd(), 'x', 'dist')
5
+ const distRoot = path.join(
6
+ process.cwd(),
7
+ packageDefaults.packageRootFolder,
8
+ packageDefaults.layoutPaths.dist,
9
+ )
5
10
 
6
11
  const HAS_EXT = /\.(js|mjs|cjs|json|node|wasm)(\?.*)?$/i
7
12
 
@@ -2,7 +2,14 @@ import { spawnSync } from 'node:child_process'
2
2
  import fs from 'node:fs'
3
3
  import path from 'node:path'
4
4
 
5
- const distRoot = path.join(process.cwd(), 'x', 'dist')
5
+ import { packageDefaults } from '../helpers/package-defaults.mjs'
6
+ import { RuntimeEnum, getRuntimeTooling } from '../helpers/cli-runtime.mjs'
7
+
8
+ const distRoot = path.join(
9
+ process.cwd(),
10
+ packageDefaults.packageRootFolder,
11
+ packageDefaults.layoutPaths.dist,
12
+ )
6
13
 
7
14
  function walkJsFiles(dir, out = []) {
8
15
  for (const name of fs.readdirSync(dir)) {
@@ -18,8 +25,9 @@ function walkJsFiles(dir, out = []) {
18
25
  }
19
26
 
20
27
  export function minifyDistFile(file) {
28
+ const bun = getRuntimeTooling(RuntimeEnum.BUN)
21
29
  const result = spawnSync(
22
- 'bun',
30
+ bun.binRunner,
23
31
  ['build', file, '--outfile', file, '--minify', '--no-bundle', '--external', '*'],
24
32
  { stdio: 'pipe', encoding: 'utf8' },
25
33
  )
@@ -3,13 +3,18 @@ import fs from 'node:fs'
3
3
  import path from 'node:path'
4
4
 
5
5
  import { packageDefaults } from '../paths.mjs'
6
+ import { detectCliHostRuntime, getRuntimeTooling } from '../helpers/cli-runtime.mjs'
6
7
  import { resolveProjectRoot } from '../helpers/project-root.mjs'
7
8
 
8
- const PREPARE_STEPS = [
9
- { name: 'lint', cmd: 'bun run lint' },
10
- { name: 'test', cmd: 'bun test x/tests' },
11
- { name: 'build', cmd: 'bun run build' },
12
- ]
9
+ function buildPrepareSteps() {
10
+ const host = getRuntimeTooling(detectCliHostRuntime())
11
+ // Use package.json scripts (SSOT) — not raw testRunner against a folder
12
+ return [
13
+ { name: 'lint', cmd: `${host.scriptRunner} lint` },
14
+ { name: 'test', cmd: `${host.scriptRunner} test` },
15
+ { name: 'build', cmd: `${host.scriptRunner} build` },
16
+ ]
17
+ }
13
18
 
14
19
  function run(cmd, { root, inherit = false } = {}) {
15
20
  execSync(cmd, {
@@ -42,7 +47,7 @@ export function runReleasePrepare({ root = resolveProjectRoot(), dryRun = false,
42
47
  console.log(`\nRelease prepare (${packageDefaults.packageName}):\n`)
43
48
  console.log(' (npm publish CI converts source → .js; git keeps TypeScript)\n')
44
49
 
45
- for (const step of PREPARE_STEPS) {
50
+ for (const step of buildPrepareSteps()) {
46
51
  console.log(`→ ${step.name}`)
47
52
  if (dryRun) {
48
53
  console.log(` [dry-run] ${step.cmd}`)
@@ -1 +1 @@
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)}}
1
+ import Q from"../../../utils/constants/defaults.json" with { type: 'json' };import{BundlerEnum as D,RuntimeEnum as M}from"../../../utils/models/enums";import{seedFromTmp as U}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 H(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===M.NODE)return M.NODE;if(q===M.BUN)return M.BUN;if(!q)throw Error(`${Q.packageName}: configs.global.runtime is required (${Object.values(M).join("|")})`);throw Error(`${Q.packageName}: unknown configs.global.runtime "${String(j)}" (expected ${Object.values(M).join("|")})`)}export function normalizeBundler(j){const q=typeof j==="string"?j.trim().toLowerCase():"";if(!q)return D.AUTO;if(q===D.TSC)return D.TSC;if(q===D.ESBUILD)return D.ESBUILD;if(q===D.BUN)return D.BUN;if(q===D.AUTO)return D.AUTO;throw Error(`${Q.packageName}: unknown build.bundler "${String(j)}" (expected ${Object.values(D).join("|")})`)}export function resolveEffectiveBundler(j,q){if(j!==D.AUTO)return j;return q===M.NODE?D.TSC:D.BUN}export function normalizeRootFolder(j){return $(j,Q.packageRootFolder)}export function normalizeSourceFolder(j){return I(j,U.sourceFolder)}export function readTmpGlobalBlock(j){const q=H(j?.global)?j.global:{},A=H(q.vars)?q.vars:{};return{runtime:normalizeRuntime(q.runtime),vars:{...A}}}export function readTmpCoreBlock(j){const q=H(j?.core)?j.core:{},A=H(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:x(A.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=H(j?.service)?j.service:{},A=H(q.paths)?q.paths:{},J=H(A.special)?A.special:{};let K=H(q.loaders)?{...q.loaders}:void 0,O=H(q.build)?q.build:void 0;if(K&&H(K.build)){const{build:X,...Y}=K;K=Y;if(!O&&H(X))O=X}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:O}}export function resolveServiceLayoutPaths(j){return _(j.paths?.special,U.layout)}function L(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??U.framework,paths:{root:j.paths?.root??Q.packageRootFolder,source:j.paths?.source??U.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=H(j.configs)?j.configs:{},A=readTmpGlobalBlock(q);return Z(j,buildTmpVarContext(A))}export function resolveTmpRuntimeConfigs(j){const q=H(j?.configs)?j.configs:{},A=readTmpGlobalBlock(q),J=readTmpServiceBlock(q),K=readTmpCoreBlock(q),O=L(J);return{global:A,service:O,core:N(K),rootFolderPath:normalizeRootFolder(O.paths.root)}}export function normalizeTmpDocument(j){const q=applyTmpGlobalVars(j);return{...q,configs:resolveTmpRuntimeConfigs(q)}}
@@ -1 +1 @@
1
- import{packageDefaults as I}from"../../../utils/constants";import{readTmpCoreBlock as J}from"../../../utils/helpers/tmp/tmp-schema";const b=I.tmpWatchDefaults;export function resolveTmpWatchIntervalMs(q){const v=q?.configs,y=J(v).tmp?.fileWatchIntervalMs??b.intervalMs,j=Number(y);if(!Number.isFinite(j))return b.intervalMs;const z=b.minIntervalMs??100,G=b.maxIntervalMs??1e4;return Math.min(G,Math.max(z,Math.round(j)))}
1
+ import{packageDefaults as J}from"../../../utils/constants";import{readTmpCoreBlock as P}from"../../../utils/helpers/tmp/tmp-schema";const Q=J.tmpWatchDefaults;function z(y){const j=Q?.[y];if(typeof j!=="number"||!Number.isFinite(j))throw Error(`${J.packageName}: tmpWatchDefaults.${y} missing in defaults.json`);return j}export function resolveTmpWatchIntervalMs(y){const j=y?.configs,K=P(j),G=z("intervalMs"),M=K.tmp?.fileWatchIntervalMs??G,I=Number(M);if(!Number.isFinite(I))return G;const N=z("minIntervalMs"),O=z("maxIntervalMs");return Math.min(O,Math.max(N,Math.round(I)))}
@@ -1,2 +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}}
1
+ import Q from"node:fs";import Y from"node:path";import{packageDefaults as M}from"../../../utils/constants";import{normalizeSourceFolder as C}from"../../../utils/helpers/tmp/path-normalize";function Z(j){return String(j).replace(/^\.\//,"")}function _(){const j=M.buildDefaults?.tsconfig;if(!j||!String(j).trim())throw Error(`${M.packageName}: buildDefaults.tsconfig missing in defaults.json`);return String(j)}export function layoutOptionsFromRuntimeConfigs(j){const B=j.service?.paths,G=B?.special;return{rootFolderPath:j.rootFolderPath||M.packageRootFolder,mainFolderPath:C(B?.source,M.mainSourceFolder),pathsDist:G?.dist||M.layoutPaths.dist,pathsTests:G?.tests||M.layoutPaths.tests}}export function layoutFingerprint(j){return[j.rootFolderPath,Z(j.mainFolderPath),j.pathsDist,j.pathsTests].join("\x00")}export function resolveRecommendedTsconfig(j){const B=Z(j.mainFolderPath),G=j.rootFolderPath,I=M.pathAliasKey;return{include:[B],exclude:[`${G}/${j.pathsTests}`],compilerOptions:{baseUrl:".",paths:{[I]:[`${B}/*`]},rootDir:`./${B}`,outDir:`./${G}/${j.pathsDist}`}}}function E(j){const B=Y.join(j,"package.json");if(!Q.existsSync(B))return`${M.packageName}/tsconfig.base.json`;try{if(JSON.parse(Q.readFileSync(B,"utf8")).name===M.packageName)return"./tsconfig.base.json"}catch{}return`${M.packageName}/tsconfig.base.json`}function W(j,B,G){const I=B.compilerOptions??{};return{...B,extends:B.extends??G,include:j.include,exclude:j.exclude,compilerOptions:{...I,baseUrl:j.compilerOptions.baseUrl,paths:j.compilerOptions.paths,rootDir:j.compilerOptions.rootDir,outDir:j.compilerOptions.outDir}}}export function auditTsconfigAgainstLayout(j,B,G=_()){const I=Y.join(j,G);if(!Q.existsSync(I))return{ok:!1,missing:!0,notes:[`${G} missing`]};let J;try{J=JSON.parse(Q.readFileSync(I,"utf8"))}catch{return{ok:!1,missing:!1,notes:[`${G} unreadable`]}}const H=resolveRecommendedTsconfig(B),N=[],V=J.compilerOptions??{},X=M.pathAliasKey;if(V.outDir!==H.compilerOptions.outDir)N.push("outDir drift");if(!(Array.isArray(J.include)?J.include.map(String):[]).some((A)=>Z(A)===H.include[0]))N.push("include drift");const $=V.paths?.[X];if(JSON.stringify($)!==JSON.stringify(H.compilerOptions.paths[X]))N.push(`paths ${X} drift`);return{ok:N.length===0,missing:!1,notes:N}}export function writeTsconfigFromLayout(j,B,G=_()){const I=Y.join(j,G),J=!Q.existsSync(I);let H={};if(!J)try{H=JSON.parse(Q.readFileSync(I,"utf8"))}catch{H={}}const N=resolveRecommendedTsconfig(B),V=W(N,H,E(j));Q.writeFileSync(I,`${JSON.stringify(V,null,2)}
2
+ `,"utf8");return{wrote:!0,created:J,abs:I}}let U=null;export function resetToolchainHealState(){U=null}export function healToolchainIfLayoutNeedsSync(j,B,G={}){const I=layoutOptionsFromRuntimeConfigs(B),J=layoutFingerprint(I),H=_(),N=auditTsconfigAgainstLayout(j,I,H);if(U===null){U=J;if(N.ok)return{healed:!1,tsconfigRel:H,fingerprint:J};writeTsconfigFromLayout(j,I,H);if(!G.quiet)console.info(`[${M.packageName}] toolchain auto-synced (${H}) — bootstrap layout drift`);return{healed:!0,reason:"bootstrap",tsconfigRel:H,fingerprint:J}}if(J===U)return{healed:!1,tsconfigRel:H,fingerprint:J};U=J;writeTsconfigFromLayout(j,I,H);if(!G.quiet)console.info(`[${M.packageName}] toolchain auto-synced (${H}) — tmp layout paths changed`);return{healed:!0,reason:"layout-changed",tsconfigRel:H,fingerprint:J}}