Skip to content

Commit 1786fbe

Browse files
committed
fix: ensure that app and ts version strings are loaded
1 parent 85c9f87 commit 1786fbe

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

packages/core/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@h3ravel/core",
3-
"version": "1.9.3",
3+
"version": "1.9.4",
44
"description": "Core application container, lifecycle management and service providers for H3ravel.",
55
"type": "module",
66
"main": "./dist/index.js",
@@ -61,10 +61,12 @@
6161
"edge.js": "^6.3.0",
6262
"h3": "2.0.0-beta.4",
6363
"reflect-metadata": "^0.2.2",
64+
"semver": "^7.7.2",
6465
"srvx": "^0.8.7",
6566
"tslib": "^2.8.1"
6667
},
6768
"devDependencies": {
69+
"@types/semver": "^7.7.1",
6870
"typescript": "^5.9.2"
6971
}
7072
}

packages/core/src/Application.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'reflect-metadata'
22

3-
import { IApplication, IPathName, IServiceProvider, Logger } from '@h3ravel/shared'
3+
import { FileSystem, IApplication, IPathName, IServiceProvider, Logger } from '@h3ravel/shared'
44

55
import { Container } from './Container'
66
import { ContainerResolver } from './Di/ContainerResolver'
@@ -12,14 +12,16 @@ import { detect } from 'detect-port'
1212
import dotenv from 'dotenv'
1313
import dotenvExpand from 'dotenv-expand'
1414
import path from 'node:path'
15+
import { readFile } from 'node:fs/promises'
16+
import semver from 'semver'
1517

1618
type AServiceProvider = (new (_app: Application) => IServiceProvider) & IServiceProvider
1719

1820
export class Application extends Container implements IApplication {
1921
public paths = new PathLoader()
2022
private tries: number = 0
2123
private booted = false
22-
private versions = { app: '0', ts: '0' }
24+
private versions = { app: '0.0.0', ts: '0.0.0' }
2325
private basePath: string
2426

2527
private providers: IServiceProvider[] = []
@@ -65,15 +67,18 @@ export class Application extends Container implements IApplication {
6567
}
6668

6769
protected async loadOptions () {
68-
const app = await this.safeImport(this.getPath('base', 'package.json'))
69-
const core = await this.safeImport('../package.json')
70+
try {
71+
const corePath = FileSystem.findModulePkg('@h3ravel/core', process.cwd()) ?? ''
72+
const app = JSON.parse(await readFile(path.join(process.cwd(), '/package.json'), { encoding: 'utf8' }))
73+
const core = JSON.parse(await readFile(path.join(corePath, 'package.json'), { encoding: 'utf8' }))
7074

71-
if (app && app.dependencies) {
72-
this.versions.app = app.dependencies['@h3ravel/core']
73-
}
74-
if (core && core.devDependencies) {
75-
this.versions.ts = app.devDependencies.typescript
76-
}
75+
if (app) {
76+
this.versions.app = semver.minVersion(app.version)?.version ?? this.versions.app
77+
}
78+
if (core && core.devDependencies) {
79+
this.versions.ts = semver.minVersion(app.devDependencies.typescript)?.version ?? this.versions.ts
80+
}
81+
} catch { /** */ }//
7782
}
7883

7984
/**

pnpm-lock.yaml

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)