11import 'reflect-metadata'
22
3- import { IApplication , IPathName , IServiceProvider , Logger } from '@h3ravel/shared'
3+ import { FileSystem , IApplication , IPathName , IServiceProvider , Logger } from '@h3ravel/shared'
44
55import { Container } from './Container'
66import { ContainerResolver } from './Di/ContainerResolver'
@@ -12,14 +12,16 @@ import { detect } from 'detect-port'
1212import dotenv from 'dotenv'
1313import dotenvExpand from 'dotenv-expand'
1414import path from 'node:path'
15+ import { readFile } from 'node:fs/promises'
16+ import semver from 'semver'
1517
1618type AServiceProvider = ( new ( _app : Application ) => IServiceProvider ) & IServiceProvider
1719
1820export 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 /**
0 commit comments