Skip to content

Commit 252c3e9

Browse files
authored
Merge pull request #144 from AthennaIO/develop
chore(npm): require @athenna/config
2 parents 0e66773 + c877e30 commit 252c3e9

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@athenna/common",
3-
"version": "5.6.0",
3+
"version": "5.7.0",
44
"description": "The Athenna common helpers to use in any Node.js ESM project.",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",
@@ -106,7 +106,7 @@
106106
"youch-terminal": "^2.2.3"
107107
},
108108
"devDependencies": {
109-
"@athenna/test": "^5.2.0",
109+
"@athenna/test": "^5.3.0",
110110
"@athenna/tsconfig": "^5.0.0",
111111
"@japa/expect-type": "^2.0.3",
112112
"@types/bytes": "^3.1.5",

src/helpers/String.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ import pluralize from 'pluralize'
1111
import * as changeCase from 'change-case'
1212

1313
import { crc32 } from 'crc'
14+
import { debug } from '#src/debug'
15+
import { Path } from '#src/helpers/Path'
1416
import { Module } from '#src/helpers/Module'
1517
import { Options } from '#src/helpers/Options'
1618
import { Macroable } from '#src/helpers/Macroable'
1719
import { createHmac, randomBytes } from 'node:crypto'
1820
import { OrdinalNanException } from '#src/exceptions/OrdinalNanException'
1921
import { NotFoundAthennaConfig } from '#src/exceptions/NotFoundAthennaConfig'
2022

21-
const config = await Module.safeImport('@athenna/config')
22-
2323
export 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

Comments
 (0)