@wyxos/zephyr 0.9.0 → 0.9.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wyxos/zephyr",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "A streamlined deployment tool for web applications with intelligent Laravel project detection",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -1,6 +1,8 @@
1
1
  import fs from 'node:fs/promises'
2
2
  import path from 'node:path'
3
3
 
4
+ import semver from 'semver'
5
+
4
6
  import {commandExists} from '../../utils/command.mjs'
5
7
  import {gitCommitArgs} from '../../utils/git-hooks.mjs'
6
8
  import {resolveReleaseType} from '../../release/release-type.mjs'
@@ -20,28 +22,79 @@ async function isGitIgnored(rootDir, filePath, {runCommand} = {}) {
20
22
  }
21
23
  }
22
24
 
23
- async function readLatestVersionBumpCommit(rootDir, {runCommand} = {}) {
24
- if (typeof runCommand !== 'function') {
25
+ function parseVersionBumpCommit(line) {
26
+ const [hash, shortHash, subject] = line.split('\0')
27
+ const match = /^chore: bump version to (\d+\.\d+\.\d+(?:[-+][^\s]+)?)$/i.exec(subject ?? '')
28
+
29
+ if (!match) {
25
30
  return null
26
31
  }
27
32
 
33
+ return {hash, shortHash, version: match[1]}
34
+ }
35
+
36
+ async function readVersionBumpCommits(rootDir, {runCommand} = {}) {
37
+ if (typeof runCommand !== 'function') {
38
+ return []
39
+ }
40
+
28
41
  try {
29
- const {stdout = ''} = await runCommand('git', ['log', '--format=%H%x00%h%x00%s', '-50'], {
42
+ const {stdout = ''} = await runCommand('git', ['log', '--format=%H%x00%h%x00%s', '-1000'], {
30
43
  capture: true,
31
44
  cwd: rootDir
32
45
  })
33
46
 
34
- for (const line of stdout.split('\n')) {
35
- const [hash, shortHash, subject] = line.split('\0')
36
- if (/^chore: bump version to \d+\.\d+\.\d+(?:[-+].*)?$/i.test(subject ?? '')) {
37
- return {hash, shortHash}
38
- }
39
- }
47
+ return stdout
48
+ .split('\n')
49
+ .map(parseVersionBumpCommit)
50
+ .filter(Boolean)
40
51
  } catch {
52
+ return []
53
+ }
54
+ }
55
+
56
+ function selectVersionSuggestionReference(currentVersion, versionBumps) {
57
+ const current = semver.parse(currentVersion)
58
+
59
+ if (!current) {
60
+ return versionBumps[0] ?? null
61
+ }
62
+
63
+ let earliestKnownCurrentMinor = null
64
+ const currentMinorBoundary = versionBumps.find((versionBump) => {
65
+ const parsed = semver.parse(versionBump.version)
66
+ const isCurrentMinor = parsed
67
+ && parsed.major === current.major
68
+ && parsed.minor === current.minor
69
+ && parsed.prerelease.length === 0
70
+
71
+ if (isCurrentMinor) {
72
+ earliestKnownCurrentMinor = versionBump
73
+ }
74
+
75
+ return isCurrentMinor && parsed.patch === 0
76
+ })
77
+
78
+ return currentMinorBoundary ?? earliestKnownCurrentMinor ?? versionBumps[0] ?? null
79
+ }
80
+
81
+ function formatVersionReferenceLabel(reference, currentVersion) {
82
+ if (!reference) {
41
83
  return null
42
84
  }
43
85
 
44
- return null
86
+ const current = semver.parse(currentVersion)
87
+ const parsed = semver.parse(reference.version)
88
+ const isCurrentMinor = current
89
+ && parsed
90
+ && parsed.major === current.major
91
+ && parsed.minor === current.minor
92
+ && parsed.prerelease.length === 0
93
+ const prefix = isCurrentMinor
94
+ ? parsed.patch === 0 ? 'current app minor baseline' : 'earliest known app minor baseline'
95
+ : 'last app version bump'
96
+
97
+ return `${prefix} ${reference.shortHash} (${reference.version})`
45
98
  }
46
99
 
47
100
  async function resolveDeploymentVersionValue(rootDir, {
@@ -57,7 +110,8 @@ async function resolveDeploymentVersionValue(rootDir, {
57
110
  return String(versionArg).trim()
58
111
  }
59
112
 
60
- const latestVersionBump = await readLatestVersionBumpCommit(rootDir, {runCommand})
113
+ const versionBumps = await readVersionBumpCommits(rootDir, {runCommand})
114
+ const versionReference = selectVersionSuggestionReference(pkg.version, versionBumps)
61
115
 
62
116
  return await resolveReleaseType({
63
117
  currentVersion: pkg.version,
@@ -68,8 +122,8 @@ async function resolveDeploymentVersionValue(rootDir, {
68
122
  runCommand,
69
123
  logStep: logProcessing,
70
124
  logWarning,
71
- latestTag: latestVersionBump?.hash ?? null,
72
- referenceLabel: latestVersionBump ? `last app version bump ${latestVersionBump.shortHash}` : null
125
+ latestTag: versionReference?.hash ?? null,
126
+ referenceLabel: formatVersionReferenceLabel(versionReference, pkg.version)
73
127
  })
74
128
  }
75
129