@xrystal/core 3.37.3 → 3.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,6 +7,31 @@
7
7
 
8
8
  ---
9
9
 
10
+ ## npm publish / npm yayın
11
+
12
+ | | **EN** | **TR** |
13
+ |---|--------|--------|
14
+ | **Ships** | `x/dist` (minified `.js` + `.d.ts`), `x/bin`, `x/tmp.yml`, `x/assets` | Aynı — yalnızca bunlar |
15
+ | **Never** | `source/` `.ts` in npm | npm'e `source/` `.ts` **asla** gitmez |
16
+ | **Runtime** | `main` / `exports` → `x/dist/` | `main` / `exports` → `x/dist/` |
17
+
18
+ **EN — 3 publish checks (all must pass):**
19
+ 1. `package.json` `files` — no `source/`, `main`/`exports` → `x/dist`
20
+ 2. `npm pack --dry-run` — no `source/` paths
21
+ 3. CI: `prepare-npm-publish` → `verify-npm-pack` (strict: disk + minify)
22
+
23
+ **TR — 3 publish kontrolü (hepsi geçmeli):**
24
+ 1. `package.json` `files` — `source/` yok, `main`/`exports` → `x/dist`
25
+ 2. `npm pack --dry-run` — `source/` yok
26
+ 3. CI: `prepare-npm-publish` → `verify-npm-pack` (strict: disk + minify)
27
+
28
+ ```bash
29
+ bun run release:prepare # lint → build → test
30
+ node x/bin/scripts/verify-publish-config.mjs # local prepublish gate
31
+ ```
32
+
33
+ ---
34
+
10
35
  ## `tmp.yml` layout / tmp.yml düzeni
11
36
 
12
37
  **EN — structure:** `service` (app identity, paths, runtime, build) + `core` (library mechanisms like tmp watch).
@@ -78,7 +103,7 @@ In one sentence: **`tmp.yml` is the project key** — `@xrystal/core` reads it,
78
103
 
79
104
  **Boot:** `ensureCoreTmpEntry()` → `getTmpSnapshot()` → `coreLoader()` → loaders `syncFromTmp()`.
80
105
 
81
- **Published npm artifact:** npm tarball ships **only** `x/dist` (minified `.js` + `.d.ts`), `x/bin`, `x/tmp.yml`, `x/assets` — **no `source/` `.ts` files**. `main` / `types` / `exports` → **`x/dist/`**. Local dev uses `source/**/*.ts`; npm consumers run **`x/dist/index.js`** (Node ESM).
106
+ See [npm publish / npm yayın](#npm-publish--npm-yayın) for what ships to npm.
82
107
 
83
108
  ---
84
109
 
@@ -99,7 +124,7 @@ Tek cümle: **`tmp.yml` projenin anahtarı** — `@xrystal/core` onu okuyup load
99
124
 
100
125
  **Boot:** `ensureCoreTmpEntry()` → `getTmpSnapshot()` → `coreLoader()` → loader’lar `syncFromTmp()`.
101
126
 
102
- **npm paketi:** tarball’da **yalnızca** `x/dist` (minify `.js` + `.d.ts`), `x/bin`, `x/tmp.yml`, `x/assets` — **`source/` `.ts` yok`**. `main` / `types` / `exports` → **`x/dist/`**. Geliştirmede `source/**/*.ts`; npm tüketicisi **`x/dist/index.js`** (Node ESM).
127
+ npm için → [npm publish / npm yayın](#npm-publish--npm-yayın).
103
128
 
104
129
  ---
105
130
 
@@ -1782,9 +1807,9 @@ configs:
1782
1807
 
1783
1808
  **TR — build sırası (@xrystal/core lib):** `rm x/dist` → `tsc` → `tsc-alias` → `fix-dist-imports` → `minify-dist?` (`build.minify`)
1784
1809
 
1785
- **EN:** `prepublishOnly` / `release:prepare` runs lint → build → test. Publish CI strips `source/`; npm gets minified `x/dist` only (+ `x/bin`, seed `tmp.yml`, assets).
1810
+ **EN:** `prepublishOnly` = `release:prepare` + `verify-publish-config`. See [npm publish](#npm-publish--npm-yayın).
1786
1811
 
1787
- **TR:** `prepublishOnly` / `release:prepare` lint → build → test çalıştırır. Publish CI `source/` siler; npm’e yalnızca minify `x/dist` (+ `x/bin`, seed `tmp.yml`, assets) girer.
1812
+ **TR:** `prepublishOnly` = `release:prepare` + `verify-publish-config`. Bkz. [npm publish](#npm-publish--npm-yayın).
1788
1813
 
1789
1814
  ```bash
1790
1815
  xcore build
@@ -1833,9 +1858,9 @@ xcore start # bun x/dist/index.js (+ .global.env / .prod.env if present)
1833
1858
  3. **EN:** `git tag vX.Y.Z` + push → GitHub Actions publishes to npm.
1834
1859
  **TR:** Tag + push → CI npm’e publish eder.
1835
1860
 
1836
- **EN:** Never commit compiled `.js` under `source/`. Publish CI runs `prepare-npm-publish.mjs` — removes `source/`, ships minified `x/dist` only (folder tree preserved; identifiers mangled when `build.minify: true`).
1861
+ **EN:** Never commit `.js` under `source/`. Publish uses minified `x/dist` only — [npm publish](#npm-publish--npm-yayın).
1837
1862
 
1838
- **TR:** `source/` altına derlenmiş `.js` commit etme. Publish CI `prepare-npm-publish.mjs` çalıştırır — `source/` silinir, npm’e yalnızca minify `x/dist` gider (klasör yapısı korunur; `build.minify: true` ile identifier’lar küçültülür).
1863
+ **TR:** `source/` altına `.js` commit etme. Publish yalnızca minify `x/dist` — [npm publish](#npm-publish--npm-yayın).
1839
1864
 
1840
1865
  **EN:** Service `npm run tag` does not publish `@xrystal/core` — use `xcore tag` or `"release:tag": "xcore tag"` on the **service** repo.
1841
1866
 
@@ -2295,9 +2320,9 @@ bun run build # tsc → x/dist (+ fix-dist-imports; minify if tmp
2295
2320
  **EN:** Lightweight unit/integration tests (no full Awilix boot in most suites). Path alias `@/*` → `./source/*` via `bunfig.toml`.
2296
2321
  **TR:** Hafif unit/integration testleri (çoğu suite’te tam Awilix boot yok). `@/*` alias `bunfig.toml` ile çözülür.
2297
2322
 
2298
- **EN:** Publish CI: `lint` → `build` → `test` → `prepare-npm-publish` (drops `source/`) → **`verify-npm-pack`** (fails if any `source/` in tarball) → `npm publish`. One-time step also unpublishes leaked `3.37.0–3.37.2` (remove next commit).
2323
+ **EN:** Publish CI: `lint` → `build` → `test` → `prepare-npm-publish` → `verify-npm-pack` → `npm publish`. Details: [npm publish](#npm-publish--npm-yayın).
2299
2324
 
2300
- **TR:** Publish CI: `lint` → `build` → `test` → `prepare-npm-publish` (`source/` silinir) → **`verify-npm-pack`** (tarball’da `source/` varsa fail) → `npm publish`. Tek seferlik adım sızan `3.37.0–3.37.2` sürümlerini kaldırır (sonraki commit’te sil).
2325
+ **TR:** Publish CI: `lint` → `build` → `test` → `prepare-npm-publish` → `verify-npm-pack` → `npm publish`. Detay: [npm publish](#npm-publish--npm-yayın).
2301
2326
 
2302
2327
  `express` is a **devDependency** only — not shipped to apps / uygulamalara gitmez.
2303
2328
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.37.3",
4
+ "version": "3.38.1",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -19,13 +19,13 @@
19
19
  "tsconfig.base.json",
20
20
  "README.md"
21
21
  ],
22
- "main": "./x/dist/index.js",
23
- "types": "./x/dist/index.d.ts",
22
+ "main": "./x/dist/project/index.js",
23
+ "types": "./x/dist/project/index.d.ts",
24
24
  "exports": {
25
25
  "./tsconfig.base.json": "./tsconfig.base.json",
26
26
  ".": {
27
- "types": "./x/dist/index.d.ts",
28
- "default": "./x/dist/index.js"
27
+ "types": "./x/dist/project/index.d.ts",
28
+ "default": "./x/dist/project/index.js"
29
29
  },
30
30
  "./utils": {
31
31
  "types": "./x/dist/utils/index.d.ts",
@@ -59,7 +59,7 @@
59
59
  "build": "node x/bin/main-cli.js build",
60
60
  "test": "bun test x/tests",
61
61
  "lint": "eslint source",
62
- "prepublishOnly": "bun run release:prepare",
62
+ "prepublishOnly": "bun run release:prepare && node x/bin/scripts/verify-publish-config.mjs",
63
63
  "release:prepare": "bun run lint && bun run build && bun test x/tests",
64
64
  "build:prod": "bun run release:prepare && node x/bin/scripts/clean-source-types.mjs",
65
65
  "build:dev": "node x/bin/main-cli.js dev",
@@ -9,7 +9,7 @@ import {
9
9
  readProjectPackageJson,
10
10
  } from '../helpers/project-root.mjs'
11
11
  import { listRuntimeInventory, resolveRuntimeInfo } from '../helpers/runtime-info.mjs'
12
- import { evaluateVersionBump, getLatestTagVersion, getVersionState, VERSION_PATTERN } from '../scripts/version-check.mjs'
12
+ import { evaluateVersionBump, getVersionState, resolveCommitVersionHint, resolveVersionBaseline, VERSION_PATTERN } from '../scripts/version-check.mjs'
13
13
  import { auditTsconfigAlignment, resolveToolchainPathsFromProject } from '../helpers/toolchain-config.mjs'
14
14
  import { isGitHookInstalled } from '../scripts/install-git-hooks.mjs'
15
15
 
@@ -112,14 +112,23 @@ export function registerDoctorCommand(cli, { cliName = 'xcore' } = {}) {
112
112
  console.log(` ${'disk version'.padEnd(18)}${state.disk.version}`)
113
113
  console.log(` ${'version match'.padEnd(18)}${state.versionMatch ? chalk.green('yes') : chalk.red('no')}`)
114
114
  console.log(` ${'package.json'.padEnd(18)}${state.isPackageJsonClean ? chalk.green('committed') : chalk.yellow('dirty')}`)
115
- const latestTag = getLatestTagVersion(root)
115
+ const { latestTag, parentVersion } = resolveVersionBaseline(root)
116
+ const commitHint = resolveCommitVersionHint(root)
116
117
  console.log(` ${'latest tag'.padEnd(18)}${latestTag ? `v${latestTag}` : chalk.gray('none')}`)
118
+ console.log(` ${'prev commit'.padEnd(18)}${parentVersion ? `v${parentVersion}` : chalk.gray('none')}`)
119
+ console.log(` ${'commit hint'.padEnd(18)}${commitHint ? `v${commitHint}` : chalk.gray('none')}`)
120
+ if (commitHint && commitHint !== state.committed.version) {
121
+ console.log(` ${'commit/pkg'.padEnd(18)}${chalk.red(`mismatch (want v${commitHint})`)}`)
122
+ } else if (commitHint) {
123
+ console.log(` ${'commit/pkg'.padEnd(18)}${chalk.green('aligned')}`)
124
+ }
117
125
  const evaluation = evaluateVersionBump(state.committed.version, 'HEAD', root)
118
126
  if (evaluation.baselineVersion) {
119
- const bumpText = evaluation.ok
120
- ? chalk.green(`ok (${evaluation.status})`)
121
- : chalk.red(`must be > ${evaluation.baselineVersion}`)
127
+ const bumpText = evaluation.ok ? chalk.green(`ok (${evaluation.status})`) : chalk.red(evaluation.status)
122
128
  console.log(` bump vs ${evaluation.baselineLabel}: ${bumpText}`)
129
+ if (evaluation.gap?.warnings?.length) {
130
+ console.log(` ${'jump warning'.padEnd(18)}${chalk.yellow(evaluation.gap.warnings.join('; '))}`)
131
+ }
123
132
  } else {
124
133
  console.log(` ${'bump check'.padEnd(18)}${chalk.green('first release baseline')}`)
125
134
  }
@@ -12,7 +12,6 @@ const CLI_GENERATED_SCHEMA = path.join(CLI_BIN_DIR, '.generated/tmp-schema.mjs')
12
12
  const CLI_SCHEMA_SOURCE = 'source/utils/helpers/tmp/tmp-schema.ts'
13
13
 
14
14
  const CORE_EXPORT_SUBPATHS = [
15
- '',
16
15
  'utils',
17
16
  'loader',
18
17
  'loader/controller',
@@ -37,16 +36,19 @@ export function resolveDistLayout(root = process.cwd()) {
37
36
 
38
37
  export function buildCorePackageExports(distPrefix) {
39
38
  const base = distPrefix.replace(/\/$/, '')
39
+ const mainEntry = `${base}/project/index`
40
40
  const exports = {
41
41
  './tsconfig.base.json': './tsconfig.base.json',
42
+ '.': {
43
+ types: `${mainEntry}.d.ts`,
44
+ default: `${mainEntry}.js`,
45
+ },
42
46
  }
43
47
 
44
48
  for (const sub of CORE_EXPORT_SUBPATHS) {
45
- const suffix = sub ? `/${sub}` : ''
46
- const key = sub ? `./${sub}` : '.'
47
- exports[key] = {
48
- types: `${base}${suffix}/index.d.ts`,
49
- default: `${base}${suffix}/index.js`,
49
+ exports[`./${sub}`] = {
50
+ types: `${base}/${sub}/index.d.ts`,
51
+ default: `${base}/${sub}/index.js`,
50
52
  }
51
53
  }
52
54
 
@@ -105,8 +107,8 @@ export function syncPackageManifest(root = process.cwd(), { write = true } = {})
105
107
  const { distPrefix, distRel } = resolveDistLayout(root)
106
108
  const next = {
107
109
  ...pkg,
108
- main: `${distPrefix}/index.js`,
109
- types: `${distPrefix}/index.d.ts`,
110
+ main: `${distPrefix}/project/index.js`,
111
+ types: `${distPrefix}/project/index.d.ts`,
110
112
  exports: buildCorePackageExports(distPrefix),
111
113
  files: normalizeFilesList(pkg.files, distRel),
112
114
  }
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs'
3
3
  import path from 'node:path'
4
+ import { PublishGuardError, runPublishGuards } from './publish-guard.mjs'
4
5
 
5
6
  const root = process.cwd()
6
7
 
@@ -24,26 +25,15 @@ for (const rel of pathsToRemove) {
24
25
  console.log(`prepare-npm-publish: removed ${rel}`)
25
26
  }
26
27
 
27
- const distJs = []
28
- function countDistJs(dir) {
29
- for (const name of fs.readdirSync(dir)) {
30
- const abs = path.join(dir, name)
31
- const stat = fs.statSync(abs)
32
- if (stat.isDirectory()) countDistJs(abs)
33
- else if (name.endsWith('.js')) distJs.push(abs)
34
- }
35
- }
36
-
37
- const distDir = path.join(root, 'x', 'dist')
38
- if (!fs.existsSync(distDir)) {
28
+ if (!fs.existsSync(path.join(root, 'x', 'dist'))) {
39
29
  console.error('prepare-npm-publish: x/dist missing — run build first')
40
30
  process.exit(1)
41
31
  }
42
32
 
43
- countDistJs(distDir)
44
- if (distJs.length < 10) {
45
- console.error(`prepare-npm-publish: expected full dist tree, found ${distJs.length} .js file(s)`)
33
+ try {
34
+ const { jsCount } = runPublishGuards(root, { strictDisk: true })
35
+ console.log(`prepare-npm-publish: ready (${jsCount} .js in x/dist, verified)`)
36
+ } catch (error) {
37
+ console.error(`prepare-npm-publish: ✗ ${error instanceof PublishGuardError ? error.message : error.message}`)
46
38
  process.exit(1)
47
39
  }
48
-
49
- console.log(`prepare-npm-publish: ready (${distJs.length} .js in x/dist, no source/)`)
@@ -0,0 +1,113 @@
1
+ import { execSync } from 'node:child_process'
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+
5
+ export class PublishGuardError extends Error {
6
+ constructor(message) {
7
+ super(message)
8
+ this.name = 'PublishGuardError'
9
+ }
10
+ }
11
+
12
+ export function readPackage(root = process.cwd()) {
13
+ return JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
14
+ }
15
+
16
+ export function assertFilesListNoSource(pkg) {
17
+ const files = Array.isArray(pkg.files) ? pkg.files : []
18
+ const bad = files.filter((entry) => {
19
+ const normalized = String(entry).replace(/^\.\//, '').replace(/\\/g, '/')
20
+ return normalized === 'source' || normalized.startsWith('source/')
21
+ })
22
+ if (bad.length > 0) {
23
+ throw new PublishGuardError(`package.json files must not include source/ (found: ${bad.join(', ')})`)
24
+ }
25
+ }
26
+
27
+ export function assertFilesListHasDist(pkg) {
28
+ const files = Array.isArray(pkg.files) ? pkg.files : []
29
+ if (!files.some((entry) => String(entry).replace(/^\.\//, '').includes('dist'))) {
30
+ throw new PublishGuardError('package.json files must include x/dist')
31
+ }
32
+ }
33
+
34
+ export function assertMainExportsPointToDist(pkg) {
35
+ const main = String(pkg.main ?? '')
36
+ if (!main.includes('/dist/')) {
37
+ throw new PublishGuardError(`package.json main must point to x/dist (got ${main || 'empty'})`)
38
+ }
39
+ const exports = pkg.exports ?? {}
40
+ for (const [key, value] of Object.entries(exports)) {
41
+ if (key === './tsconfig.base.json') continue
42
+ const target = typeof value === 'string' ? value : value?.default
43
+ if (target && !String(target).includes('/dist/')) {
44
+ throw new PublishGuardError(`exports[${key}] must point to x/dist (got ${target})`)
45
+ }
46
+ }
47
+ }
48
+
49
+ export function assertSourceAbsentOnDisk(root = process.cwd()) {
50
+ if (fs.existsSync(path.join(root, 'source'))) {
51
+ throw new PublishGuardError('source/ must not exist on disk at publish time')
52
+ }
53
+ }
54
+
55
+ export function countDistJs(root = process.cwd()) {
56
+ const distDir = path.join(root, 'x', 'dist')
57
+ if (!fs.existsSync(distDir)) return 0
58
+ let count = 0
59
+ const walk = (dir) => {
60
+ for (const name of fs.readdirSync(dir)) {
61
+ const abs = path.join(dir, name)
62
+ if (fs.statSync(abs).isDirectory()) walk(abs)
63
+ else if (name.endsWith('.js')) count += 1
64
+ }
65
+ }
66
+ walk(distDir)
67
+ return count
68
+ }
69
+
70
+ export function assertDistTree(root = process.cwd(), minJs = 10) {
71
+ const distIndex = path.join(root, 'x/dist/index.js')
72
+ if (!fs.existsSync(distIndex)) {
73
+ throw new PublishGuardError('x/dist/index.js missing — run build first')
74
+ }
75
+ const jsCount = countDistJs(root)
76
+ if (jsCount < minJs) {
77
+ throw new PublishGuardError(`x/dist incomplete (${jsCount} .js files, need >= ${minJs})`)
78
+ }
79
+ }
80
+
81
+ export function assertDistMinified(root = process.cwd()) {
82
+ const indexJs = fs.readFileSync(path.join(root, 'x/dist/index.js'), 'utf8')
83
+ const lines = indexJs.split('\n').filter((line) => line.trim().length > 0)
84
+ const looksReadable = lines.length > 3 && indexJs.includes("from './") && !indexJs.includes('from"')
85
+ if (looksReadable) {
86
+ throw new PublishGuardError('x/dist/index.js looks unminified — enable build.minify before publish')
87
+ }
88
+ }
89
+
90
+ export function assertNpmPackClean(root = process.cwd()) {
91
+ const dryRun = execSync('npm pack --dry-run 2>&1', { cwd: root, encoding: 'utf8' })
92
+ if (/source\/.*\.ts/.test(dryRun) || /npm notice.*source\//.test(dryRun)) {
93
+ throw new PublishGuardError('npm pack tarball lists source/ — TypeScript source must not ship')
94
+ }
95
+ if (!/x\/dist\/.*\.js/.test(dryRun)) {
96
+ throw new PublishGuardError('npm pack tarball must include x/dist/**/*.js')
97
+ }
98
+ return dryRun
99
+ }
100
+
101
+ export function runPublishGuards(root = process.cwd(), { strictDisk = false } = {}) {
102
+ const pkg = readPackage(root)
103
+ assertFilesListNoSource(pkg)
104
+ assertFilesListHasDist(pkg)
105
+ assertMainExportsPointToDist(pkg)
106
+ assertDistTree(root)
107
+ assertNpmPackClean(root)
108
+ if (strictDisk) {
109
+ assertSourceAbsentOnDisk(root)
110
+ assertDistMinified(root)
111
+ }
112
+ return { pkg, jsCount: countDistJs(root) }
113
+ }
@@ -1,45 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { execSync } from 'node:child_process'
3
- import fs from 'node:fs'
4
- import path from 'node:path'
5
-
6
- const root = process.cwd()
7
- const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
8
-
9
- function fail(message) {
10
- console.error(`verify-npm-pack: ✗ ${message}`)
2
+ import { PublishGuardError, runPublishGuards } from './publish-guard.mjs'
3
+
4
+ try {
5
+ const { jsCount } = runPublishGuards(process.cwd(), { strictDisk: true })
6
+ console.log('verify-npm-pack: ✓ package.json files — no source/')
7
+ console.log('verify-npm-pack: ✓ main/exports → x/dist')
8
+ console.log(`verify-npm-pack: ✓ npm pack clean (${jsCount} .js, minified)`)
9
+ } catch (error) {
10
+ console.error(`verify-npm-pack: ✗ ${error instanceof PublishGuardError ? error.message : error.message}`)
11
11
  process.exit(1)
12
12
  }
13
-
14
- if (fs.existsSync(path.join(root, 'source'))) {
15
- fail('source/ still exists on disk — run prepare-npm-publish.mjs first')
16
- }
17
-
18
- const files = Array.isArray(pkg.files) ? pkg.files : []
19
- if (files.some((entry) => {
20
- const normalized = String(entry).replace(/^\.\//, '')
21
- return normalized === 'source' || normalized.startsWith('source/')
22
- })) {
23
- fail('package.json files must not include source/')
24
- }
25
-
26
- if (!files.some((entry) => String(entry).replace(/^\.\//, '').includes('dist'))) {
27
- fail('package.json files must include x/dist')
28
- }
29
-
30
- const dryRun = execSync('npm pack --dry-run 2>&1', { cwd: root, encoding: 'utf8' })
31
-
32
- if (/source\/.*\.ts/.test(dryRun) || /npm notice.*source\//.test(dryRun)) {
33
- fail('npm pack tarball lists source/ — TypeScript source must not ship')
34
- }
35
-
36
- if (!/x\/dist\/.*\.js/.test(dryRun)) {
37
- fail('npm pack tarball must include x/dist/**/*.js')
38
- }
39
-
40
- if (!fs.existsSync(path.join(root, 'x/dist/index.js'))) {
41
- fail('x/dist/index.js missing')
42
- }
43
-
44
- console.log('verify-npm-pack: ✓ no source/ in package')
45
- console.log('verify-npm-pack: ✓ x/dist runtime present')
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { PublishGuardError, runPublishGuards } from './publish-guard.mjs'
3
+
4
+ try {
5
+ runPublishGuards(process.cwd(), { strictDisk: false })
6
+ console.log('verify-publish-config: ✓ npm pack would not ship source/')
7
+ } catch (error) {
8
+ console.error(`verify-publish-config: ✗ ${error instanceof PublishGuardError ? error.message : error.message}`)
9
+ process.exit(1)
10
+ }
@@ -118,56 +118,130 @@ export function getLatestTagVersion(root = getProjectRoot()) {
118
118
  }
119
119
  }
120
120
 
121
+ export function pickHigherSemver(a, b) {
122
+ if (!a) return b ?? null
123
+ if (!b) return a
124
+ return compareSemver(a, b) >= 0 ? a : b
125
+ }
126
+
127
+ export function getHeadCommitSubject(root = getProjectRoot()) {
128
+ try {
129
+ return run('git log -1 --pretty=%s', { root })
130
+ } catch {
131
+ return ''
132
+ }
133
+ }
134
+
135
+ export function extractVersionFromCommitMessage(message) {
136
+ const text = String(message ?? '').trim()
137
+ const exact = text.match(/^v?(\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?)$/i)
138
+ if (exact) return exact[1]
139
+ const embedded = text.match(/\bv?(\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?)\b/)
140
+ return embedded?.[1] ?? null
141
+ }
142
+
143
+ export function resolveCommitVersionHint(root = getProjectRoot()) {
144
+ return extractVersionFromCommitMessage(getHeadCommitSubject(root))
145
+ }
146
+
147
+ export function analyzeSemverGap(from, to) {
148
+ if (!from || !to) return { kind: 'unknown', warnings: [] }
149
+ const cmp = compareSemver(to, from)
150
+ if (cmp < 0) return { kind: 'downgrade', warnings: [`downgrade ${from} → ${to}`] }
151
+ if (cmp === 0) return { kind: 'same', warnings: [] }
152
+
153
+ const f = parseSemver(from)
154
+ const t = parseSemver(to)
155
+ const warnings = []
156
+ const majorJump = t.major - f.major
157
+ const minorJump = t.minor - f.minor
158
+ const patchJump = t.patch - f.patch
159
+
160
+ if (majorJump > 1) warnings.push(`major jump +${majorJump} (${from} → ${to})`)
161
+ if (majorJump === 0 && minorJump > 1) warnings.push(`minor jump +${minorJump} (${from} → ${to})`)
162
+ if (majorJump === 0 && minorJump === 0 && patchJump > 1) warnings.push(`patch jump +${patchJump} (${from} → ${to})`)
163
+ if (majorJump === 0 && minorJump > 0 && patchJump > 0) warnings.push(`mixed minor+patch bump (${from} → ${to})`)
164
+
165
+ const kind = majorJump > 0 ? 'major' : minorJump > 0 ? 'minor' : 'patch'
166
+ return { kind, warnings }
167
+ }
168
+
169
+ export function assertCommitPackageVersionAlign(version, root = getProjectRoot()) {
170
+ const hint = resolveCommitVersionHint(root)
171
+ if (!hint) return { hint: null, aligned: true }
172
+ if (hint === version) return { hint, aligned: true }
173
+ throw new Error(
174
+ `Version mismatch:\n commit message: v${hint}\n package.json: ${version}\n\nBump package.json to ${hint} (or fix the commit message) before tagging.`,
175
+ )
176
+ }
177
+
121
178
  export function resolveVersionBaseline(root = getProjectRoot()) {
122
179
  const latestTag = getLatestTagVersion(root)
180
+ const headVersion = readPackageJsonVersionAtRef('HEAD', root)
123
181
  const parentVersion = readPackageJsonVersionAtRef('HEAD~1', root)
124
- const baselineVersion = latestTag ?? parentVersion
125
- const baselineLabel = latestTag ? `latest tag v${latestTag}` : 'previous commit'
126
- return { baselineVersion, baselineLabel, latestTag, parentVersion }
182
+ const baselineVersion = pickHigherSemver(latestTag, parentVersion)
183
+
184
+ let baselineLabel = 'first release'
185
+ if (latestTag && parentVersion) {
186
+ if (latestTag === parentVersion) baselineLabel = `latest tag / previous commit v${latestTag}`
187
+ else if (compareSemver(latestTag, parentVersion) > 0) baselineLabel = `latest tag v${latestTag} (> previous commit v${parentVersion})`
188
+ else baselineLabel = `previous commit v${parentVersion} (> latest tag v${latestTag})`
189
+ } else if (latestTag) {
190
+ baselineLabel = `latest tag v${latestTag}`
191
+ } else if (parentVersion) {
192
+ baselineLabel = `previous commit v${parentVersion}`
193
+ }
194
+
195
+ return { baselineVersion, baselineLabel, latestTag, parentVersion, headVersion }
127
196
  }
128
197
 
129
198
  export function resolveStagedVersionBaseline(root = getProjectRoot()) {
130
199
  const headVersion = readPackageJsonVersionAtRef('HEAD', root)
131
200
  const latestTag = getLatestTagVersion(root)
201
+ const parentVersion = readPackageJsonVersionAtRef('HEAD~1', root)
202
+ const baselineVersion = pickHigherSemver(pickHigherSemver(latestTag, headVersion), parentVersion)
132
203
 
133
- if (latestTag && headVersion) {
134
- const preferTag = compareSemver(latestTag, headVersion) >= 0
135
- return {
136
- baselineVersion: preferTag ? latestTag : headVersion,
137
- baselineLabel: preferTag ? `latest tag v${latestTag}` : 'current HEAD commit',
138
- latestTag,
139
- headVersion,
140
- }
141
- }
142
-
143
- if (latestTag) {
144
- return { baselineVersion: latestTag, baselineLabel: `latest tag v${latestTag}`, latestTag, headVersion }
145
- }
204
+ let baselineLabel = 'version floor'
205
+ if (baselineVersion === latestTag) baselineLabel = `latest tag v${latestTag}`
206
+ else if (baselineVersion === headVersion) baselineLabel = 'current HEAD commit'
207
+ else if (baselineVersion === parentVersion) baselineLabel = 'previous commit'
146
208
 
147
- return {
148
- baselineVersion: headVersion,
149
- baselineLabel: 'current HEAD commit',
150
- latestTag: null,
151
- headVersion,
152
- }
209
+ return { baselineVersion, baselineLabel, latestTag, headVersion, parentVersion }
153
210
  }
154
211
 
155
- /** @returns {{ ok: boolean, baselineVersion: string|null, baselineLabel: string, status: string }} */
212
+ /** @returns {{ ok: boolean, baselineVersion: string|null, baselineLabel: string, status: string, gap: ReturnType<typeof analyzeSemverGap>, commitHint: string|null, alignedWithCommit: boolean }} */
156
213
  export function evaluateVersionBump(version, ref = 'HEAD', root = getProjectRoot()) {
157
- const { baselineVersion, baselineLabel, latestTag } = resolveVersionBaseline(root)
214
+ const { baselineVersion, baselineLabel, latestTag, headVersion, parentVersion } = resolveVersionBaseline(root)
215
+ const commitHint = resolveCommitVersionHint(root)
216
+ const alignedWithCommit = !commitHint || commitHint === version
217
+ const gap = baselineVersion ? analyzeSemverGap(baselineVersion, version) : { kind: 'unknown', warnings: [] }
218
+
158
219
  if (!baselineVersion) {
159
- return { ok: true, baselineVersion: null, baselineLabel: 'first release', status: 'first release' }
220
+ return { ok: true, baselineVersion: null, baselineLabel: 'first release', status: 'first release', gap, commitHint, alignedWithCommit }
160
221
  }
161
222
 
162
223
  assertVersionFormat(version)
163
224
  const cmp = compareSemver(version, baselineVersion)
164
225
 
226
+ if (!alignedWithCommit) {
227
+ return {
228
+ ok: false,
229
+ baselineVersion,
230
+ baselineLabel,
231
+ status: `commit wants v${commitHint}, package.json is ${version}`,
232
+ gap,
233
+ commitHint,
234
+ alignedWithCommit,
235
+ }
236
+ }
237
+
165
238
  if (cmp > 0) {
166
- return { ok: true, baselineVersion, baselineLabel, status: `>${baselineVersion}` }
239
+ const jump = gap.warnings.length ? ` [${gap.warnings.join('; ')}]` : ''
240
+ return { ok: true, baselineVersion, baselineLabel, status: `>${baselineVersion} (${gap.kind})${jump}`, gap, commitHint, alignedWithCommit }
167
241
  }
168
242
 
169
243
  if (cmp < 0) {
170
- return { ok: false, baselineVersion, baselineLabel, status: `<${baselineVersion}` }
244
+ return { ok: false, baselineVersion, baselineLabel, status: `<${baselineVersion}`, gap, commitHint, alignedWithCommit }
171
245
  }
172
246
 
173
247
  if (latestTag && version === latestTag) {
@@ -178,6 +252,9 @@ export function evaluateVersionBump(version, ref = 'HEAD', root = getProjectRoot
178
252
  baselineVersion,
179
253
  baselineLabel,
180
254
  status: `=${latestTag} (retag on new commit)`,
255
+ gap,
256
+ commitHint,
257
+ alignedWithCommit,
181
258
  }
182
259
  }
183
260
  return {
@@ -185,10 +262,13 @@ export function evaluateVersionBump(version, ref = 'HEAD', root = getProjectRoot
185
262
  baselineVersion,
186
263
  baselineLabel,
187
264
  status: `=${latestTag} (tag on HEAD)`,
265
+ gap,
266
+ commitHint,
267
+ alignedWithCommit,
188
268
  }
189
269
  }
190
270
 
191
- return { ok: false, baselineVersion, baselineLabel, status: `=${baselineVersion}` }
271
+ return { ok: false, baselineVersion, baselineLabel, status: `=${baselineVersion}`, gap, commitHint, alignedWithCommit }
192
272
  }
193
273
 
194
274
  export function assertVersionIncreased(current, baseline, baselineLabel = 'previous version') {
@@ -296,7 +376,17 @@ export function assertReadyToTag({ requireClean = false, root = getProjectRoot()
296
376
  }
297
377
 
298
378
  assertVersionFormat(version)
299
- assertVersionBumpForTag(root)
379
+ assertCommitPackageVersionAlign(version, root)
380
+
381
+ const evaluation = evaluateVersionBump(version, 'HEAD', root)
382
+ if (!evaluation.ok) {
383
+ throw new Error(
384
+ `package.json version is not valid for release.\n current: ${version}\n floor: ${evaluation.baselineVersion} (${evaluation.baselineLabel})\n status: ${evaluation.status}`,
385
+ )
386
+ }
387
+ if (evaluation.gap?.warnings?.length) {
388
+ console.warn(`⚠ Large version jump: ${evaluation.gap.warnings.join('; ')}`)
389
+ }
300
390
 
301
391
  const tag = resolveTagState(version, 'HEAD', root)
302
392
 
package/x/dist/index.d.ts CHANGED
@@ -1,3 +1 @@
1
- export { default as coreLoader, core, coreInit } from './project/index.js';
2
- export { ensureCoreTmpEntry, isCorePackageRoot } from './utils/helpers/core/tmp-layout';
3
- export { getTmpSnapshot } from './utils/helpers/tmp/tmp-loader';
1
+ export {};
package/x/dist/index.js CHANGED
@@ -1 +1 @@
1
- import r from"./project/index.js";import{ensureCoreTmpEntry as e,isCorePackageRoot as t}from"./utils/helpers/core/tmp-layout.js";import{getTmpSnapshot as a}from"./utils/helpers/tmp/tmp-loader.js";await(async()=>{const o=process.cwd();if(t(o))e(o);a();await r({})})();export{default as coreLoader,core,coreInit}from"./project/index.js";export{ensureCoreTmpEntry,isCorePackageRoot}from"./utils/helpers/core/tmp-layout.js";export{getTmpSnapshot}from"./utils/helpers/tmp/tmp-loader.js";
1
+ import a from"./project/index.js";await(async()=>{await a({})})();
@@ -1,8 +1,12 @@
1
+ export { ensureCoreTmpEntry, isCorePackageRoot } from '../utils/helpers/core/tmp-layout';
2
+ export { getTmpSnapshot } from '../utils/helpers/tmp/tmp-loader';
1
3
  export declare const core: {
2
4
  _: Record<string, unknown>;
3
5
  };
4
6
  export declare const coreInit: (params: {
5
- locales?: Record<string, any>;
7
+ locales?: Record<string, unknown>;
6
8
  }) => Promise<void>;
7
- declare const coreLoader: ({}: {}) => Promise<{} | undefined>;
9
+ declare const coreLoader: (_params?: Record<string, never>) => Promise<{
10
+ _: Record<string, unknown>;
11
+ }>;
8
12
  export default coreLoader;
@@ -1 +1 @@
1
- var __dirname="/home/runner/work/-xrystal-core/-xrystal-core/x/dist/project";import o from"path";import{System as t,Configs as i,Logger as a,Events as c,Localizations as n,DtoRuntime as p,Clients as l,Controller as m,KafkaForCore as f}from"../loader/index.js";import{Constants as v,getCore as g,x as _}from"../utils/index.js";export const core=g(),coreInit=async(e)=>{const{locales:r}=e;if(r)globalThis.__LOCAL_MESSAGES__=r};let s=!1;const u=async({})=>{if(s)return{};try{await(await _.load([o.join(__dirname,"..","loader","**/*.{ts,js}")],{exclude:[o.join(__dirname,"..","utils","**/class.x.{ts,js}")]})).initialize([{service:t,props:{core}},{service:i,props:{}},{service:f,props:{}},{service:a,props:{}},{service:c,props:{}},{service:n,props:{}},{service:p,props:{}},{service:m,props:{}},{service:l,props:{}}]);s=!0}catch(e){const r=e instanceof Error?e.message:String(e);console.error(`[${v.packageName} core failure]: ${r}`)}};export default u;
1
+ var __dirname="/home/runner/work/-xrystal-core/-xrystal-core/x/dist/project";import w from"path";import{System as G,Configs as I,Logger as J,Events as N,Localizations as O,DtoRuntime as Q,Clients as U,Controller as V,KafkaForCore as W}from"../loader/index.js";import{Constants as X,getCore as Y,x as Z}from"../utils/index.js";import{ensureCoreTmpEntry as _,isCorePackageRoot as $}from"../utils/helpers/core/tmp-layout.js";import{getTmpSnapshot as v}from"../utils/helpers/tmp/tmp-loader.js";export{ensureCoreTmpEntry,isCorePackageRoot}from"../utils/helpers/core/tmp-layout.js";export{getTmpSnapshot}from"../utils/helpers/tmp/tmp-loader.js";export const core=Y(),coreInit=async(q)=>{const{locales:b}=q;if(b)globalThis.__LOCAL_MESSAGES__=b};let A=!1;const x=async(q={})=>{if(A)return core;const b=process.cwd();if($(b))_(b);v();try{await(await Z.load([w.join(__dirname,"..","loader","**/*.{ts,js}")],{exclude:[w.join(__dirname,"..","utils","**/class.x.{ts,js}")]})).initialize([{service:G,props:{core}},{service:I,props:{}},{service:W,props:{}},{service:J,props:{}},{service:N,props:{}},{service:O,props:{}},{service:Q,props:{}},{service:V,props:{}},{service:U,props:{}}]);A=!0;return core}catch(j){const B=j instanceof Error?j.message:String(j);console.error(`[${X.packageName} core failure]: ${B}`);throw j}};export default x;
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * ONE-TIME cleanup: remove npm versions that shipped source/ in the tarball.
4
- * Remove this script + the workflow step after leaked versions are gone.
5
- */
6
- import { execSync } from 'node:child_process'
7
- import fs from 'node:fs'
8
- import path from 'node:path'
9
-
10
- const pkgName = '@xrystal/core'
11
- const root = process.cwd()
12
- const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
13
- const publishingVersion = pkg.version
14
-
15
- function run(cmd) {
16
- return execSync(cmd, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim()
17
- }
18
-
19
- function resolveVersionsToUnpublish() {
20
- const fromEnv = process.env.UNPUBLISH_VERSIONS?.trim()
21
- if (fromEnv) {
22
- return fromEnv.split(',').map((v) => v.trim()).filter(Boolean)
23
- }
24
-
25
- let published = []
26
- try {
27
- const raw = run(`npm view ${pkgName} versions --json`)
28
- published = JSON.parse(raw)
29
- if (!Array.isArray(published)) published = [published]
30
- } catch {
31
- console.log('unpublish-leaked: no published versions found on registry')
32
- return []
33
- }
34
-
35
- return published
36
- .filter((v) => v !== publishingVersion)
37
- .slice(-3)
38
- }
39
-
40
- const versions = resolveVersionsToUnpublish()
41
- if (versions.length === 0) {
42
- console.log('unpublish-leaked: nothing to unpublish')
43
- process.exit(0)
44
- }
45
-
46
- console.log(`unpublish-leaked: targeting ${versions.join(', ')} (keeping ${publishingVersion} for publish)`)
47
-
48
- for (const version of versions) {
49
- try {
50
- run(`npm unpublish ${pkgName}@${version} --force`)
51
- console.log(`unpublish-leaked: ✓ removed ${pkgName}@${version}`)
52
- } catch (error) {
53
- const stderr = error.stderr?.toString?.() ?? String(error)
54
- console.warn(`unpublish-leaked: ⚠ unpublish ${version} failed: ${stderr.split('\n')[0]}`)
55
- try {
56
- run(`npm deprecate ${pkgName}@${version} "Removed: shipped source by mistake. Upgrade to a newer release."`)
57
- console.log(`unpublish-leaked: deprecated ${pkgName}@${version} as fallback`)
58
- } catch {
59
- console.warn(`unpublish-leaked: ⚠ deprecate also failed for ${version}`)
60
- }
61
- }
62
- }