@@ -11,16 +11,18 @@ import pluralize from 'pluralize'
1111import * as changeCase from 'change-case'
1212
1313import { crc32 } from 'crc'
14+ import { debug } from '#src/debug'
15+ import { Path } from '#src/helpers/Path'
1416import { Module } from '#src/helpers/Module'
1517import { Options } from '#src/helpers/Options'
1618import { Macroable } from '#src/helpers/Macroable'
1719import { createHmac , randomBytes } from 'node:crypto'
1820import { OrdinalNanException } from '#src/exceptions/OrdinalNanException'
1921import { NotFoundAthennaConfig } from '#src/exceptions/NotFoundAthennaConfig'
2022
21- const config = await Module . safeImport ( '@athenna/config' )
22-
2323export class String extends Macroable {
24+ public static config : any
25+
2426 /**
2527 * Generate hash for a given value.
2628 *
@@ -34,11 +36,21 @@ export class String extends Macroable {
3436 value : string ,
3537 options : { key ?: string ; prefix ?: string } = { }
3638 ) {
37- if ( ! options . key && ! config ) {
39+ if ( ! this . config ) {
40+ const require = Module . createRequire ( Path . pwd ( ) )
41+
42+ try {
43+ this . config = require ( '@athenna/config' )
44+ } catch ( _err ) {
45+ debug ( '@athenna/config not found to run String.hash()' )
46+ }
47+ }
48+
49+ if ( ! options . key && ! this . config ) {
3850 throw new NotFoundAthennaConfig ( )
3951 }
4052
41- options . key = options . key || config . Config . get ( 'app.key' )
53+ options . key = options . key || this . config . Config . get ( 'app.key' )
4254
4355 const hash = createHmac ( 'sha256' , options . key ) . update ( value ) . digest ( 'hex' )
4456
0 commit comments