@xrystal/core 3.55.90 → 3.55.92

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
@@ -55,9 +55,9 @@ npm install @xrystal/core
55
55
 
56
56
  ## Release (npm) / Yayın (npm)
57
57
 
58
- **EN:** `xry version patch` (also `minor` / `major`) bumps `package.json` and **commits that bump** (no tag). Then `xry version release` (aliases: `xry release`, `xry tag`) ships the committed version: full gates + SemVer `v*` push; GitHub Actions `publish.yml` publishes to npm with `--tag latest` via [Trusted Publishers](https://docs.npmjs.com/trusted-publishers) (OIDC). Housekeeping: `artifact.yml` (zip backups) and `clean.yml` (scheduled release pruning).
58
+ **EN:** `xry version patch` (also `minor` / `major`) bumps `package.json` and **commits that bump** (no tag). On bun/npm projects it also refreshes the lockfile when needed (`bun install --frozen-lockfile` parity with CI) and commits it with the bump. `xry sync` does the same after pinning `@xrystal/core`; `xry version release` / `xry release` / `xry tag` refuse to ship while the lockfile drifts. Then `xry version release` (aliases: `xry release`, `xry tag`) ships the committed version: full gates + SemVer `v*` push; GitHub Actions `publish.yml` publishes to npm with `--tag latest` via [Trusted Publishers](https://docs.npmjs.com/trusted-publishers) (OIDC). Housekeeping: `artifact.yml` (zip backups) and `clean.yml` (scheduled release pruning).
59
59
 
60
- **TR:** `xry version patch` (`minor` / `major`) `package.json` sürümünü yazar ve **o bump’ı commit eder** (tag yok). Sonra `xry version release` (`xry release` / `xry tag`) commit’lenmiş sürümü yayınlar: tam kapı + SemVer `v*` push; `publish.yml` npm’e `--tag latest` ve [Trusted Publisher](https://docs.npmjs.com/trusted-publishers) (OIDC) ile yazar. Bakım: `artifact.yml` (zip yedek), `clean.yml` (release temizliği).
60
+ **TR:** `xry version patch` (`minor` / `major`) `package.json` sürümünü yazar ve **o bump’ı commit eder** (tag yok). Bun/npm projelerinde gerekirse lockfile’ı CI ile aynı şekilde yeniler ve bump commit’ine ekler. `xry sync` core pin sonrası lockfile hizalar; `xry version release` / `xry release` / `xry tag` lock drift varken çıkmaz. Sonra `xry version release` (`xry release` / `xry tag`) commit’lenmiş sürümü yayınlar: tam kapı + SemVer `v*` push; `publish.yml` npm’e `--tag latest` ve [Trusted Publisher](https://docs.npmjs.com/trusted-publishers) (OIDC) ile yazar. Bakım: `artifact.yml` (zip yedek), `clean.yml` (release temizliği).
61
61
 
62
62
  ## Further reading / Ek kaynak
63
63
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.55.90",
4
+ "version": "3.55.92",
5
5
  "description": "Runtime framework and CLI for API services, frontends, and multi-repo workspaces",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -0,0 +1,149 @@
1
+ import { execSync } from 'node:child_process'
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+
5
+ import { detectPackageManager } from './runtime-info.mjs'
6
+
7
+ /** Lock artifacts to stage after a package.json bump / dep pin. */
8
+ export const LOCKFILE_CANDIDATES = ['bun.lock', 'bun.lockb', 'package-lock.json', 'pnpm-lock.yaml', 'yarn.lock']
9
+
10
+ export function presentLockfiles(root) {
11
+ return LOCKFILE_CANDIDATES.filter((name) => fs.existsSync(path.join(root, name)))
12
+ }
13
+
14
+ function frozenInstallCommand(packageManager) {
15
+ switch (packageManager) {
16
+ case 'bun':
17
+ return 'bun install --frozen-lockfile'
18
+ case 'pnpm':
19
+ return 'pnpm install --frozen-lockfile'
20
+ case 'yarn':
21
+ return 'yarn install --immutable'
22
+ case 'npm':
23
+ default:
24
+ return 'npm ci'
25
+ }
26
+ }
27
+
28
+ function refreshInstallCommand(packageManager) {
29
+ switch (packageManager) {
30
+ case 'bun':
31
+ return 'bun install'
32
+ case 'pnpm':
33
+ return 'pnpm install'
34
+ case 'yarn':
35
+ return 'yarn install'
36
+ case 'npm':
37
+ default:
38
+ return 'npm install'
39
+ }
40
+ }
41
+
42
+ function runQuiet(cmd, root) {
43
+ execSync(cmd, { cwd: root, stdio: 'pipe', encoding: 'utf8' })
44
+ }
45
+
46
+ /**
47
+ * Match Docker CI: package.json must agree with the lockfile.
48
+ * @returns {{ aligned: boolean, packageManager: string, lockfiles: string[], reason?: string }}
49
+ */
50
+ export function probeLockfileAlignment(root) {
51
+ const packageManager = detectPackageManager(root)
52
+ const lockfiles = presentLockfiles(root)
53
+
54
+ if (!fs.existsSync(path.join(root, 'package.json'))) {
55
+ return { aligned: true, packageManager, lockfiles, reason: 'no package.json' }
56
+ }
57
+
58
+ if (lockfiles.length === 0) {
59
+ return { aligned: true, packageManager, lockfiles, reason: 'no lockfile' }
60
+ }
61
+
62
+ try {
63
+ runQuiet(frozenInstallCommand(packageManager), root)
64
+ return { aligned: true, packageManager, lockfiles }
65
+ } catch (error) {
66
+ const detail = String(error.stderr ?? error.message ?? '').split('\n')[0]?.trim()
67
+ return {
68
+ aligned: false,
69
+ packageManager,
70
+ lockfiles,
71
+ reason: detail || 'lockfile does not match package.json',
72
+ }
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Regenerate lockfile when drifted; re-check frozen install.
78
+ * @returns {{ synced: boolean, changed: boolean, packageManager: string, lockfiles: string[], reason?: string, dryRun?: boolean }}
79
+ */
80
+ export function ensureLockfileSynced(root, { dryRun = false, install = true } = {}) {
81
+ const probe = probeLockfileAlignment(root)
82
+ if (probe.aligned) {
83
+ return {
84
+ synced: true,
85
+ changed: false,
86
+ packageManager: probe.packageManager,
87
+ lockfiles: probe.lockfiles,
88
+ reason: probe.reason,
89
+ }
90
+ }
91
+
92
+ if (dryRun) {
93
+ return {
94
+ synced: false,
95
+ changed: true,
96
+ dryRun: true,
97
+ packageManager: probe.packageManager,
98
+ lockfiles: probe.lockfiles,
99
+ reason: probe.reason,
100
+ }
101
+ }
102
+
103
+ if (!install) {
104
+ throw new Error(
105
+ `Lockfile drift (${probe.packageManager}): ${probe.reason}\n`
106
+ + ` Run \`${refreshInstallCommand(probe.packageManager)}\` and commit the lockfile, then xry version release.`,
107
+ )
108
+ }
109
+
110
+ execSync(refreshInstallCommand(probe.packageManager), { cwd: root, stdio: 'inherit' })
111
+
112
+ const after = probeLockfileAlignment(root)
113
+ if (!after.aligned) {
114
+ throw new Error(
115
+ `Lockfile still drifted after \`${refreshInstallCommand(probe.packageManager)}\`.\n`
116
+ + ` ${after.reason ?? 'Check package.json and lockfile manually.'}`,
117
+ )
118
+ }
119
+
120
+ return {
121
+ synced: true,
122
+ changed: true,
123
+ packageManager: probe.packageManager,
124
+ lockfiles: after.lockfiles,
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Before release/tag: align lockfile with package.json; require commit if install changed files.
130
+ */
131
+ export function assertLockfileCommitted(root, runCmd) {
132
+ const lockRefresh = ensureLockfileSynced(root)
133
+ if (!lockRefresh.changed) return lockRefresh
134
+
135
+ if (!runCmd) return lockRefresh
136
+
137
+ const dirtyLines = []
138
+ for (const file of LOCKFILE_CANDIDATES) {
139
+ const line = runCmd(`git status --porcelain -- ${file}`, { root })
140
+ if (line) dirtyLines.push(line)
141
+ }
142
+ if (dirtyLines.length) {
143
+ throw new Error(
144
+ 'Lockfile was updated to match package.json but is not committed.\n'
145
+ + `${dirtyLines.join('\n')}\n\nCommit the lockfile, then run version release again.`,
146
+ )
147
+ }
148
+ return lockRefresh
149
+ }
@@ -3,6 +3,7 @@ import fs from 'node:fs'
3
3
  import path from 'node:path'
4
4
 
5
5
  import { getRuntimeTooling, resolveProjectRuntime } from './cli-runtime.mjs'
6
+ import { ensureLockfileSynced } from './ensure-lockfile.mjs'
6
7
  import { packageDefaults } from './package-defaults.mjs'
7
8
 
8
9
  function readDeclaredCoreVersion(pkg) {
@@ -48,7 +49,15 @@ export function syncCoreDependency(root, targetVersion, { dryRun = false } = {})
48
49
  }
49
50
 
50
51
  if (dryRun) {
51
- return { synced: true, dryRun: true, declared, current, targetVersion }
52
+ const lockPreview = ensureLockfileSynced(root, { dryRun: true, install: true })
53
+ return {
54
+ synced: true,
55
+ dryRun: true,
56
+ declared,
57
+ current,
58
+ targetVersion,
59
+ lockPreview,
60
+ }
52
61
  }
53
62
 
54
63
  const packageManager = resolveProjectPackageManager(root)
@@ -63,5 +72,7 @@ export function syncCoreDependency(root, targetVersion, { dryRun = false } = {})
63
72
  }
64
73
  }
65
74
 
66
- return { synced: true, declared, current, targetVersion }
75
+ const lock = ensureLockfileSynced(root, { install: true })
76
+
77
+ return { synced: true, declared, current, targetVersion, lock }
67
78
  }
@@ -9,6 +9,7 @@ import { syncCoreDependency } from './sync-core-dependency.mjs'
9
9
  import { syncProjectToolchain } from './toolchain-config.mjs'
10
10
  import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
11
11
  import { packageDefaults } from './package-defaults.mjs'
12
+ import { ensureLockfileSynced } from './ensure-lockfile.mjs'
12
13
 
13
14
  export function syncOneProject(entry, coreVersion, {
14
15
  dryRun = false,
@@ -25,11 +26,23 @@ export function syncOneProject(entry, coreVersion, {
25
26
  const core = syncCoreDependency(entry.path, coreVersion, { dryRun: true })
26
27
  if (core.synced) {
27
28
  lines.push({ level: 'gray', text: `would pin ${packageDefaults.packageName}@${coreVersion} (from ${core.current ?? core.declared})` })
29
+ if (core.lockPreview?.dryRun && !core.lockPreview.synced) {
30
+ lines.push({
31
+ level: 'gray',
32
+ text: `would refresh lockfile (${core.lockPreview.packageManager}: ${core.lockPreview.reason})`,
33
+ })
34
+ }
28
35
  } else if (core.reason === 'up-to-date') {
29
36
  lines.push({ level: 'gray', text: `${packageDefaults.packageName}@${coreVersion} (ok)` })
30
37
  } else if (core.reason === 'no core dependency') {
31
38
  lines.push({ level: 'yellow', text: `skip core pin (${core.reason})` })
32
39
  }
40
+ const lockDry = ensureLockfileSynced(entry.path, { dryRun: true })
41
+ if (lockDry.dryRun) {
42
+ lines.push({ level: 'gray', text: `would refresh ${lockDry.lockfiles.join(', ') || 'lockfile'} (${lockDry.reason})` })
43
+ } else if (lockDry.lockfiles.length) {
44
+ lines.push({ level: 'gray', text: `${lockDry.lockfiles.join(', ')} aligned with package.json` })
45
+ }
33
46
  if (tmpWouldCreate && tmpPath) {
34
47
  lines.push({ level: 'gray', text: `would create ${path.relative(entry.path, tmpPath) || tmpPath}` })
35
48
  }
@@ -49,12 +62,22 @@ export function syncOneProject(entry, coreVersion, {
49
62
  const core = syncCoreDependency(entry.path, coreVersion, { dryRun: false })
50
63
  if (core.synced) {
51
64
  lines.push({ level: 'green', text: `pinned ${packageDefaults.packageName}@${coreVersion}` })
65
+ if (core.lock?.changed) {
66
+ lines.push({ level: 'green', text: `lockfile aligned (${core.lock.packageManager})` })
67
+ }
52
68
  } else if (core.reason === 'up-to-date') {
53
69
  lines.push({ level: 'gray', text: `${packageDefaults.packageName}@${coreVersion} (ok)` })
54
70
  } else if (core.reason === 'no core dependency') {
55
71
  lines.push({ level: 'yellow', text: `skip core pin (${core.reason})` })
56
72
  }
57
73
 
74
+ const lock = ensureLockfileSynced(entry.path)
75
+ if (lock.changed && lock.lockfiles.length) {
76
+ lines.push({ level: 'green', text: `refreshed ${lock.lockfiles.join(', ')}` })
77
+ } else if (lock.lockfiles.length) {
78
+ lines.push({ level: 'gray', text: `${lock.lockfiles.join(', ')} aligned` })
79
+ }
80
+
58
81
  if (tmpCreated && tmpPath) {
59
82
  lines.push({ level: 'green', text: `created ${path.relative(entry.path, tmpPath) || tmpPath}` })
60
83
  }
@@ -1,5 +1,10 @@
1
1
  import { execSync } from 'node:child_process'
2
2
  import { getVersionState, readDiskPackageJson, run } from './version-check.mjs'
3
+ import {
4
+ assertLockfileCommitted,
5
+ ensureLockfileSynced,
6
+ probeLockfileAlignment,
7
+ } from '../helpers/ensure-lockfile.mjs'
3
8
 
4
9
  const CALVER_RELEASE = /^(\d{2})\.(\d{2})\.(\d{2})$/
5
10
  const CALVER_DEV = /^(\d{2})\.(\d{2})\.(\d{2})-dev-p(\d+)$/
@@ -107,6 +112,17 @@ export function runCalverTagPush({ root, dryRun = false } = {}) {
107
112
  const state = getVersionState('HEAD', root)
108
113
  const version = state.committed.version
109
114
 
115
+ const lockProbe = probeLockfileAlignment(root)
116
+ if (lockProbe.reason !== 'no package.json' && lockProbe.reason !== 'no lockfile') {
117
+ if (!lockProbe.aligned) {
118
+ if (dryRun) {
119
+ console.warn(`⚠ Lockfile drift (${lockProbe.packageManager}): ${lockProbe.reason}`)
120
+ } else {
121
+ ensureLockfileSynced(root, { install: false })
122
+ }
123
+ }
124
+ }
125
+
110
126
  if (!state.isPackageJsonClean) {
111
127
  throw new Error('package.json uncommitted — run `xry version patch` (or commit the bump) before tagging.')
112
128
  }
@@ -114,6 +130,8 @@ export function runCalverTagPush({ root, dryRun = false } = {}) {
114
130
  throw new Error('package.json on disk does not match HEAD — run `xry version patch` (or commit) first.')
115
131
  }
116
132
 
133
+ assertLockfileCommitted(root, (cmd, opts) => run(cmd, opts))
134
+
117
135
  const tagName = gitTagFromCalver(version)
118
136
  if (gitTagExists(tagName, root)) {
119
137
  throw new Error(`Tag ${tagName} already exists.`)
@@ -10,6 +10,7 @@ import { fileURLToPath } from 'node:url'
10
10
  import { parseSemver, getVersionState, readDiskPackageJson, run } from './version-check.mjs'
11
11
  import { bumpCalverPatch, gitTagFromCalver, detectCalverEnv } from './calver.mjs'
12
12
  import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
13
+ import { ensureLockfileSynced, presentLockfiles } from '../helpers/ensure-lockfile.mjs'
13
14
 
14
15
  /** @returns {'semver'|'calver'} */
15
16
  export function resolveReleaseMode(root) {
@@ -64,14 +65,18 @@ export function commitPackageJsonBump(root, version, { isCore } = {}) {
64
65
  const core = isCore ?? isCorePackageProject(root)
65
66
  const message = bumpCommitMessage(version, { isCore: core })
66
67
 
67
- run('git add -- package.json', { root })
68
- const staged = run('git diff --cached --name-only -- package.json', { root })
68
+ ensureLockfileSynced(root, { install: true })
69
+
70
+ const lockfiles = presentLockfiles(root)
71
+ const commitPaths = ['package.json', ...lockfiles]
72
+ run(`git add -- ${commitPaths.join(' ')}`, { root })
73
+ const staged = run('git diff --cached --name-only', { root })
69
74
  if (!staged.trim()) {
70
75
  throw new Error('Nothing to commit: package.json has no staged changes after bump.')
71
76
  }
72
77
 
73
78
  try {
74
- execFileSync('git', ['commit', '-m', message, '--', 'package.json'], {
79
+ execFileSync('git', ['commit', '-m', message, '--', ...commitPaths], {
75
80
  cwd: root,
76
81
  stdio: 'inherit',
77
82
  encoding: 'utf8',
@@ -5,6 +5,11 @@ import { fileURLToPath } from 'node:url'
5
5
  import { resolveProjectRoot } from '../helpers/project-root.mjs'
6
6
  import { semverVersionPattern } from '../paths.mjs'
7
7
  import { runReleasePrepare } from './release-prepare.mjs'
8
+ import {
9
+ assertLockfileCommitted,
10
+ ensureLockfileSynced,
11
+ probeLockfileAlignment,
12
+ } from '../helpers/ensure-lockfile.mjs'
8
13
 
9
14
  export const VERSION_PATTERN = semverVersionPattern
10
15
 
@@ -355,7 +360,25 @@ export function resolveTagState(version, ref = 'HEAD', root = getProjectRoot())
355
360
  }
356
361
  }
357
362
 
358
- export function assertReadyToTag({ requireClean = false, root = getProjectRoot() } = {}) {
363
+ function assertLockfileForRelease(root, { dryRun = false } = {}) {
364
+ const probe = probeLockfileAlignment(root)
365
+ if (probe.reason === 'no package.json' || probe.reason === 'no lockfile') {
366
+ return probe
367
+ }
368
+ if (probe.aligned) {
369
+ return probe
370
+ }
371
+ if (dryRun) {
372
+ console.warn(`⚠ Lockfile drift (${probe.packageManager}): ${probe.reason}`)
373
+ return probe
374
+ }
375
+ ensureLockfileSynced(root, { install: false })
376
+ return probe
377
+ }
378
+
379
+ export function assertReadyToTag({ requireClean = false, root = getProjectRoot(), dryRun = false } = {}) {
380
+ assertLockfileForRelease(root, { dryRun })
381
+
359
382
  const state = getVersionState('HEAD', root)
360
383
  const version = state.committed.version
361
384
 
@@ -375,6 +398,8 @@ export function assertReadyToTag({ requireClean = false, root = getProjectRoot()
375
398
  )
376
399
  }
377
400
 
401
+ assertLockfileCommitted(root, (cmd, opts) => run(cmd, opts))
402
+
378
403
  assertVersionFormat(version)
379
404
  assertCommitPackageVersionAlign(version, root)
380
405
 
@@ -413,11 +438,11 @@ export async function runTagRelease({
413
438
  skipPrepare = false,
414
439
  root = getProjectRoot(),
415
440
  } = {}) {
416
- assertReadyToTag({ requireClean, root })
441
+ assertReadyToTag({ requireClean, root, dryRun })
417
442
 
418
443
  runReleasePrepare({ root, dryRun, skipPrepare })
419
444
 
420
- const state = assertReadyToTag({ requireClean, root })
445
+ const state = assertReadyToTag({ requireClean, root, dryRun })
421
446
  const { version, branch, headCommit, tag } = state
422
447
  const shortCommit = headCommit.slice(0, 7)
423
448