@xrystal/core 3.42.0 → 3.45.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 +27 -24
- package/package.json +2 -2
- package/x/bin/commands/project.mjs +24 -11
- package/x/bin/commands/release.mjs +2 -2
- package/x/bin/commands/sync.mjs +1 -1
- package/x/bin/helpers/.generated/seed-from-tmp.mjs +1 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +93 -14
- package/x/bin/helpers/banner.mjs +7 -7
- package/x/bin/helpers/build-config.mjs +71 -17
- package/x/bin/helpers/cli-help.mjs +5 -4
- package/x/bin/helpers/cli-identity.mjs +6 -0
- package/x/bin/helpers/package-defaults.mjs +27 -1
- package/x/bin/helpers/project-artifacts.mjs +16 -7
- package/x/bin/helpers/tmp-schema.mjs +5 -0
- package/x/bin/helpers/toolchain-config.mjs +1 -1
- package/x/bin/main-cli.js +8 -4
- package/x/bin/scripts/clean-source-types.mjs +5 -2
- package/x/bin/scripts/prepare-npm-publish.mjs +9 -7
- package/x/bin/scripts/publish-guard.mjs +7 -5
- package/x/dist/loader/controller/index.js +1 -1
- package/x/dist/utils/constants/defaults.json +1 -0
- package/x/dist/utils/constants/index.d.ts +3 -0
- package/x/dist/utils/constants/index.js +1 -1
- package/x/dist/utils/helpers/handlers/adapters.js +1 -1
- package/x/dist/utils/helpers/protocol/index.d.ts +1 -1
- package/x/dist/utils/helpers/protocol/index.js +1 -1
- package/x/dist/utils/helpers/state/props-from-tmp.d.ts +1 -1
- package/x/dist/utils/helpers/state/props-from-tmp.js +1 -1
- package/x/dist/utils/helpers/state/request-key-guard.d.ts +1 -1
- package/x/dist/utils/helpers/state/request-key-guard.js +1 -1
- package/x/dist/utils/helpers/tmp/index.d.ts +2 -1
- package/x/dist/utils/helpers/tmp/index.js +1 -1
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -1
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -1
- package/x/dist/utils/helpers/tmp/tmp-interpolate.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-interpolate.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +12 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
- package/x/dist/utils/helpers/tmp/toolchain-heal.d.ts +46 -0
- package/x/dist/utils/helpers/tmp/toolchain-heal.js +2 -0
- package/x/dist/utils/models/enums/index.d.ts +10 -0
- package/x/dist/utils/models/enums/index.js +1 -1
- package/x/tmp.yml +7 -1
package/README.md
CHANGED
|
@@ -3,26 +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.45.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.45.0 / 3.45.0'da ne değişti
|
|
11
11
|
|
|
12
12
|
| Change / Değişiklik | EN | TR |
|
|
13
13
|
|---------------------|----|----|
|
|
14
|
-
| **
|
|
15
|
-
| **No
|
|
16
|
-
| **
|
|
17
|
-
|
|
14
|
+
| **CLI identity** | Commander / help / logs lead with `@xrystal/core` | Kimlik = paket adı |
|
|
15
|
+
| **No brand hardcodes** | Errors use `packageName`; invoke bin stays `xry` | Hardcode temizliği |
|
|
16
|
+
| **Publish helpers** | Source/dist paths from defaults + tmp seed | Publish path SSOT |
|
|
17
|
+
|
|
18
|
+
Carried from **3.44.0:** layout auto-sync, banner package name, bun/node runtime coverage.
|
|
18
19
|
|
|
19
20
|
```bash
|
|
20
|
-
npx xry sync # apply tmp.yml → tsconfig
|
|
21
|
+
npx xry sync # force-apply tmp.yml → tsconfig (usually auto)
|
|
21
22
|
npx xry sync --dry-run
|
|
22
23
|
```
|
|
23
24
|
|
|
24
|
-
**Breaking / Kırıcı:** replace scripts and docs that called `xcore`, `xrystal`, or the old `tmp` bin with `xry`.
|
|
25
|
-
|
|
26
25
|
---
|
|
27
26
|
|
|
28
27
|
## Why / Neden
|
|
@@ -35,7 +34,7 @@ npx xry sync --dry-run
|
|
|
35
34
|
# EN: existing project — kernel only · TR: mevcut proje — sadece kernel
|
|
36
35
|
bun add @xrystal/core
|
|
37
36
|
npx xry tmp # seed x/tmp.yml into YOUR layout
|
|
38
|
-
|
|
37
|
+
# tsconfig paths auto-heal from tmp.yml (xry sync = force / CI)
|
|
39
38
|
# wire coreLoader + dtoMiddleware in your entry file
|
|
40
39
|
```
|
|
41
40
|
|
|
@@ -73,7 +72,7 @@ mkdir my-api && cd my-api
|
|
|
73
72
|
bun init -y
|
|
74
73
|
bun add @xrystal/core elysia
|
|
75
74
|
npx xry tmp # EN: create x/tmp.yml from seed if missing · TR: yoksa seed'den oluşturur
|
|
76
|
-
npx xry
|
|
75
|
+
npx xry doctor # EN: optional health check · TR: isteğe bağlı sağlık kontrolü
|
|
77
76
|
```
|
|
78
77
|
|
|
79
78
|
`package.json`:
|
|
@@ -81,7 +80,7 @@ npx xry sync # EN: tsconfig from tmp.yml · TR: tmp.yml → tsconfig
|
|
|
81
80
|
```json
|
|
82
81
|
{
|
|
83
82
|
"dependencies": {
|
|
84
|
-
"@xrystal/core": "^3.
|
|
83
|
+
"@xrystal/core": "^3.45.0",
|
|
85
84
|
"elysia": "^1.4.19"
|
|
86
85
|
},
|
|
87
86
|
"scripts": {
|
|
@@ -115,14 +114,16 @@ my-api/
|
|
|
115
114
|
|
|
116
115
|
| File / Dosya | Owns / Sahip olduğu |
|
|
117
116
|
|--------------|---------------------|
|
|
118
|
-
| `x/tmp.yml` | Service paths, loaders, protocols,
|
|
119
|
-
| `tsconfig.json` | Compiler language options; path layout
|
|
120
|
-
| Package defaults (internal) | CLI
|
|
117
|
+
| `x/tmp.yml` | Service paths, loaders, protocols, runtime, bundler · layout seed |
|
|
118
|
+
| `tsconfig.json` | Compiler language options; path layout auto-heals from `tmp.yml` |
|
|
119
|
+
| Package defaults (internal) | Package identity (`@xrystal/core`) + CLI bin (`xry`) — not project layout |
|
|
121
120
|
|
|
122
121
|
### Minimal `x/tmp.yml`
|
|
123
122
|
|
|
124
123
|
```yaml
|
|
125
124
|
configs:
|
|
125
|
+
global:
|
|
126
|
+
runtime: bun # bun | node
|
|
126
127
|
service:
|
|
127
128
|
name: my-api
|
|
128
129
|
framework: elysia # express | elysia | node | fetch
|
|
@@ -130,6 +131,8 @@ configs:
|
|
|
130
131
|
root: ./x
|
|
131
132
|
source: ./source
|
|
132
133
|
protocols: [http]
|
|
134
|
+
build:
|
|
135
|
+
bundler: auto # auto | bun | tsc | esbuild
|
|
133
136
|
loaders:
|
|
134
137
|
dto: { withDefaultHeaders: true }
|
|
135
138
|
loggers: { logLevel: info }
|
|
@@ -174,7 +177,7 @@ bun run dev
|
|
|
174
177
|
|-----------------|----|----|
|
|
175
178
|
| `xry create [name] [path]` | Start project from template + `tmp.yml` | Template + `tmp.yml` ile proje başlat |
|
|
176
179
|
| `xry tmp` | Create `tmp.yml` from seed if missing | `tmp.yml` yoksa seed'den oluştur |
|
|
177
|
-
| `xry sync` |
|
|
180
|
+
| `xry sync` | Force-sync `tsconfig` from `tmp.yml` (auto-heals otherwise) | Force sync (normalde otomatik) |
|
|
178
181
|
| `xry dev` | Watch `source/index.ts` + dev env | `source/index.ts` watch + dev env |
|
|
179
182
|
| `xry build` | Output → `x/dist` | Çıktı → `x/dist` |
|
|
180
183
|
| `xry start` | Run `x/dist` + prod env | `x/dist` + prod env |
|
|
@@ -192,7 +195,7 @@ bun run dev
|
|
|
192
195
|
| Feature / Özellik | EN | TR | Example / Örnek |
|
|
193
196
|
|-------------------|----|----|-----------------|
|
|
194
197
|
| **Boot / DI** | Awilix loaders: System, Logger, Kafka, Dto, i18n, … | Awilix loader'lar | `await coreLoader({})` |
|
|
195
|
-
| **Live `tmp.yml`** | Edit file → loaders re-sync
|
|
198
|
+
| **Live `tmp.yml`** | Edit file → loaders re-sync; path changes heal tsconfig | Dosya → loader sync; path → tsconfig heal | `paths.source` rename → tsconfig updates |
|
|
196
199
|
| **`ctr()` pipeline** | `checks → logic → response`, no `res.json()` | Endpoint pipeline | `list = this.ctr({ logic: async () => ({ data: [] }) })` |
|
|
197
200
|
| **DTO responses** | Standard API shape via `@xrystal/dto` | Standart API cevabı | `return { data: [], message: '@successfully user' }` |
|
|
198
201
|
| **Trace** | `requestId` per request/job (ALS) | İstek/job trace id | `req.requestId` · `runWithTrace('job-1', fn)` |
|
|
@@ -542,13 +545,13 @@ Details / detay: [`@xrystal/dto`](https://www.npmjs.com/package/@xrystal/dto)
|
|
|
542
545
|
|
|
543
546
|
```
|
|
544
547
|
1. Your repo + bun add @xrystal/core + xry tmp (or xry create for greenfield)
|
|
545
|
-
2.
|
|
546
|
-
3.
|
|
547
|
-
4.
|
|
548
|
-
5.
|
|
549
|
-
6.
|
|
550
|
-
7. xry
|
|
551
|
-
8. xry
|
|
548
|
+
2. tmp.yml → framework, runtime, loaders, paths (tsconfig auto-heals)
|
|
549
|
+
3. coreLoader() → once at top of YOUR index.ts
|
|
550
|
+
4. Controller → ctr() per endpoint
|
|
551
|
+
5. Framework → dtoMiddleware + routes
|
|
552
|
+
6. xry dev → develop
|
|
553
|
+
7. xry build → start → production
|
|
554
|
+
8. xry sync → only when you need a force / dry-run / CI pin
|
|
552
555
|
```
|
|
553
556
|
|
|
554
557
|
### Express — end-to-end / uçtan uca
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Yusuf Yasir KAYGUSUZ",
|
|
3
3
|
"name": "@xrystal/core",
|
|
4
|
-
"version": "3.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "3.45.0",
|
|
5
|
+
"description": "microservice runtime library",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
8
8
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -11,7 +11,10 @@ import {
|
|
|
11
11
|
resolveDevEntry,
|
|
12
12
|
resolveDistEntryAbs,
|
|
13
13
|
resolveEnvFiles,
|
|
14
|
+
resolvePackageScriptRunner,
|
|
15
|
+
resolveRuntimeRunner,
|
|
14
16
|
resolveServiceBuildSteps,
|
|
17
|
+
resolveTestCommand,
|
|
15
18
|
shouldDelegatePackageBuild,
|
|
16
19
|
summarizeBuildPlan,
|
|
17
20
|
} from '../helpers/build-config.mjs'
|
|
@@ -38,42 +41,48 @@ function resolveTestTarget(root) {
|
|
|
38
41
|
export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
39
42
|
cli
|
|
40
43
|
.command('dev')
|
|
41
|
-
.description('Watch
|
|
44
|
+
.description('Watch TypeScript entry with dev env files')
|
|
42
45
|
.action(() => {
|
|
43
46
|
const root = getProjectRoot()
|
|
44
|
-
const { layout } = readTmpBuildContext(root)
|
|
47
|
+
const { layout, runtime } = readTmpBuildContext(root)
|
|
45
48
|
const entry = resolveDevEntry(root, layout)
|
|
46
49
|
const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.dev.env'])
|
|
47
50
|
const envArgs = envFiles.map((file) => `--env-file=${file}`).join(' ')
|
|
51
|
+
const runner = resolveRuntimeRunner(runtime)
|
|
48
52
|
|
|
49
53
|
printCommandHeader({ cliName, command: 'dev', version: readCliPackageJson().version })
|
|
50
54
|
console.log(chalk.gray(` root: ${root}`))
|
|
55
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
51
56
|
console.log(chalk.gray(` entry: ${entry} (.ts)\n`))
|
|
52
|
-
runInProject(root,
|
|
57
|
+
runInProject(root, `${runner} --watch ${envArgs} ${entry}`.trim())
|
|
53
58
|
})
|
|
54
59
|
|
|
55
60
|
cli
|
|
56
61
|
.command('build')
|
|
57
|
-
.description('Bundle to dist/ (
|
|
62
|
+
.description('Bundle to dist/ (bundler from tmp.yml)')
|
|
58
63
|
.action(() => {
|
|
59
64
|
const root = getProjectRoot()
|
|
60
65
|
ensureProjectArtifacts(root, { writeToolchain: true, writeManifest: true })
|
|
61
66
|
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
67
|
+
const { layout, build, runtime, bundler } = readTmpBuildContext(root)
|
|
62
68
|
|
|
63
69
|
printCommandHeader({ cliName, command: 'build', version: readCliPackageJson().version })
|
|
64
70
|
console.log(chalk.gray(` root: ${root}`))
|
|
65
71
|
|
|
66
72
|
if (shouldDelegatePackageBuild(pkg)) {
|
|
67
|
-
runInProject(root,
|
|
73
|
+
runInProject(root, `${resolvePackageScriptRunner(runtime)} build`)
|
|
68
74
|
return
|
|
69
75
|
}
|
|
70
76
|
|
|
71
|
-
const
|
|
72
|
-
const plan = summarizeBuildPlan(root, layout, build)
|
|
77
|
+
const plan = summarizeBuildPlan(root, layout, build, runtime)
|
|
73
78
|
const steps = isCorePackageName(pkg.name)
|
|
74
79
|
? resolveCoreBuildSteps(root, plan.distRel, build)
|
|
75
|
-
: resolveServiceBuildSteps(root, layout, build)
|
|
80
|
+
: resolveServiceBuildSteps(root, layout, build, runtime)
|
|
76
81
|
console.log(chalk.gray(` mode: ${isCorePackageName(pkg.name) ? 'core entries' : 'service tsconfig + tmp overrides'}`))
|
|
82
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
83
|
+
if (!isCorePackageName(pkg.name)) {
|
|
84
|
+
console.log(chalk.gray(` bundler: ${plan.bundler || bundler}`))
|
|
85
|
+
}
|
|
77
86
|
if (plan.tsconfigRel) {
|
|
78
87
|
console.log(chalk.gray(` tsconfig: ${plan.tsconfigRel}`))
|
|
79
88
|
}
|
|
@@ -94,7 +103,7 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
94
103
|
.description('Run dist/index.js with prod env files')
|
|
95
104
|
.action(() => {
|
|
96
105
|
const root = getProjectRoot()
|
|
97
|
-
const { layout, build } = readTmpBuildContext(root)
|
|
106
|
+
const { layout, build, runtime } = readTmpBuildContext(root)
|
|
98
107
|
const entryAbs = resolveDistEntryAbs(root, layout, build)
|
|
99
108
|
|
|
100
109
|
if (!fs.existsSync(entryAbs)) {
|
|
@@ -106,11 +115,13 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
106
115
|
const entry = relativeFromRoot(root, entryAbs)
|
|
107
116
|
const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.prod.env'])
|
|
108
117
|
const envArgs = envFiles.map((file) => `--env-file=${file}`).join(' ')
|
|
118
|
+
const runner = resolveRuntimeRunner(runtime)
|
|
109
119
|
|
|
110
120
|
printCommandHeader({ cliName, command: 'start', version: readCliPackageJson().version })
|
|
111
121
|
console.log(chalk.gray(` root: ${root}`))
|
|
122
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
112
123
|
console.log(chalk.gray(` entry: ${entry} (.js)\n`))
|
|
113
|
-
runInProject(root,
|
|
124
|
+
runInProject(root, `${runner} ${envArgs} ${entry}`.trim())
|
|
114
125
|
})
|
|
115
126
|
|
|
116
127
|
cli
|
|
@@ -118,10 +129,12 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
118
129
|
.description('Run tests from tmp.yml paths')
|
|
119
130
|
.action(() => {
|
|
120
131
|
const root = getProjectRoot()
|
|
132
|
+
const { runtime } = readTmpBuildContext(root)
|
|
121
133
|
const target = resolveTestTarget(root)
|
|
122
134
|
|
|
123
135
|
printCommandHeader({ cliName, command: 'test', version: readCliPackageJson().version })
|
|
136
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
124
137
|
console.log(chalk.gray(` target: ${target}\n`))
|
|
125
|
-
runInProject(root,
|
|
138
|
+
runInProject(root, resolveTestCommand(runtime, target))
|
|
126
139
|
})
|
|
127
140
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
import { readCliPackageJson, readProjectPackageJson, getProjectRoot } from '../helpers/project-root.mjs'
|
|
3
3
|
import { compareSemver, getVersionState, resolveVersionBaseline, runTagRelease } from '../scripts/version-check.mjs'
|
|
4
|
-
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
4
|
+
import { CLI_PRIMARY_NAME, PACKAGE_NAME } from '../helpers/cli-identity.mjs'
|
|
5
5
|
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
6
6
|
|
|
7
7
|
export function registerTagCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
@@ -40,7 +40,7 @@ export function registerVersionCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
|
|
|
40
40
|
const projectPkg = readProjectPackageJson(root)
|
|
41
41
|
const state = getVersionState('HEAD', root)
|
|
42
42
|
|
|
43
|
-
console.log(chalk.cyan(`\n${
|
|
43
|
+
console.log(chalk.cyan(`\n${PACKAGE_NAME} version\n`))
|
|
44
44
|
console.log(chalk.gray(' CLI (tool)'))
|
|
45
45
|
console.log(` ${packageDefaults.packageName}: ${chalk.bold(`${cliPkg.name}@${cliPkg.version}`)}`)
|
|
46
46
|
console.log('')
|
package/x/bin/commands/sync.mjs
CHANGED
|
@@ -42,7 +42,7 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
42
42
|
cli
|
|
43
43
|
.command('sync')
|
|
44
44
|
.alias('sync-toolchain')
|
|
45
|
-
.description('
|
|
45
|
+
.description('Force-sync tsconfig from tmp.yml (also auto-heals on layout path change / CLI entry)')
|
|
46
46
|
.option('--dry-run', 'Preview without writing')
|
|
47
47
|
.action(run)
|
|
48
48
|
}
|
|
@@ -6,6 +6,7 @@ var defaults_default = {
|
|
|
6
6
|
cliBinNames: [
|
|
7
7
|
"xry"
|
|
8
8
|
],
|
|
9
|
+
cliBinFile: "main-cli.js",
|
|
9
10
|
tmpBaseName: "tmp",
|
|
10
11
|
tmpExtension: ".yml",
|
|
11
12
|
templateRepoUri: "https://github.com/xdloper/api-gpt-svc",
|
|
@@ -122,24 +123,81 @@ function loadSeedFromBundledTmp(tmpFilePath) {
|
|
|
122
123
|
}
|
|
123
124
|
var seedFromTmp = loadSeedFromBundledTmp();
|
|
124
125
|
|
|
125
|
-
// source/utils/helpers/tmp/tmp-
|
|
126
|
+
// source/utils/helpers/tmp/tmp-interpolate.ts
|
|
127
|
+
import Handlebars from "handlebars";
|
|
126
128
|
function isRecord(value) {
|
|
127
129
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
128
130
|
}
|
|
131
|
+
function interpolateWithContext(value, context) {
|
|
132
|
+
if (typeof value === "string") {
|
|
133
|
+
if (!value.includes("{{"))
|
|
134
|
+
return value;
|
|
135
|
+
return Handlebars.compile(value)(context);
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(value)) {
|
|
138
|
+
return value.map((item) => interpolateWithContext(item, context));
|
|
139
|
+
}
|
|
140
|
+
if (isRecord(value)) {
|
|
141
|
+
const next = {};
|
|
142
|
+
for (const [key, child] of Object.entries(value)) {
|
|
143
|
+
next[key] = interpolateWithContext(child, context);
|
|
144
|
+
}
|
|
145
|
+
return next;
|
|
146
|
+
}
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// source/utils/helpers/tmp/tmp-schema.ts
|
|
151
|
+
function isRecord2(value) {
|
|
152
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
153
|
+
}
|
|
129
154
|
function readWatchIntervalValue(raw) {
|
|
130
155
|
if (typeof raw === "number" || typeof raw === "string")
|
|
131
156
|
return raw;
|
|
132
157
|
return;
|
|
133
158
|
}
|
|
159
|
+
function normalizeRuntime(value) {
|
|
160
|
+
const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
161
|
+
if (raw === "node" /* NODE */)
|
|
162
|
+
return "node" /* NODE */;
|
|
163
|
+
if (raw === "bun" /* BUN */)
|
|
164
|
+
return "bun" /* BUN */;
|
|
165
|
+
return "bun" /* BUN */;
|
|
166
|
+
}
|
|
167
|
+
function normalizeBundler(value) {
|
|
168
|
+
const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
169
|
+
if (raw === "tsc" /* TSC */)
|
|
170
|
+
return "tsc" /* TSC */;
|
|
171
|
+
if (raw === "esbuild" /* ESBUILD */)
|
|
172
|
+
return "esbuild" /* ESBUILD */;
|
|
173
|
+
if (raw === "bun" /* BUN */)
|
|
174
|
+
return "bun" /* BUN */;
|
|
175
|
+
if (raw === "auto" /* AUTO */)
|
|
176
|
+
return "auto" /* AUTO */;
|
|
177
|
+
return "auto" /* AUTO */;
|
|
178
|
+
}
|
|
179
|
+
function resolveEffectiveBundler(bundler, runtime) {
|
|
180
|
+
if (bundler !== "auto" /* AUTO */)
|
|
181
|
+
return bundler;
|
|
182
|
+
return runtime === "node" /* NODE */ ? "tsc" /* TSC */ : "bun" /* BUN */;
|
|
183
|
+
}
|
|
134
184
|
function normalizeRootFolder2(value) {
|
|
135
185
|
return normalizeRootFolder(value, defaults_default.packageRootFolder);
|
|
136
186
|
}
|
|
137
187
|
function normalizeSourceFolder2(value) {
|
|
138
188
|
return normalizeSourceFolder(value, seedFromTmp.sourceFolder);
|
|
139
189
|
}
|
|
190
|
+
function readTmpGlobalBlock(configs) {
|
|
191
|
+
const global = isRecord2(configs?.global) ? configs.global : {};
|
|
192
|
+
const varsRaw = isRecord2(global.vars) ? global.vars : {};
|
|
193
|
+
return {
|
|
194
|
+
runtime: normalizeRuntime(global.runtime),
|
|
195
|
+
vars: { ...varsRaw }
|
|
196
|
+
};
|
|
197
|
+
}
|
|
140
198
|
function readTmpCoreBlock(configs) {
|
|
141
|
-
const core =
|
|
142
|
-
const tmp =
|
|
199
|
+
const core = isRecord2(configs?.core) ? configs.core : {};
|
|
200
|
+
const tmp = isRecord2(core.tmp) ? core.tmp : {};
|
|
143
201
|
return {
|
|
144
202
|
tmp: {
|
|
145
203
|
fileWatchIntervalMs: readWatchIntervalValue(tmp.fileWatchIntervalMs)
|
|
@@ -147,15 +205,15 @@ function readTmpCoreBlock(configs) {
|
|
|
147
205
|
};
|
|
148
206
|
}
|
|
149
207
|
function readTmpServiceBlock(configs) {
|
|
150
|
-
const service =
|
|
151
|
-
const pathsRaw =
|
|
152
|
-
const special =
|
|
153
|
-
let loaders =
|
|
154
|
-
let build =
|
|
155
|
-
if (loaders &&
|
|
208
|
+
const service = isRecord2(configs?.service) ? configs.service : {};
|
|
209
|
+
const pathsRaw = isRecord2(service.paths) ? service.paths : {};
|
|
210
|
+
const special = isRecord2(pathsRaw.special) ? pathsRaw.special : {};
|
|
211
|
+
let loaders = isRecord2(service.loaders) ? { ...service.loaders } : undefined;
|
|
212
|
+
let build = isRecord2(service.build) ? service.build : undefined;
|
|
213
|
+
if (loaders && isRecord2(loaders.build)) {
|
|
156
214
|
const { build: nestedBuild, ...rest } = loaders;
|
|
157
215
|
loaders = rest;
|
|
158
|
-
if (!build &&
|
|
216
|
+
if (!build && isRecord2(nestedBuild)) {
|
|
159
217
|
build = nestedBuild;
|
|
160
218
|
}
|
|
161
219
|
}
|
|
@@ -201,29 +259,50 @@ function buildNormalizedCore(core) {
|
|
|
201
259
|
}
|
|
202
260
|
};
|
|
203
261
|
}
|
|
262
|
+
function buildTmpVarContext(global) {
|
|
263
|
+
return {
|
|
264
|
+
...global.vars,
|
|
265
|
+
runtime: global.runtime,
|
|
266
|
+
global
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function applyTmpGlobalVars(tmp) {
|
|
270
|
+
const configs = isRecord2(tmp.configs) ? tmp.configs : {};
|
|
271
|
+
const global = readTmpGlobalBlock(configs);
|
|
272
|
+
return interpolateWithContext(tmp, buildTmpVarContext(global));
|
|
273
|
+
}
|
|
204
274
|
function resolveTmpRuntimeConfigs(tmp) {
|
|
205
|
-
const configs =
|
|
275
|
+
const configs = isRecord2(tmp?.configs) ? tmp.configs : {};
|
|
276
|
+
const global = readTmpGlobalBlock(configs);
|
|
206
277
|
const service = readTmpServiceBlock(configs);
|
|
207
278
|
const core = readTmpCoreBlock(configs);
|
|
208
279
|
const normalizedService = buildNormalizedService(service);
|
|
209
280
|
return {
|
|
281
|
+
global,
|
|
210
282
|
service: normalizedService,
|
|
211
283
|
core: buildNormalizedCore(core),
|
|
212
284
|
rootFolderPath: normalizeRootFolder2(normalizedService.paths.root)
|
|
213
285
|
};
|
|
214
286
|
}
|
|
215
287
|
function normalizeTmpDocument(tmp) {
|
|
288
|
+
const interpolated = applyTmpGlobalVars(tmp);
|
|
216
289
|
return {
|
|
217
|
-
...
|
|
218
|
-
configs: resolveTmpRuntimeConfigs(
|
|
290
|
+
...interpolated,
|
|
291
|
+
configs: resolveTmpRuntimeConfigs(interpolated)
|
|
219
292
|
};
|
|
220
293
|
}
|
|
221
294
|
export {
|
|
222
295
|
resolveTmpRuntimeConfigs,
|
|
223
296
|
resolveServiceLayoutPaths,
|
|
297
|
+
resolveEffectiveBundler,
|
|
224
298
|
readTmpServiceBlock,
|
|
299
|
+
readTmpGlobalBlock,
|
|
225
300
|
readTmpCoreBlock,
|
|
226
301
|
normalizeTmpDocument,
|
|
227
302
|
normalizeSourceFolder2 as normalizeSourceFolder,
|
|
228
|
-
|
|
303
|
+
normalizeRuntime,
|
|
304
|
+
normalizeRootFolder2 as normalizeRootFolder,
|
|
305
|
+
normalizeBundler,
|
|
306
|
+
buildTmpVarContext,
|
|
307
|
+
applyTmpGlobalVars
|
|
229
308
|
};
|
package/x/bin/helpers/banner.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import chalk from 'chalk'
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
CLI_BIN_NAMES,
|
|
5
|
-
CLI_PRIMARY_NAME,
|
|
6
5
|
packageDefaults,
|
|
7
6
|
} from './package-defaults.mjs'
|
|
8
7
|
|
|
@@ -45,8 +44,7 @@ export function brandTitle() {
|
|
|
45
44
|
return `${chalk.bold.white(`${primary} `)}${chalk.bold.magenta(secondary)}`
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
export function printBanner({ version, runtimeName, invokedAs } = {}) {
|
|
49
|
-
const bin = invokedAs && invokedAs !== 'main-cli.js' ? invokedAs : CLI_PRIMARY_NAME
|
|
47
|
+
export function printBanner({ version, runtimeName, invokedAs: _invokedAs } = {}) {
|
|
50
48
|
const versionLabel = version ? chalk.bold.green(`v${version}`) : chalk.gray('v?')
|
|
51
49
|
const runtimeLabel = runtimeName ? chalk.bold.white(runtimeName) : ''
|
|
52
50
|
const { tagline, capabilities } = brand()
|
|
@@ -57,19 +55,21 @@ export function printBanner({ version, runtimeName, invokedAs } = {}) {
|
|
|
57
55
|
console.log(chalk.bold.gray(` ${tagline}`))
|
|
58
56
|
console.log('')
|
|
59
57
|
console.log(
|
|
60
|
-
` ${chalk.bold.cyan(
|
|
58
|
+
` ${chalk.bold.cyan(packageDefaults.packageName)} ${versionLabel}${runtimeLabel ? ` ${chalk.gray('·')} ${runtimeLabel}` : ''}`,
|
|
61
59
|
)
|
|
62
60
|
console.log(chalk.bold.gray(` ${capabilities}`))
|
|
63
61
|
console.log(chalk.dim(` cli: ${BIN_ALIASES_LABEL}`))
|
|
64
62
|
console.log('')
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
export function printCommandHeader({ cliName, command, version } = {}) {
|
|
68
|
-
const label = cliName || CLI_PRIMARY_NAME
|
|
65
|
+
export function printCommandHeader({ cliName: _cliName, command, version } = {}) {
|
|
69
66
|
const versionLabel = version ? chalk.green(`v${version}`) : ''
|
|
67
|
+
const title = command
|
|
68
|
+
? `${packageDefaults.packageName} ${command}`
|
|
69
|
+
: packageDefaults.packageName
|
|
70
70
|
console.log('')
|
|
71
71
|
console.log(
|
|
72
|
-
`${chalk.bold.cyan(
|
|
72
|
+
`${chalk.bold.cyan(title)} ${chalk.gray('·')} ${brandTitle()} ${versionLabel}`.trim(),
|
|
73
73
|
)
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -4,7 +4,13 @@ import yaml from 'yaml'
|
|
|
4
4
|
|
|
5
5
|
import { packageDefaults } from '../paths.mjs'
|
|
6
6
|
import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
normalizeTmpDocument,
|
|
9
|
+
readTmpServiceBlock,
|
|
10
|
+
readTmpGlobalBlock,
|
|
11
|
+
normalizeBundler,
|
|
12
|
+
resolveEffectiveBundler,
|
|
13
|
+
} from './tmp-schema.mjs'
|
|
8
14
|
|
|
9
15
|
import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
|
|
10
16
|
|
|
@@ -36,7 +42,9 @@ export function readTmpBuildContext(root) {
|
|
|
36
42
|
const tmp = normalizeTmpDocument(yaml.parse(fs.readFileSync(ensured.tmpFilePath, 'utf8')))
|
|
37
43
|
const configs = tmp.configs ?? {}
|
|
38
44
|
const build = readTmpServiceBlock(configs).build ?? {}
|
|
39
|
-
|
|
45
|
+
const global = readTmpGlobalBlock(configs)
|
|
46
|
+
const bundler = resolveEffectiveBundler(normalizeBundler(build.bundler), global.runtime)
|
|
47
|
+
return { layout: ensured.layout, configs, build, global, runtime: global.runtime, bundler }
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
export function normalizeMainFolder(mainFolderPath = packageDefaults.mainSourceFolder) {
|
|
@@ -225,24 +233,28 @@ export function resolveSourcemapFlag(buildConfig = {}, tsconfig = null) {
|
|
|
225
233
|
return ''
|
|
226
234
|
}
|
|
227
235
|
|
|
228
|
-
function
|
|
236
|
+
function resolveTscBin(runtime = 'bun') {
|
|
237
|
+
return runtime === 'node' ? 'npx tsc' : 'bunx tsc'
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function withTscProject(root, buildConfig, extraArgs, runtime = 'bun') {
|
|
229
241
|
const tsconfigRel = resolveTsconfigRel(root, buildConfig)
|
|
230
242
|
const projectFlag = tsconfigRel ? `--project ${tsconfigRel} ` : ''
|
|
231
|
-
return
|
|
243
|
+
return `${resolveTscBin(runtime)} ${projectFlag}${extraArgs}`.replace(/\s+/g, ' ').trim()
|
|
232
244
|
}
|
|
233
245
|
|
|
234
|
-
export function resolveTypecheckCommand(root, buildConfig = {}) {
|
|
246
|
+
export function resolveTypecheckCommand(root, buildConfig = {}, runtime = 'bun') {
|
|
235
247
|
const tsconfigRel = resolveTsconfigRel(root, buildConfig)
|
|
236
248
|
if (!tsconfigRel) {
|
|
237
249
|
throw new Error(
|
|
238
250
|
'build.typecheck is enabled but tsconfig was not found. Set build.tsconfig or add tsconfig.json.',
|
|
239
251
|
)
|
|
240
252
|
}
|
|
241
|
-
return withTscProject(root, buildConfig, '--noEmit')
|
|
253
|
+
return withTscProject(root, buildConfig, '--noEmit', runtime)
|
|
242
254
|
}
|
|
243
255
|
|
|
244
|
-
export function resolveTscCommand(root, distRel, buildConfig = {}) {
|
|
245
|
-
const cmd = withTscProject(root, buildConfig, `--emitDeclarationOnly --declaration --outDir ${distRel}
|
|
256
|
+
export function resolveTscCommand(root, distRel, buildConfig = {}, runtime = 'bun') {
|
|
257
|
+
const cmd = withTscProject(root, buildConfig, `--emitDeclarationOnly --declaration --outDir ${distRel}`, runtime)
|
|
246
258
|
return buildConfig.tscLenient ? `${cmd} || true` : cmd
|
|
247
259
|
}
|
|
248
260
|
|
|
@@ -253,16 +265,42 @@ export function resolveBunBuildCommand(entryGlobs, distRel, buildConfig = {}, ts
|
|
|
253
265
|
return `bun build ${entryGlobs.join(' ')} ${flags.join(' ')}`.replace(/\s+/g, ' ').trim()
|
|
254
266
|
}
|
|
255
267
|
|
|
256
|
-
export function
|
|
268
|
+
export function resolveTscBuildCommand(root, distRel, buildConfig = {}, runtime = 'bun') {
|
|
269
|
+
return withTscProject(root, buildConfig, `--outDir ${distRel}`, runtime)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function resolveEsbuildBuildCommand(entryGlobs, distRel, buildConfig = {}, tsconfig = null, runtime = 'bun') {
|
|
273
|
+
const minify = resolveMinifyEnabled(buildConfig) ? ' --minify' : ''
|
|
274
|
+
const sourcemapFlag = resolveSourcemapFlag(buildConfig, tsconfig)
|
|
275
|
+
const sourcemap = sourcemapFlag ? ' --sourcemap' : ''
|
|
276
|
+
const bin = runtime === 'node' ? 'npx esbuild' : 'bunx esbuild'
|
|
277
|
+
const entries = entryGlobs.join(' ')
|
|
278
|
+
return `${bin} ${entries} --bundle --platform=node --packages=external --outdir=${distRel}${minify}${sourcemap}`.replace(/\s+/g, ' ').trim()
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function resolveServiceBundleCommand(root, plan, buildConfig = {}, runtime = 'bun', bundler = 'bun') {
|
|
282
|
+
if (bundler === 'tsc') {
|
|
283
|
+
return resolveTscBuildCommand(root, plan.distRel, buildConfig, runtime)
|
|
284
|
+
}
|
|
285
|
+
if (bundler === 'esbuild') {
|
|
286
|
+
return resolveEsbuildBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig, runtime)
|
|
287
|
+
}
|
|
288
|
+
return resolveBunBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}, runtime = 'bun') {
|
|
257
292
|
const tsconfig = readTsconfigJson(root, buildConfig)
|
|
258
293
|
const distRel = resolveDistRelWithTsconfig(root, layout, buildConfig, tsconfig)
|
|
259
294
|
const entryGlobs = resolveBuildEntryGlobs(layout.mainFolderPath, buildConfig, tsconfig)
|
|
295
|
+
const bundler = resolveEffectiveBundler(normalizeBundler(buildConfig.bundler), runtime)
|
|
260
296
|
|
|
261
297
|
return {
|
|
262
298
|
tsconfig,
|
|
263
299
|
tsconfigRel: tsconfig?.rel ?? null,
|
|
264
300
|
distRel,
|
|
265
301
|
entryGlobs,
|
|
302
|
+
runtime,
|
|
303
|
+
bundler,
|
|
266
304
|
typecheck: resolveTypecheckEnabled(buildConfig),
|
|
267
305
|
declarations: resolveDeclarationsEnabled(buildConfig, tsconfig),
|
|
268
306
|
sourcemap: resolveSourcemapFlag(buildConfig, tsconfig) || 'false',
|
|
@@ -302,32 +340,34 @@ export function resolveCoreBuildSteps(root, distRel, buildConfig = {}) {
|
|
|
302
340
|
return steps
|
|
303
341
|
}
|
|
304
342
|
|
|
305
|
-
export function resolveServiceBuildSteps(root, layout, buildConfig = {}) {
|
|
306
|
-
const plan = resolveEffectiveBuildOptions(root, layout, buildConfig)
|
|
343
|
+
export function resolveServiceBuildSteps(root, layout, buildConfig = {}, runtime = 'bun') {
|
|
344
|
+
const plan = resolveEffectiveBuildOptions(root, layout, buildConfig, runtime)
|
|
307
345
|
const steps = []
|
|
308
346
|
|
|
309
347
|
if (plan.typecheck) {
|
|
310
|
-
steps.push(resolveTypecheckCommand(root, buildConfig))
|
|
348
|
+
steps.push(resolveTypecheckCommand(root, buildConfig, runtime))
|
|
311
349
|
}
|
|
312
350
|
|
|
313
351
|
steps.push(
|
|
314
352
|
`rm -rf ${plan.distRel}`,
|
|
315
|
-
|
|
353
|
+
resolveServiceBundleCommand(root, plan, buildConfig, runtime, plan.bundler),
|
|
316
354
|
)
|
|
317
355
|
|
|
318
|
-
if (plan.declarations) {
|
|
319
|
-
steps.push(resolveTscCommand(root, plan.distRel, buildConfig))
|
|
356
|
+
if (plan.declarations && plan.bundler !== 'tsc') {
|
|
357
|
+
steps.push(resolveTscCommand(root, plan.distRel, buildConfig, runtime))
|
|
320
358
|
}
|
|
321
359
|
|
|
322
360
|
return steps
|
|
323
361
|
}
|
|
324
362
|
|
|
325
|
-
export function summarizeBuildPlan(root, layout, buildConfig = {}) {
|
|
326
|
-
const plan = resolveEffectiveBuildOptions(root, layout, buildConfig)
|
|
363
|
+
export function summarizeBuildPlan(root, layout, buildConfig = {}, runtime = 'bun') {
|
|
364
|
+
const plan = resolveEffectiveBuildOptions(root, layout, buildConfig, runtime)
|
|
327
365
|
return {
|
|
328
366
|
distRel: plan.distRel,
|
|
329
367
|
entryGlobs: plan.entryGlobs,
|
|
330
368
|
tsconfigRel: plan.tsconfigRel,
|
|
369
|
+
runtime: plan.runtime,
|
|
370
|
+
bundler: plan.bundler,
|
|
331
371
|
typecheck: plan.typecheck,
|
|
332
372
|
declarations: plan.declarations,
|
|
333
373
|
sourcemap: plan.sourcemap,
|
|
@@ -352,3 +392,17 @@ export function resolveEnvFiles(envDir, names) {
|
|
|
352
392
|
.map((name) => path.join(envDir, name))
|
|
353
393
|
.filter((file) => fs.existsSync(file))
|
|
354
394
|
}
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
export function resolveRuntimeRunner(runtime = 'bun') {
|
|
398
|
+
return runtime === 'node' ? 'node' : 'bun'
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export function resolvePackageScriptRunner(runtime = 'bun') {
|
|
402
|
+
return runtime === 'node' ? 'npm run' : 'bun run'
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export function resolveTestCommand(runtime = 'bun', target) {
|
|
406
|
+
if (runtime === 'node') return `node --test ${target}`
|
|
407
|
+
return `bun test ${target}`
|
|
408
|
+
}
|