@xrystal/core 3.45.1 → 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 +16 -2
- 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/seed-from-tmp.mjs +30 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +51 -2
- package/x/bin/helpers/build-config.mjs +49 -32
- package/x/bin/helpers/cli-runtime.mjs +84 -0
- package/x/bin/helpers/package-defaults.mjs +30 -1
- package/x/bin/helpers/project-artifacts.mjs +22 -17
- package/x/bin/helpers/runtime-info.mjs +13 -4
- package/x/bin/helpers/toolchain-config.mjs +17 -5
- package/x/bin/main-cli.js +5 -9
- 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/defaults.json +30 -0
- package/x/dist/utils/constants/index.js +1 -1
- 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/README.md
CHANGED
|
@@ -3,10 +3,24 @@
|
|
|
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.
|
|
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
|
+
|
|
17
|
+
## What's new in 3.45.2 / 3.45.2'da ne değişti
|
|
18
|
+
|
|
19
|
+
| Change / Değişiklik | EN | TR |
|
|
20
|
+
|---------------------|----|----|
|
|
21
|
+
| **Runtime SSOT** | `defaults.runtimes` + `RuntimeEnum`; no Bun/Node hardcodes in CLI | Runtime hardcode kalktı |
|
|
22
|
+
| **tmp.global.runtime** | Banner/project runtime from tmp.yml | Proje runtime tmp'den |
|
|
23
|
+
|
|
10
24
|
## What's new in 3.45.1 / 3.45.1'da ne değişti
|
|
11
25
|
|
|
12
26
|
| Change / Değişiklik | EN | TR |
|
|
@@ -79,7 +93,7 @@ npx xry doctor # EN: optional health check · TR: isteğe bağlı sağlı
|
|
|
79
93
|
```json
|
|
80
94
|
{
|
|
81
95
|
"dependencies": {
|
|
82
|
-
"@xrystal/core": "^3.45.
|
|
96
|
+
"@xrystal/core": "^3.45.4",
|
|
83
97
|
"elysia": "^1.4.19"
|
|
84
98
|
},
|
|
85
99
|
"scripts": {
|
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 })
|
|
@@ -25,6 +25,36 @@ var defaults_default = {
|
|
|
25
25
|
tagline: "microservice runtime library",
|
|
26
26
|
capabilities: "loaders · tmp.yml · dto · i18n · multi-protocol · scaffold"
|
|
27
27
|
},
|
|
28
|
+
runtimes: {
|
|
29
|
+
bun: {
|
|
30
|
+
label: "Bun",
|
|
31
|
+
packageManager: "bun",
|
|
32
|
+
installCommand: "bun install",
|
|
33
|
+
scriptRunner: "bun run",
|
|
34
|
+
binRunner: "bun",
|
|
35
|
+
testRunner: "bun test",
|
|
36
|
+
tscBin: "bunx tsc",
|
|
37
|
+
esbuildBin: "bunx esbuild",
|
|
38
|
+
devInvoker: null
|
|
39
|
+
},
|
|
40
|
+
node: {
|
|
41
|
+
label: "Node.js",
|
|
42
|
+
packageManager: "npm",
|
|
43
|
+
installCommand: "npm install",
|
|
44
|
+
scriptRunner: "npm run",
|
|
45
|
+
binRunner: "node",
|
|
46
|
+
testRunner: "node --test",
|
|
47
|
+
tscBin: "npx tsc",
|
|
48
|
+
esbuildBin: "npx esbuild",
|
|
49
|
+
devInvoker: "npx"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
bundlers: [
|
|
53
|
+
"auto",
|
|
54
|
+
"bun",
|
|
55
|
+
"tsc",
|
|
56
|
+
"esbuild"
|
|
57
|
+
],
|
|
28
58
|
tmpWatchDefaults: {
|
|
29
59
|
intervalMs: 500,
|
|
30
60
|
minIntervalMs: 100,
|
|
@@ -20,6 +20,36 @@ var defaults_default = {
|
|
|
20
20
|
tagline: "microservice runtime library",
|
|
21
21
|
capabilities: "loaders · tmp.yml · dto · i18n · multi-protocol · scaffold"
|
|
22
22
|
},
|
|
23
|
+
runtimes: {
|
|
24
|
+
bun: {
|
|
25
|
+
label: "Bun",
|
|
26
|
+
packageManager: "bun",
|
|
27
|
+
installCommand: "bun install",
|
|
28
|
+
scriptRunner: "bun run",
|
|
29
|
+
binRunner: "bun",
|
|
30
|
+
testRunner: "bun test",
|
|
31
|
+
tscBin: "bunx tsc",
|
|
32
|
+
esbuildBin: "bunx esbuild",
|
|
33
|
+
devInvoker: null
|
|
34
|
+
},
|
|
35
|
+
node: {
|
|
36
|
+
label: "Node.js",
|
|
37
|
+
packageManager: "npm",
|
|
38
|
+
installCommand: "npm install",
|
|
39
|
+
scriptRunner: "npm run",
|
|
40
|
+
binRunner: "node",
|
|
41
|
+
testRunner: "node --test",
|
|
42
|
+
tscBin: "npx tsc",
|
|
43
|
+
esbuildBin: "npx esbuild",
|
|
44
|
+
devInvoker: "npx"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
bundlers: [
|
|
48
|
+
"auto",
|
|
49
|
+
"bun",
|
|
50
|
+
"tsc",
|
|
51
|
+
"esbuild"
|
|
52
|
+
],
|
|
23
53
|
tmpWatchDefaults: {
|
|
24
54
|
intervalMs: 500,
|
|
25
55
|
minIntervalMs: 100,
|
|
@@ -35,6 +65,20 @@ var defaults_default = {
|
|
|
35
65
|
}
|
|
36
66
|
};
|
|
37
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
|
+
|
|
38
82
|
// source/utils/helpers/tmp/seed-from-tmp.ts
|
|
39
83
|
import fs from "node:fs";
|
|
40
84
|
import path from "node:path";
|
|
@@ -162,10 +206,15 @@ function normalizeRuntime(value) {
|
|
|
162
206
|
return "node" /* NODE */;
|
|
163
207
|
if (raw === "bun" /* BUN */)
|
|
164
208
|
return "bun" /* BUN */;
|
|
165
|
-
|
|
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("|")})`);
|
|
166
213
|
}
|
|
167
214
|
function normalizeBundler(value) {
|
|
168
215
|
const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
216
|
+
if (!raw)
|
|
217
|
+
return "auto" /* AUTO */;
|
|
169
218
|
if (raw === "tsc" /* TSC */)
|
|
170
219
|
return "tsc" /* TSC */;
|
|
171
220
|
if (raw === "esbuild" /* ESBUILD */)
|
|
@@ -174,7 +223,7 @@ function normalizeBundler(value) {
|
|
|
174
223
|
return "bun" /* BUN */;
|
|
175
224
|
if (raw === "auto" /* AUTO */)
|
|
176
225
|
return "auto" /* AUTO */;
|
|
177
|
-
|
|
226
|
+
throw new Error(`${defaults_default.packageName}: unknown build.bundler "${String(value)}" (expected ${Object.values(BundlerEnum).join("|")})`);
|
|
178
227
|
}
|
|
179
228
|
function resolveEffectiveBundler(bundler, runtime) {
|
|
180
229
|
if (bundler !== "auto" /* AUTO */)
|
|
@@ -3,6 +3,7 @@ import path from 'node:path'
|
|
|
3
3
|
import yaml from 'yaml'
|
|
4
4
|
|
|
5
5
|
import { packageDefaults } from '../paths.mjs'
|
|
6
|
+
import { getRuntimeTooling, RuntimeEnum, BundlerEnum, detectCliHostRuntime } from './cli-runtime.mjs'
|
|
6
7
|
import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
|
|
7
8
|
import {
|
|
8
9
|
normalizeTmpDocument,
|
|
@@ -25,6 +26,14 @@ export const CLI_BUILD_SCRIPT_RE = new RegExp(
|
|
|
25
26
|
|
|
26
27
|
const BUILD_DEFAULTS = packageDefaults.buildDefaults ?? {}
|
|
27
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
|
+
|
|
28
37
|
export function isCorePackageName(name) {
|
|
29
38
|
return name === packageDefaults.packageName
|
|
30
39
|
}
|
|
@@ -57,7 +66,7 @@ export function resolveTsconfigRel(root, buildConfig = {}) {
|
|
|
57
66
|
const configured =
|
|
58
67
|
typeof buildConfig.tsconfig === 'string' && buildConfig.tsconfig.trim()
|
|
59
68
|
? buildConfig.tsconfig.trim()
|
|
60
|
-
:
|
|
69
|
+
: requireBuildTsconfig()
|
|
61
70
|
|
|
62
71
|
const abs = path.isAbsolute(configured) ? configured : path.join(root, configured)
|
|
63
72
|
if (!fs.existsSync(abs)) return null
|
|
@@ -233,17 +242,17 @@ export function resolveSourcemapFlag(buildConfig = {}, tsconfig = null) {
|
|
|
233
242
|
return ''
|
|
234
243
|
}
|
|
235
244
|
|
|
236
|
-
function resolveTscBin(runtime =
|
|
237
|
-
return runtime
|
|
245
|
+
function resolveTscBin(runtime = detectCliHostRuntime()) {
|
|
246
|
+
return getRuntimeTooling(runtime).tscBin
|
|
238
247
|
}
|
|
239
248
|
|
|
240
|
-
function withTscProject(root, buildConfig, extraArgs, runtime =
|
|
249
|
+
function withTscProject(root, buildConfig, extraArgs, runtime = detectCliHostRuntime()) {
|
|
241
250
|
const tsconfigRel = resolveTsconfigRel(root, buildConfig)
|
|
242
251
|
const projectFlag = tsconfigRel ? `--project ${tsconfigRel} ` : ''
|
|
243
252
|
return `${resolveTscBin(runtime)} ${projectFlag}${extraArgs}`.replace(/\s+/g, ' ').trim()
|
|
244
253
|
}
|
|
245
254
|
|
|
246
|
-
export function resolveTypecheckCommand(root, buildConfig = {}, runtime =
|
|
255
|
+
export function resolveTypecheckCommand(root, buildConfig = {}, runtime = detectCliHostRuntime()) {
|
|
247
256
|
const tsconfigRel = resolveTsconfigRel(root, buildConfig)
|
|
248
257
|
if (!tsconfigRel) {
|
|
249
258
|
throw new Error(
|
|
@@ -253,7 +262,7 @@ export function resolveTypecheckCommand(root, buildConfig = {}, runtime = 'bun')
|
|
|
253
262
|
return withTscProject(root, buildConfig, '--noEmit', runtime)
|
|
254
263
|
}
|
|
255
264
|
|
|
256
|
-
export function resolveTscCommand(root, distRel, buildConfig = {}, runtime =
|
|
265
|
+
export function resolveTscCommand(root, distRel, buildConfig = {}, runtime = detectCliHostRuntime()) {
|
|
257
266
|
const cmd = withTscProject(root, buildConfig, `--emitDeclarationOnly --declaration --outDir ${distRel}`, runtime)
|
|
258
267
|
return buildConfig.tscLenient ? `${cmd} || true` : cmd
|
|
259
268
|
}
|
|
@@ -262,33 +271,33 @@ export function resolveBunBuildCommand(entryGlobs, distRel, buildConfig = {}, ts
|
|
|
262
271
|
const sourcemapFlag = resolveSourcemapFlag(buildConfig, tsconfig)
|
|
263
272
|
const minifyFlags = resolveMinifyFlags(buildConfig)
|
|
264
273
|
const flags = [...minifyFlags, ...(sourcemapFlag ? [sourcemapFlag] : []), '--outdir', distRel, '--target', 'node', "--external", "'*'"]
|
|
265
|
-
return
|
|
274
|
+
return `${getRuntimeTooling(RuntimeEnum.BUN).binRunner} build ${entryGlobs.join(' ')} ${flags.join(' ')}`.replace(/\s+/g, ' ').trim()
|
|
266
275
|
}
|
|
267
276
|
|
|
268
|
-
export function resolveTscBuildCommand(root, distRel, buildConfig = {}, runtime =
|
|
277
|
+
export function resolveTscBuildCommand(root, distRel, buildConfig = {}, runtime = detectCliHostRuntime()) {
|
|
269
278
|
return withTscProject(root, buildConfig, `--outDir ${distRel}`, runtime)
|
|
270
279
|
}
|
|
271
280
|
|
|
272
|
-
export function resolveEsbuildBuildCommand(entryGlobs, distRel, buildConfig = {}, tsconfig = null, runtime =
|
|
281
|
+
export function resolveEsbuildBuildCommand(entryGlobs, distRel, buildConfig = {}, tsconfig = null, runtime = detectCliHostRuntime()) {
|
|
273
282
|
const minify = resolveMinifyEnabled(buildConfig) ? ' --minify' : ''
|
|
274
283
|
const sourcemapFlag = resolveSourcemapFlag(buildConfig, tsconfig)
|
|
275
284
|
const sourcemap = sourcemapFlag ? ' --sourcemap' : ''
|
|
276
|
-
const bin = runtime
|
|
285
|
+
const bin = getRuntimeTooling(runtime).esbuildBin
|
|
277
286
|
const entries = entryGlobs.join(' ')
|
|
278
287
|
return `${bin} ${entries} --bundle --platform=node --packages=external --outdir=${distRel}${minify}${sourcemap}`.replace(/\s+/g, ' ').trim()
|
|
279
288
|
}
|
|
280
289
|
|
|
281
|
-
export function resolveServiceBundleCommand(root, plan, buildConfig = {}, runtime =
|
|
282
|
-
if (bundler ===
|
|
290
|
+
export function resolveServiceBundleCommand(root, plan, buildConfig = {}, runtime = detectCliHostRuntime(), bundler = normalizeBundler('bun')) {
|
|
291
|
+
if (bundler === BundlerEnum.TSC) {
|
|
283
292
|
return resolveTscBuildCommand(root, plan.distRel, buildConfig, runtime)
|
|
284
293
|
}
|
|
285
|
-
if (bundler ===
|
|
294
|
+
if (bundler === BundlerEnum.ESBUILD) {
|
|
286
295
|
return resolveEsbuildBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig, runtime)
|
|
287
296
|
}
|
|
288
297
|
return resolveBunBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig)
|
|
289
298
|
}
|
|
290
299
|
|
|
291
|
-
export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}, runtime =
|
|
300
|
+
export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}, runtime = detectCliHostRuntime()) {
|
|
292
301
|
const tsconfig = readTsconfigJson(root, buildConfig)
|
|
293
302
|
const distRel = resolveDistRelWithTsconfig(root, layout, buildConfig, tsconfig)
|
|
294
303
|
const entryGlobs = resolveBuildEntryGlobs(layout.mainFolderPath, buildConfig, tsconfig)
|
|
@@ -323,24 +332,31 @@ export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}, run
|
|
|
323
332
|
}
|
|
324
333
|
|
|
325
334
|
export function resolveCoreBuildSteps(root, distRel, buildConfig = {}) {
|
|
326
|
-
const
|
|
327
|
-
|
|
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`
|
|
328
343
|
const steps = [
|
|
329
|
-
`${
|
|
344
|
+
`${scriptsBase}/sync-cli-defaults.mjs`,
|
|
330
345
|
`rm -rf ${distRel}`,
|
|
331
|
-
|
|
332
|
-
|
|
346
|
+
`${host.tscBin} --project ${resolvedTsconfig}`,
|
|
347
|
+
`${xBin} tsc-alias -p ${resolvedTsconfig}`,
|
|
333
348
|
]
|
|
349
|
+
|
|
334
350
|
if (resolveMinifyEnabled(buildConfig)) {
|
|
335
|
-
steps.push(`${
|
|
351
|
+
steps.push(`${scriptsBase}/minify-dist.mjs`)
|
|
336
352
|
}
|
|
337
|
-
steps.push(`${
|
|
338
|
-
steps.push(`${
|
|
339
|
-
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`)
|
|
340
356
|
return steps
|
|
341
357
|
}
|
|
342
358
|
|
|
343
|
-
export function resolveServiceBuildSteps(root, layout, buildConfig = {}, runtime =
|
|
359
|
+
export function resolveServiceBuildSteps(root, layout, buildConfig = {}, runtime = detectCliHostRuntime()) {
|
|
344
360
|
const plan = resolveEffectiveBuildOptions(root, layout, buildConfig, runtime)
|
|
345
361
|
const steps = []
|
|
346
362
|
|
|
@@ -360,7 +376,7 @@ export function resolveServiceBuildSteps(root, layout, buildConfig = {}, runtime
|
|
|
360
376
|
return steps
|
|
361
377
|
}
|
|
362
378
|
|
|
363
|
-
export function summarizeBuildPlan(root, layout, buildConfig = {}, runtime =
|
|
379
|
+
export function summarizeBuildPlan(root, layout, buildConfig = {}, runtime = detectCliHostRuntime()) {
|
|
364
380
|
const plan = resolveEffectiveBuildOptions(root, layout, buildConfig, runtime)
|
|
365
381
|
return {
|
|
366
382
|
distRel: plan.distRel,
|
|
@@ -394,15 +410,16 @@ export function resolveEnvFiles(envDir, names) {
|
|
|
394
410
|
}
|
|
395
411
|
|
|
396
412
|
|
|
397
|
-
export function resolveRuntimeRunner(runtime =
|
|
398
|
-
return runtime
|
|
413
|
+
export function resolveRuntimeRunner(runtime = detectCliHostRuntime()) {
|
|
414
|
+
return getRuntimeTooling(runtime).binRunner
|
|
399
415
|
}
|
|
400
416
|
|
|
401
|
-
export function resolvePackageScriptRunner(runtime =
|
|
402
|
-
return runtime
|
|
417
|
+
export function resolvePackageScriptRunner(runtime = detectCliHostRuntime()) {
|
|
418
|
+
return getRuntimeTooling(runtime).scriptRunner
|
|
403
419
|
}
|
|
404
420
|
|
|
405
|
-
export function resolveTestCommand(runtime =
|
|
406
|
-
|
|
407
|
-
return `bun test ${target}`
|
|
421
|
+
export function resolveTestCommand(runtime = detectCliHostRuntime(), target) {
|
|
422
|
+
return `${getRuntimeTooling(runtime).testRunner} ${target}`.trim()
|
|
408
423
|
}
|
|
424
|
+
|
|
425
|
+
export { RuntimeEnum, detectCliHostRuntime, getRuntimeTooling }
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import yaml from 'yaml'
|
|
3
|
+
|
|
4
|
+
import { packageDefaults, PACKAGE_NAME } from './package-defaults.mjs'
|
|
5
|
+
import { normalizeRuntime, normalizeTmpDocument, readTmpGlobalBlock } from './tmp-schema.mjs'
|
|
6
|
+
import { ensureTmpFile } from './tmp-layout.mjs'
|
|
7
|
+
|
|
8
|
+
/** Runtime ids = keys of defaults.runtimes (aligned with RuntimeEnum). */
|
|
9
|
+
export const RuntimeEnum = Object.freeze(
|
|
10
|
+
Object.fromEntries(
|
|
11
|
+
Object.keys(packageDefaults.runtimes).map((key) => [key.toUpperCase(), key]),
|
|
12
|
+
),
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
/** Bundler ids = defaults.bundlers (aligned with BundlerEnum). */
|
|
16
|
+
export const BundlerEnum = Object.freeze(
|
|
17
|
+
Object.fromEntries(
|
|
18
|
+
packageDefaults.bundlers.map((key) => [String(key).toUpperCase(), key]),
|
|
19
|
+
),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
export function detectCliHostRuntime() {
|
|
23
|
+
const bunKey = RuntimeEnum.BUN
|
|
24
|
+
const nodeKey = RuntimeEnum.NODE
|
|
25
|
+
if (!bunKey || !nodeKey) {
|
|
26
|
+
throw new Error(`${PACKAGE_NAME}: defaults.runtimes must define bun and node`)
|
|
27
|
+
}
|
|
28
|
+
return process.versions.bun ? bunKey : nodeKey
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getRuntimeTooling(runtime) {
|
|
32
|
+
const key = normalizeRuntime(runtime)
|
|
33
|
+
const tooling = packageDefaults.runtimes?.[key]
|
|
34
|
+
if (!tooling) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`${PACKAGE_NAME}: defaults.runtimes.${key} missing — add it to defaults.json`,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
return tooling
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Project runtime from tmp.yml configs.global.runtime. */
|
|
43
|
+
export function resolveProjectRuntime(root = process.cwd()) {
|
|
44
|
+
const { tmpFilePath } = ensureTmpFile(root)
|
|
45
|
+
const raw = yaml.parse(fs.readFileSync(tmpFilePath, 'utf8'))
|
|
46
|
+
const normalized = normalizeTmpDocument(raw)
|
|
47
|
+
const global = readTmpGlobalBlock(normalized.configs)
|
|
48
|
+
return normalizeRuntime(global.runtime)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function resolveDevCommand(cliName, runtime = detectCliHostRuntime()) {
|
|
52
|
+
const tooling = getRuntimeTooling(runtime)
|
|
53
|
+
if (tooling.devInvoker) return `${tooling.devInvoker} ${cliName} dev`
|
|
54
|
+
return `${cliName} dev`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* CLI UX context: banner/project runtime from tmp; install tooling from host process.
|
|
59
|
+
*/
|
|
60
|
+
export function resolveCliContext({ cliName, root = process.cwd() } = {}) {
|
|
61
|
+
const hostRuntime = detectCliHostRuntime()
|
|
62
|
+
const hostTooling = getRuntimeTooling(hostRuntime)
|
|
63
|
+
|
|
64
|
+
let projectRuntime = hostRuntime
|
|
65
|
+
let projectTooling = hostTooling
|
|
66
|
+
try {
|
|
67
|
+
projectRuntime = resolveProjectRuntime(root)
|
|
68
|
+
projectTooling = getRuntimeTooling(projectRuntime)
|
|
69
|
+
} catch {
|
|
70
|
+
// create / pre-tmp flows: host only until tmp.yml exists
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
cliName,
|
|
75
|
+
runtime: projectRuntime,
|
|
76
|
+
hostRuntime,
|
|
77
|
+
runtimeName: projectTooling.label,
|
|
78
|
+
packageManager: hostTooling.packageManager,
|
|
79
|
+
installCommand: hostTooling.installCommand,
|
|
80
|
+
devCommand: resolveDevCommand(cliName, hostRuntime),
|
|
81
|
+
tooling: projectTooling,
|
|
82
|
+
hostTooling,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -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)
|
|
@@ -60,6 +66,21 @@ function assertIdentityDefaults(raw, sourceLabel) {
|
|
|
60
66
|
throw new Error(`package defaults incomplete (${sourceLabel}): cliBinNames or cliName required`)
|
|
61
67
|
}
|
|
62
68
|
}
|
|
69
|
+
const runtimes = raw.runtimes
|
|
70
|
+
if (!runtimes || typeof runtimes !== 'object') {
|
|
71
|
+
throw new Error(`package defaults incomplete (${sourceLabel}): runtimes map required`)
|
|
72
|
+
}
|
|
73
|
+
for (const key of Object.keys(runtimes)) {
|
|
74
|
+
const entry = runtimes[key]
|
|
75
|
+
for (const field of ['label', 'packageManager', 'installCommand', 'scriptRunner', 'binRunner', 'testRunner', 'tscBin', 'esbuildBin']) {
|
|
76
|
+
if (entry?.[field] == null || String(entry[field]).trim() === '') {
|
|
77
|
+
throw new Error(`package defaults incomplete (${sourceLabel}): runtimes.${key}.${field}`)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!Array.isArray(raw.bundlers) || raw.bundlers.length === 0) {
|
|
82
|
+
throw new Error(`package defaults incomplete (${sourceLabel}): bundlers list required`)
|
|
83
|
+
}
|
|
63
84
|
}
|
|
64
85
|
|
|
65
86
|
function loadRawDefaults() {
|
|
@@ -86,12 +107,20 @@ if (!seed?.mainSourceFolder || !String(seed.mainSourceFolder).trim()) {
|
|
|
86
107
|
)
|
|
87
108
|
}
|
|
88
109
|
|
|
110
|
+
const frozenRuntimes = Object.freeze(
|
|
111
|
+
Object.fromEntries(
|
|
112
|
+
Object.entries(raw.runtimes).map(([key, value]) => [key, Object.freeze({ ...value })]),
|
|
113
|
+
),
|
|
114
|
+
)
|
|
115
|
+
|
|
89
116
|
export const packageDefaults = Object.freeze({
|
|
90
117
|
...raw,
|
|
91
118
|
mainSourceFolder: seed.mainSourceFolder,
|
|
92
119
|
framework: seed.framework,
|
|
93
120
|
layoutPaths: seed.layoutPaths,
|
|
94
121
|
brand: Object.freeze({ ...(raw.brand ?? {}) }),
|
|
122
|
+
runtimes: frozenRuntimes,
|
|
123
|
+
bundlers: Object.freeze([...raw.bundlers]),
|
|
95
124
|
buildDefaults: Object.freeze({ ...(raw.buildDefaults ?? {}) }),
|
|
96
125
|
tmpWatchDefaults: Object.freeze({ ...(raw.tmpWatchDefaults ?? {}) }),
|
|
97
126
|
cliBinNames: Object.freeze([...(raw.cliBinNames ?? [raw.cliName])]),
|
|
@@ -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,12 +1,21 @@
|
|
|
1
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
1
2
|
import { execSync } from 'node:child_process'
|
|
2
3
|
import fs from 'node:fs'
|
|
3
4
|
import os from 'node:os'
|
|
4
5
|
import path from 'node:path'
|
|
5
6
|
|
|
7
|
+
function runtimeExecutable(key) {
|
|
8
|
+
const tooling = packageDefaults.runtimes?.[key]
|
|
9
|
+
if (!tooling) {
|
|
10
|
+
throw new Error(`defaults.runtimes.${key} missing`)
|
|
11
|
+
}
|
|
12
|
+
return { key, label: tooling.label, cmd: tooling.binRunner }
|
|
13
|
+
}
|
|
14
|
+
|
|
6
15
|
const EXECUTABLES = [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
{ key:
|
|
16
|
+
runtimeExecutable('node'),
|
|
17
|
+
runtimeExecutable('bun'),
|
|
18
|
+
{ key: packageDefaults.runtimes.node.packageManager, label: packageDefaults.runtimes.node.packageManager, cmd: packageDefaults.runtimes.node.packageManager },
|
|
10
19
|
{ key: 'pnpm', label: 'pnpm', cmd: 'pnpm' },
|
|
11
20
|
{ key: 'yarn', label: 'Yarn', cmd: 'yarn' },
|
|
12
21
|
{ key: 'deno', label: 'Deno', cmd: 'deno' },
|
|
@@ -130,7 +139,7 @@ export function detectPackageManager(root = process.cwd()) {
|
|
|
130
139
|
export function resolveRuntimeInfo(root = process.cwd()) {
|
|
131
140
|
const bunEmbedded = process.versions.bun
|
|
132
141
|
const cliHost = bunEmbedded ? 'bun' : 'node'
|
|
133
|
-
const cliHostLabel = bunEmbedded ?
|
|
142
|
+
const cliHostLabel = bunEmbedded ? packageDefaults.runtimes.bun.label : packageDefaults.runtimes.node.label
|
|
134
143
|
const cliHostVersion = bunEmbedded
|
|
135
144
|
? normalizeSemver(bunEmbedded)
|
|
136
145
|
: normalizeSemver(process.version.replace(/^v/, ''))
|
|
@@ -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(
|
package/x/bin/main-cli.js
CHANGED
|
@@ -19,25 +19,21 @@ import {
|
|
|
19
19
|
} from './helpers/cli-identity.mjs'
|
|
20
20
|
import { readCliPackageJson, getProjectRoot } from './helpers/project-root.mjs'
|
|
21
21
|
import { ensureProjectArtifacts } from './helpers/project-artifacts.mjs'
|
|
22
|
+
import { resolveCliContext } from './helpers/cli-runtime.mjs'
|
|
22
23
|
|
|
23
24
|
const pkg = readCliPackageJson()
|
|
25
|
+
const projectRoot = getProjectRoot()
|
|
24
26
|
|
|
25
27
|
try {
|
|
26
|
-
ensureProjectArtifacts(
|
|
28
|
+
ensureProjectArtifacts(projectRoot, { writeToolchain: false, writeManifest: false })
|
|
27
29
|
} catch {
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
const cliName = resolveInvokedAs()
|
|
31
|
-
|
|
32
|
-
const isBun = !!process.versions.bun
|
|
33
|
-
const runtimeName = isBun ? 'Bun' : 'Node.js'
|
|
34
|
-
const packageManager = isBun ? 'bun' : 'npm'
|
|
35
|
-
const installCommand = isBun ? 'bun install' : 'npm install'
|
|
36
|
-
const devCommand = isBun ? `${cliName} dev` : `npx ${cliName} dev`
|
|
37
|
-
const cliContext = { cliName, runtimeName, packageManager, installCommand, devCommand }
|
|
33
|
+
const cliContext = resolveCliContext({ cliName, root: projectRoot })
|
|
38
34
|
|
|
39
35
|
if (shouldShowBanner()) {
|
|
40
|
-
printBanner({ version: pkg.version, runtimeName, invokedAs: cliName })
|
|
36
|
+
printBanner({ version: pkg.version, runtimeName: cliContext.runtimeName, invokedAs: cliName })
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
if (isRootHelpRequest()) {
|
|
@@ -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}`)
|
|
@@ -19,6 +19,36 @@
|
|
|
19
19
|
"tagline": "microservice runtime library",
|
|
20
20
|
"capabilities": "loaders \u00b7 tmp.yml \u00b7 dto \u00b7 i18n \u00b7 multi-protocol \u00b7 scaffold"
|
|
21
21
|
},
|
|
22
|
+
"runtimes": {
|
|
23
|
+
"bun": {
|
|
24
|
+
"label": "Bun",
|
|
25
|
+
"packageManager": "bun",
|
|
26
|
+
"installCommand": "bun install",
|
|
27
|
+
"scriptRunner": "bun run",
|
|
28
|
+
"binRunner": "bun",
|
|
29
|
+
"testRunner": "bun test",
|
|
30
|
+
"tscBin": "bunx tsc",
|
|
31
|
+
"esbuildBin": "bunx esbuild",
|
|
32
|
+
"devInvoker": null
|
|
33
|
+
},
|
|
34
|
+
"node": {
|
|
35
|
+
"label": "Node.js",
|
|
36
|
+
"packageManager": "npm",
|
|
37
|
+
"installCommand": "npm install",
|
|
38
|
+
"scriptRunner": "npm run",
|
|
39
|
+
"binRunner": "node",
|
|
40
|
+
"testRunner": "node --test",
|
|
41
|
+
"tscBin": "npx tsc",
|
|
42
|
+
"esbuildBin": "npx esbuild",
|
|
43
|
+
"devInvoker": "npx"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"bundlers": [
|
|
47
|
+
"auto",
|
|
48
|
+
"bun",
|
|
49
|
+
"tsc",
|
|
50
|
+
"esbuild"
|
|
51
|
+
],
|
|
22
52
|
"tmpWatchDefaults": {
|
|
23
53
|
"intervalMs": 500,
|
|
24
54
|
"minIntervalMs": 100,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
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 +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}}
|