@xrystal/core 3.45.2 → 3.46.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 +18 -14
- package/package.json +1 -1
- package/x/bin/commands/doctor.mjs +2 -1
- package/x/bin/commands/sync.mjs +1 -1
- package/x/bin/helpers/.generated/tmp-schema.mjs +21 -2
- package/x/bin/helpers/build-config.mjs +26 -11
- package/x/bin/helpers/package-defaults.mjs +7 -1
- package/x/bin/helpers/project-artifacts.mjs +22 -17
- package/x/bin/helpers/toolchain-config.mjs +17 -5
- package/x/bin/scripts/clean-dist-tests.mjs +7 -1
- package/x/bin/scripts/fix-dist-imports.mjs +6 -1
- package/x/bin/scripts/minify-dist.mjs +10 -2
- package/x/bin/scripts/release-prepare.mjs +11 -6
- package/x/dist/utils/constants/index.js +1 -1
- package/x/dist/utils/constants/package-root.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -1
- package/x/dist/utils/helpers/tmp/toolchain-heal.js +2 -2
- package/x/dist/utils/package-root.js +0 -1
- /package/x/dist/utils/{package-root.d.ts → constants/package-root.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -3,25 +3,25 @@
|
|
|
3
3
|
> **EN** — Microservice runtime: Express or Elysia HTTP, DI loaders, live `tmp.yml`, standardized API responses.
|
|
4
4
|
> **TR** — Microservice runtime: Express veya Elysia HTTP, DI loader'lar, canlı `tmp.yml`, standart API cevapları.
|
|
5
5
|
|
|
6
|
-
**CLI:** `xry` · **Version:** `3.
|
|
6
|
+
**CLI:** `xry` · **Version:** `3.46.0` · [npm](https://www.npmjs.com/package/@xrystal/core)
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
## What's new in 3.
|
|
10
|
+
## What's new in 3.46.0 / 3.46.0'da ne değişti
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|---------------------|----|----|
|
|
14
|
-
| **Runtime SSOT** | `defaults.runtimes` + `RuntimeEnum`; no Bun/Node hardcodes in CLI | Runtime hardcode kalktı |
|
|
15
|
-
| **tmp.global.runtime** | Banner/project runtime from tmp.yml | Proje runtime tmp'den |
|
|
12
|
+
**EN:** SSOT architecture is closed — identity, runtime tooling, paths, and CLI share one source of truth. Missing values throw; layout drift auto-heals.
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
**TR:** SSOT mimarisi kapandı — kimlik, runtime tooling, path ve CLI tek kaynaktan. Eksik değer throw; path drift otomatik heal.
|
|
18
15
|
|
|
19
16
|
| Change / Değişiklik | EN | TR |
|
|
20
17
|
|---------------------|----|----|
|
|
21
|
-
| **
|
|
22
|
-
| **
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
| **Identity** | CLI display = `@xrystal/core`; invoke bin = `xry` | Kimlik paket adı, bin `xry` |
|
|
19
|
+
| **defaults.json** | Package name, CLI, brand, `runtimes{}`, `bundlers[]` | Paket kimliği + tooling haritası |
|
|
20
|
+
| **tmp.yml** | Layout, `global.runtime`, vars, `build.bundler` | Proje layout + runtime |
|
|
21
|
+
| **Live pulse** | tmp watch → loader sync; path drift → tsconfig heal | Canlı sync + otomatik heal |
|
|
22
|
+
| **Strict normalize** | Unknown/missing `runtime` / `bundler` throws (empty bundler → `auto`) | Sessiz `?? 'bun'` yok |
|
|
23
|
+
| **Tooling map** | Scripts/build/CLI use `defaults.runtimes` (no `bun` / `x/dist` literals) | Hardcode temiz |
|
|
24
|
+
| **`xry sync`** | Force / CI only — daily ritual değil | Force / CI |
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
27
|
npx xry sync # force-apply tmp.yml → tsconfig (usually auto)
|
|
@@ -86,7 +86,7 @@ npx xry doctor # EN: optional health check · TR: isteğe bağlı sağlı
|
|
|
86
86
|
```json
|
|
87
87
|
{
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@xrystal/core": "^3.
|
|
89
|
+
"@xrystal/core": "^3.46.0",
|
|
90
90
|
"elysia": "^1.4.19"
|
|
91
91
|
},
|
|
92
92
|
"scripts": {
|
|
@@ -120,9 +120,13 @@ my-api/
|
|
|
120
120
|
|
|
121
121
|
| File / Dosya | Owns / Sahip olduğu |
|
|
122
122
|
|--------------|---------------------|
|
|
123
|
-
| `
|
|
123
|
+
| `defaults.json` (package) | Identity (`@xrystal/core`), CLI bin (`xry`), brand, `runtimes` / `bundlers` tooling |
|
|
124
|
+
| `x/tmp.yml` | Service paths, loaders, protocols, `global.runtime`, bundler · layout seed |
|
|
124
125
|
| `tsconfig.json` | Compiler language options; path layout auto-heals from `tmp.yml` |
|
|
125
|
-
|
|
126
|
+
|
|
127
|
+
**EN:** Edit `tmp.yml` for your project. Package defaults stay inside `@xrystal/core` — do not hardcode runtime/bin/path names in app code.
|
|
128
|
+
|
|
129
|
+
**TR:** Projede `tmp.yml` düzenle. Paket default'ları `@xrystal/core` içinde kalır — uygulama kodunda runtime/bin/path hardcode etme.
|
|
126
130
|
|
|
127
131
|
### Minimal `x/tmp.yml`
|
|
128
132
|
|
package/package.json
CHANGED
|
@@ -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:
|
|
107
|
+
console.log(chalk.gray(` fix: ${getRuntimeTooling(detectCliHostRuntime()).packageManager} add ${packageDefaults.packageName}@${cliPkg.version}`))
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
printSection('Git')
|
package/x/bin/commands/sync.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
:
|
|
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
|
|
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
|
|
328
|
-
|
|
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
|
-
`${
|
|
344
|
+
`${scriptsBase}/sync-cli-defaults.mjs`,
|
|
331
345
|
`rm -rf ${distRel}`,
|
|
332
|
-
|
|
333
|
-
|
|
346
|
+
`${host.tscBin} --project ${resolvedTsconfig}`,
|
|
347
|
+
`${xBin} tsc-alias -p ${resolvedTsconfig}`,
|
|
334
348
|
]
|
|
349
|
+
|
|
335
350
|
if (resolveMinifyEnabled(buildConfig)) {
|
|
336
|
-
steps.push(`${
|
|
351
|
+
steps.push(`${scriptsBase}/minify-dist.mjs`)
|
|
337
352
|
}
|
|
338
|
-
steps.push(`${
|
|
339
|
-
steps.push(`${
|
|
340
|
-
steps.push(`${
|
|
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'
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
101
|
-
* npm has no source
|
|
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, '
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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: [
|
|
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
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
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 w from"node:path";import{packageRootDir as x}from"../../utils/package-root";import b from"./defaults.json" with { type: 'json' };import{seedFromTmp as j}from"../../utils/helpers/tmp/seed-from-tmp";export const packageDefaults=Object.freeze({...b,mainSourceFolder:j.sourceFolder,framework:j.framework,layoutPaths:Object.freeze({...j.layout}),brand:Object.freeze({...b.brand}),runtimes:Object.freeze(Object.fromEntries(Object.entries(b.runtimes).map(([n,q])=>[n,Object.freeze({...q})]))),bundlers:Object.freeze([...b.bundlers]),buildDefaults:Object.freeze({...b.buildDefaults}),tmpWatchDefaults:Object.freeze({...b.tmpWatchDefaults}),cliBinNames:Object.freeze([...b.cliBinNames??[b.cliName]])}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const z=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static cliName=packageDefaults.cliName;static cliBinNames=packageDefaults.cliBinNames;static pathAliasKey=packageDefaults.pathAliasKey;static brand=packageDefaults.brand;static mainSourceFolder=packageDefaults.mainSourceFolder;static framework=packageDefaults.framework;static layoutPaths=packageDefaults.layoutPaths;static cliBinFile=packageDefaults.cliBinFile;static logTag=packageDefaults.packageName;static bundledCoreTmpPath=w.join(x,packageDefaults.packageRootFolder,z)}export{seedFromTmp,loadSeedFromBundledTmp}from"../../utils/helpers/tmp/seed-from-tmp";
|
|
1
|
+
import w from"node:path";import{packageRootDir as x}from"../../utils/constants/package-root";import b from"./defaults.json" with { type: 'json' };import{seedFromTmp as j}from"../../utils/helpers/tmp/seed-from-tmp";export const packageDefaults=Object.freeze({...b,mainSourceFolder:j.sourceFolder,framework:j.framework,layoutPaths:Object.freeze({...j.layout}),brand:Object.freeze({...b.brand}),runtimes:Object.freeze(Object.fromEntries(Object.entries(b.runtimes).map(([n,q])=>[n,Object.freeze({...q})]))),bundlers:Object.freeze([...b.bundlers]),buildDefaults:Object.freeze({...b.buildDefaults}),tmpWatchDefaults:Object.freeze({...b.tmpWatchDefaults}),cliBinNames:Object.freeze([...b.cliBinNames??[b.cliName]])}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const z=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static cliName=packageDefaults.cliName;static cliBinNames=packageDefaults.cliBinNames;static pathAliasKey=packageDefaults.pathAliasKey;static brand=packageDefaults.brand;static mainSourceFolder=packageDefaults.mainSourceFolder;static framework=packageDefaults.framework;static layoutPaths=packageDefaults.layoutPaths;static cliBinFile=packageDefaults.cliBinFile;static logTag=packageDefaults.packageName;static bundledCoreTmpPath=w.join(x,packageDefaults.packageRootFolder,z)}export{seedFromTmp,loadSeedFromBundledTmp}from"../../utils/helpers/tmp/seed-from-tmp";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import b from"node:path";import{fileURLToPath as w}from"node:url";const q=b.dirname(w(import.meta.url));export const sourceDir=b.resolve(q,"..",".."),packageRootDir=b.resolve(q,"..","..","..");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
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
|
|
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
|
|
2
|
-
`,"utf8");return{wrote:!0,created:
|
|
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}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import o from"node:path";import{fileURLToPath as t}from"node:url";const r=o.dirname(t(import.meta.url));export const sourceDir=o.resolve(r,".."),packageRootDir=o.resolve(r,"..","..");
|
|
File without changes
|