@xrystal/core 3.55.90 → 3.55.93
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 +2 -2
- package/package.json +1 -1
- package/x/bin/helpers/ensure-lockfile.mjs +149 -0
- package/x/bin/helpers/sync-core-dependency.mjs +13 -2
- package/x/bin/helpers/sync-project.mjs +23 -0
- package/x/bin/scripts/calver.mjs +18 -0
- package/x/bin/scripts/release-bump.mjs +8 -3
- package/x/bin/scripts/version-check.mjs +86 -8
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
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
}
|
package/x/bin/scripts/calver.mjs
CHANGED
|
@@ -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
|
-
|
|
68
|
-
|
|
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, '--',
|
|
79
|
+
execFileSync('git', ['commit', '-m', message, '--', ...commitPaths], {
|
|
75
80
|
cwd: root,
|
|
76
81
|
stdio: 'inherit',
|
|
77
82
|
encoding: 'utf8',
|
|
@@ -4,7 +4,12 @@ import path from 'node:path'
|
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
import { resolveProjectRoot } from '../helpers/project-root.mjs'
|
|
6
6
|
import { semverVersionPattern } from '../paths.mjs'
|
|
7
|
-
import { runReleasePrepare } from './release-prepare.mjs'
|
|
7
|
+
import { isCorePackageProject, 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
|
|
|
@@ -118,6 +123,53 @@ export function getLatestTagVersion(root = getProjectRoot()) {
|
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
125
|
|
|
126
|
+
const CALVER_DEV = /^(\d{2})\.(\d{2})\.(\d{2})-dev-p(\d+)$/
|
|
127
|
+
const CALVER_STAG = /^(\d{2})\.(\d{2})\.(\d{2})-stag-p(\d+)$/
|
|
128
|
+
const CALVER_PROD_PATCH = /^(\d{2})\.(\d{2})\.(\d{2})-p(\d+)$/
|
|
129
|
+
const CALVER_RELEASE = /^(\d{2})\.(\d{2})\.(\d{2})$/
|
|
130
|
+
|
|
131
|
+
function detectCalverLane(version) {
|
|
132
|
+
const v = String(version ?? '').trim()
|
|
133
|
+
if (CALVER_DEV.test(v)) return 'dev'
|
|
134
|
+
if (CALVER_STAG.test(v)) return 'stag'
|
|
135
|
+
if (CALVER_PROD_PATCH.test(v) || CALVER_RELEASE.test(v)) return 'prod'
|
|
136
|
+
return null
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function resolveCalverLaneFromBranch(root) {
|
|
140
|
+
const branch = run('git rev-parse --abbrev-ref HEAD', { root })
|
|
141
|
+
if (branch === 'dev') return 'dev'
|
|
142
|
+
if (branch === 'staging') return 'stag'
|
|
143
|
+
if (branch === 'prod') return 'prod'
|
|
144
|
+
return null
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Latest git tag for current CalVer lane (dev / stag / prod) — not cross-env. */
|
|
148
|
+
export function getLatestCalverTagForLane(root = getProjectRoot(), lane = resolveCalverLaneFromBranch(root)) {
|
|
149
|
+
if (!lane) return null
|
|
150
|
+
try {
|
|
151
|
+
const tags = run('git tag -l "v*" --sort=-v:refname', { root })
|
|
152
|
+
.split('\n')
|
|
153
|
+
.map((tag) => tag.trim())
|
|
154
|
+
.filter(Boolean)
|
|
155
|
+
for (const tag of tags) {
|
|
156
|
+
const version = tag.replace(/^v/, '')
|
|
157
|
+
if (detectCalverLane(version) === lane) return version
|
|
158
|
+
}
|
|
159
|
+
return null
|
|
160
|
+
} catch {
|
|
161
|
+
return null
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function resolveServiceLatestTag(root) {
|
|
166
|
+
if (isCorePackageProject(root)) return getLatestTagVersion(root)
|
|
167
|
+
const lane = resolveCalverLaneFromBranch(root)
|
|
168
|
+
const headVersion = readPackageJsonVersionAtRef('HEAD', root)
|
|
169
|
+
if (!lane && !detectCalverLane(headVersion)) return getLatestTagVersion(root)
|
|
170
|
+
return getLatestCalverTagForLane(root, lane) ?? getLatestTagVersion(root)
|
|
171
|
+
}
|
|
172
|
+
|
|
121
173
|
export function pickHigherSemver(a, b) {
|
|
122
174
|
if (!a) return b ?? null
|
|
123
175
|
if (!b) return a
|
|
@@ -176,10 +228,13 @@ export function assertCommitPackageVersionAlign(version, root = getProjectRoot()
|
|
|
176
228
|
}
|
|
177
229
|
|
|
178
230
|
export function resolveVersionBaseline(root = getProjectRoot()) {
|
|
179
|
-
const latestTag =
|
|
231
|
+
const latestTag = resolveServiceLatestTag(root)
|
|
180
232
|
const headVersion = readPackageJsonVersionAtRef('HEAD', root)
|
|
181
233
|
const parentVersion = readPackageJsonVersionAtRef('HEAD~1', root)
|
|
182
|
-
const
|
|
234
|
+
const calverLane = !isCorePackageProject(root) && resolveCalverLaneFromBranch(root)
|
|
235
|
+
const baselineVersion = calverLane
|
|
236
|
+
? pickHigherSemver(latestTag, headVersion)
|
|
237
|
+
: pickHigherSemver(latestTag, parentVersion)
|
|
183
238
|
|
|
184
239
|
let baselineLabel = 'first release'
|
|
185
240
|
if (latestTag && parentVersion) {
|
|
@@ -197,9 +252,12 @@ export function resolveVersionBaseline(root = getProjectRoot()) {
|
|
|
197
252
|
|
|
198
253
|
export function resolveStagedVersionBaseline(root = getProjectRoot()) {
|
|
199
254
|
const headVersion = readPackageJsonVersionAtRef('HEAD', root)
|
|
200
|
-
const latestTag =
|
|
255
|
+
const latestTag = resolveServiceLatestTag(root)
|
|
201
256
|
const parentVersion = readPackageJsonVersionAtRef('HEAD~1', root)
|
|
202
|
-
const
|
|
257
|
+
const calverLane = !isCorePackageProject(root) && resolveCalverLaneFromBranch(root)
|
|
258
|
+
const baselineVersion = calverLane
|
|
259
|
+
? pickHigherSemver(latestTag, headVersion)
|
|
260
|
+
: pickHigherSemver(pickHigherSemver(latestTag, headVersion), parentVersion)
|
|
203
261
|
|
|
204
262
|
let baselineLabel = 'version floor'
|
|
205
263
|
if (baselineVersion === latestTag) baselineLabel = `latest tag v${latestTag}`
|
|
@@ -355,7 +413,25 @@ export function resolveTagState(version, ref = 'HEAD', root = getProjectRoot())
|
|
|
355
413
|
}
|
|
356
414
|
}
|
|
357
415
|
|
|
358
|
-
|
|
416
|
+
function assertLockfileForRelease(root, { dryRun = false } = {}) {
|
|
417
|
+
const probe = probeLockfileAlignment(root)
|
|
418
|
+
if (probe.reason === 'no package.json' || probe.reason === 'no lockfile') {
|
|
419
|
+
return probe
|
|
420
|
+
}
|
|
421
|
+
if (probe.aligned) {
|
|
422
|
+
return probe
|
|
423
|
+
}
|
|
424
|
+
if (dryRun) {
|
|
425
|
+
console.warn(`⚠ Lockfile drift (${probe.packageManager}): ${probe.reason}`)
|
|
426
|
+
return probe
|
|
427
|
+
}
|
|
428
|
+
ensureLockfileSynced(root, { install: false })
|
|
429
|
+
return probe
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export function assertReadyToTag({ requireClean = false, root = getProjectRoot(), dryRun = false } = {}) {
|
|
433
|
+
assertLockfileForRelease(root, { dryRun })
|
|
434
|
+
|
|
359
435
|
const state = getVersionState('HEAD', root)
|
|
360
436
|
const version = state.committed.version
|
|
361
437
|
|
|
@@ -375,6 +451,8 @@ export function assertReadyToTag({ requireClean = false, root = getProjectRoot()
|
|
|
375
451
|
)
|
|
376
452
|
}
|
|
377
453
|
|
|
454
|
+
assertLockfileCommitted(root, (cmd, opts) => run(cmd, opts))
|
|
455
|
+
|
|
378
456
|
assertVersionFormat(version)
|
|
379
457
|
assertCommitPackageVersionAlign(version, root)
|
|
380
458
|
|
|
@@ -413,11 +491,11 @@ export async function runTagRelease({
|
|
|
413
491
|
skipPrepare = false,
|
|
414
492
|
root = getProjectRoot(),
|
|
415
493
|
} = {}) {
|
|
416
|
-
assertReadyToTag({ requireClean, root })
|
|
494
|
+
assertReadyToTag({ requireClean, root, dryRun })
|
|
417
495
|
|
|
418
496
|
runReleasePrepare({ root, dryRun, skipPrepare })
|
|
419
497
|
|
|
420
|
-
const state = assertReadyToTag({ requireClean, root })
|
|
498
|
+
const state = assertReadyToTag({ requireClean, root, dryRun })
|
|
421
499
|
const { version, branch, headCommit, tag } = state
|
|
422
500
|
const shortCommit = headCommit.slice(0, 7)
|
|
423
501
|
|