@innertia-solutions/innertia-nuxt 0.1.78 → 0.1.79

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.
@@ -42,4 +42,19 @@ describe('collectBuildVersion', () => {
42
42
  expect(v.commit).toBe('')
43
43
  expect(Number.isNaN(Date.parse(v.buildDate))).toBe(false)
44
44
  })
45
+
46
+ it('sin APP_VERSION ni build-info usa VERSION del monorepo (../VERSION) como vX.Y.Z-dev', () => {
47
+ const front = join(root, 'frontend')
48
+ pkg(front, { name: 'acme-front', version: '9.9.9' })
49
+ writeFileSync(join(root, 'VERSION'), '1.0.2\n')
50
+ expect(collectBuildVersion(front, {}, { git: false, packages: [] }).version).toBe('v1.0.2-dev')
51
+ })
52
+
53
+ it('APP_VERSION tiene precedencia sobre VERSION', () => {
54
+ const front = join(root, 'frontend')
55
+ pkg(front, { name: 'acme-front' })
56
+ writeFileSync(join(root, 'VERSION'), '1.0.2\n')
57
+ expect(collectBuildVersion(front, { APP_VERSION: 'v1.0.2-20261111.3' }, { git: false, packages: [] }).version)
58
+ .toBe('v1.0.2-20261111.3')
59
+ })
45
60
  })
package/build/version.ts CHANGED
@@ -51,6 +51,17 @@ function gitCommit(rootDir: string): string {
51
51
  }
52
52
  }
53
53
 
54
+ /** Dev local: VERSION en la raíz del monorepo (padre del front) → "vX.Y.Z-dev". */
55
+ function devVersion(rootDir: string): string {
56
+ try {
57
+ const path = join(rootDir, '..', 'VERSION')
58
+ const semver = existsSync(path) ? readFileSync(path, 'utf8').trim() : ''
59
+ return /^\d+\.\d+\.\d+$/.test(semver) ? `v${semver}-dev` : ''
60
+ } catch {
61
+ return ''
62
+ }
63
+ }
64
+
54
65
  /**
55
66
  * Prioridad por campo: env de build (APP_COMMIT / APP_BUILD_DATE / APP_VERSION)
56
67
  * → build-info.json en rootDir (lo escribe el Dockerfile) → fallback
@@ -67,7 +78,7 @@ export function collectBuildVersion(
67
78
 
68
79
  return {
69
80
  app: str(product.name),
70
- version: str(env.APP_VERSION) || str(info.version) || str(product.version),
81
+ version: str(env.APP_VERSION) || str(info.version) || devVersion(rootDir) || str(product.version),
71
82
  commit: str(env.APP_COMMIT) || str(info.commit) || (opts.git === false ? '' : gitCommit(rootDir)),
72
83
  buildDate: str(env.APP_BUILD_DATE) || str(info.build_date) || new Date().toISOString(),
73
84
  packages: readPackageVersions(rootDir, opts.packages ?? DEFAULT_FRONT_PACKAGES),
@@ -0,0 +1,50 @@
1
+ <script setup>
2
+ /**
3
+ * <AppVersionBadge /> — versión desplegada del front, visible en shells y login.
4
+ * Lee /_version (público). Muestra "v1.0.2 · QA #7"; tooltip con versión completa,
5
+ * commit y fecha de build. Con `to`, enlaza al detalle (p. ej. la página con <AppVersions />).
6
+ *
7
+ * ```vue
8
+ * <AppVersionBadge />
9
+ * <AppVersionBadge to="/platform" />
10
+ * ```
11
+ */
12
+ import { NuxtLink } from '#components'
13
+ import { parseVersion, versionLabel } from '../../utils/version-string'
14
+
15
+ const props = defineProps({
16
+ endpoint: { type: String, default: '/_version' },
17
+ to: { type: String, default: '' },
18
+ })
19
+
20
+ const { data } = useFetch(props.endpoint, { server: false, key: `innertia-version-badge:${props.endpoint}` })
21
+
22
+ const parts = computed(() => parseVersion(data.value?.version))
23
+ const label = computed(() => versionLabel(data.value?.version))
24
+ const title = computed(() => {
25
+ const d = data.value
26
+ if (!d) return ''
27
+ const date = d.build_date ? new Date(d.build_date) : null
28
+ return [
29
+ d.version,
30
+ d.commit ? `commit ${d.commit}` : null,
31
+ date && !Number.isNaN(date.getTime()) ? date.toLocaleString() : null,
32
+ ].filter(Boolean).join(' · ')
33
+ })
34
+ const tone = computed(() => parts.value?.environment === 'qa'
35
+ ? 'text-amber-600 dark:text-amber-400'
36
+ : 'text-muted-foreground')
37
+ </script>
38
+
39
+ <template>
40
+ <component
41
+ :is="to ? NuxtLink : 'span'"
42
+ v-if="label"
43
+ :to="to || undefined"
44
+ :title="title"
45
+ class="inline-flex items-center font-mono text-[11px] leading-none hover:text-foreground"
46
+ :class="tone"
47
+ >
48
+ {{ label }}
49
+ </component>
50
+ </template>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innertia-solutions/innertia-nuxt",
3
- "version": "0.1.78",
3
+ "version": "0.1.79",
4
4
  "description": "Innertia Solutions — Nuxt layer unificada: core, auth, multitenancy, theme y app contexts",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -0,0 +1,36 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { parseVersion, versionLabel } from '../version-string'
3
+
4
+ describe('parseVersion', () => {
5
+ it('prod', () => {
6
+ expect(parseVersion('v1.0.2-20261111.2')).toEqual({
7
+ raw: 'v1.0.2-20261111.2', semver: '1.0.2', date: '2026-11-11', environment: 'production', sequence: 2,
8
+ })
9
+ })
10
+ it('QA', () => {
11
+ expect(parseVersion('v1.0.2-20261111-QA.7')).toEqual({
12
+ raw: 'v1.0.2-20261111-QA.7', semver: '1.0.2', date: '2026-11-11', environment: 'qa', sequence: 7,
13
+ })
14
+ })
15
+ it('dev', () => {
16
+ expect(parseVersion('v1.0.2-dev')).toEqual({
17
+ raw: 'v1.0.2-dev', semver: '1.0.2', date: null, environment: 'dev', sequence: null,
18
+ })
19
+ })
20
+ it.each([null, undefined, '', '1.0.2', 'v.1.0.2-20261111.2', 'v1.0.2-20261111', 'v1.0.2-20261111-qa.1'])(
21
+ 'null si no calza: %s', (raw) => {
22
+ expect(parseVersion(raw as any)).toBeNull()
23
+ })
24
+ })
25
+
26
+ describe('versionLabel', () => {
27
+ it('formatea prod, QA y dev', () => {
28
+ expect(versionLabel('v1.0.2-20261111.2')).toBe('v1.0.2 · #2')
29
+ expect(versionLabel('v1.0.2-20261111-QA.7')).toBe('v1.0.2 · QA #7')
30
+ expect(versionLabel('v1.0.2-dev')).toBe('v1.0.2 · dev')
31
+ })
32
+ it('devuelve el string crudo si no calza, vacío si no hay', () => {
33
+ expect(versionLabel('1.4.0')).toBe('1.4.0')
34
+ expect(versionLabel(null)).toBe('')
35
+ })
36
+ })
@@ -0,0 +1,34 @@
1
+ // Formato estándar de versión de despliegue (espejo de Innertia\Version\VersionString):
2
+ // prod v1.0.2-20261111.2 · QA v1.0.2-20261111-QA.7 · dev v1.0.2-dev
3
+
4
+ export interface VersionParts {
5
+ raw: string
6
+ semver: string
7
+ date: string | null
8
+ environment: 'production' | 'qa' | 'dev'
9
+ sequence: number | null
10
+ }
11
+
12
+ const PATTERN = /^v(\d+\.\d+\.\d+)-(?:(\d{8})(?:-(QA))?\.(\d+)|(dev))$/
13
+
14
+ export function parseVersion(raw?: string | null): VersionParts | null {
15
+ const value = (raw ?? '').trim()
16
+ const m = PATTERN.exec(value)
17
+ if (!m) return null
18
+ if (m[5] === 'dev') return { raw: value, semver: m[1], date: null, environment: 'dev', sequence: null }
19
+ return {
20
+ raw: value,
21
+ semver: m[1],
22
+ date: `${m[2].slice(0, 4)}-${m[2].slice(4, 6)}-${m[2].slice(6, 8)}`,
23
+ environment: m[3] === 'QA' ? 'qa' : 'production',
24
+ sequence: Number(m[4]),
25
+ }
26
+ }
27
+
28
+ /** Etiqueta corta para UI: "v1.0.2 · QA #7" | "v1.0.2 · #2" | "v1.0.2 · dev" | crudo. */
29
+ export function versionLabel(raw?: string | null): string {
30
+ const p = parseVersion(raw)
31
+ if (!p) return (raw ?? '').trim()
32
+ if (p.environment === 'dev') return `v${p.semver} · dev`
33
+ return `v${p.semver} · ${p.environment === 'qa' ? 'QA ' : ''}#${p.sequence}`
34
+ }