Skip to content

Commit 320bc2a

Browse files
authored
fix(hooks): check if any hooks are registered before logging the deprecation warning (#10)
1 parent 33f1bbf commit 320bc2a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/runtime/server/utils/hooks.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ export interface LLMSHooks {
1919
export const llmsHooks = createHooks<LLMSHooks>()
2020

2121
llmsHooks.beforeEach(() => {
22-
console.warn('[nuxt-llms] `llmsHooks` are deprecated and will be removed in future versions. Use `useNitroApp().hooks.hook(\'llms:generate\', (event, options) => {})` instead')
22+
// @ts-expect-error - `_hooks` is private
23+
const hooks = Object.values(llmsHooks._hooks || {})
24+
const hasRegisteredHook = hooks.some(hooksList => Array.isArray(hooksList) && hooksList.length > 0)
25+
26+
if (!hasRegisteredHook) {
27+
console.warn('[nuxt-llms] `llmsHooks` are deprecated and will be removed in future versions. Use `useNitroApp().hooks.hook(\'llms:generate\', (event, options) => {})` instead')
28+
}
2329
})
2430

2531
/**

0 commit comments

Comments
 (0)