This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate to hookable's
createDebugger
- Loading branch information
Showing
4 changed files
with
25 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,9 @@ | ||
import { createDebugger } from 'hookable' | ||
import { defineNuxtPlugin } from '#app' | ||
|
||
const wrapName = (event: string) => process.server ? `[nuxt] ${event}` : event | ||
|
||
export default defineNuxtPlugin((nuxtApp) => { | ||
nuxtApp.hooks.beforeEach(({ name }) => { | ||
console.time(wrapName(name)) | ||
}) | ||
|
||
nuxtApp.hooks.afterEach(({ name, args }) => { | ||
if (process.client) { | ||
console.groupCollapsed(name) | ||
console.timeLog(name, args) | ||
console.groupEnd() | ||
} | ||
if (process.server) { | ||
console.timeEnd(wrapName(name)) | ||
} | ||
// @ts-expect-error remove in next version of hookable | ||
createDebugger(nuxtApp.hooks, { | ||
tag: 'nuxt app' | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
import { createDebugger } from 'hookable' | ||
import type { NitroAppPlugin } from 'nitropack' | ||
|
||
const wrapName = (event: string) => `[nitro] ${event}` | ||
|
||
export default <NitroAppPlugin> function (nitro) { | ||
nitro.hooks.beforeEach(({ name }) => { | ||
console.time(wrapName(name)) | ||
}) | ||
|
||
nitro.hooks.afterEach(({ name }) => { | ||
console.timeEnd(wrapName(name)) | ||
createDebugger(nitro.hooks, { | ||
tag: 'nitro app' | ||
}) | ||
} |