From 9af7bef1a938e30951fc58695140117163987ead Mon Sep 17 00:00:00 2001 From: Baroshem Date: Thu, 16 Feb 2023 14:16:17 +0100 Subject: [PATCH 1/6] feat-#18678: add restart hook --- packages/nuxi/src/commands/dev.ts | 2 ++ packages/schema/src/types/hooks.ts | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/nuxi/src/commands/dev.ts b/packages/nuxi/src/commands/dev.ts index c4521ae20cf7..faeb699977d2 100644 --- a/packages/nuxi/src/commands/dev.ts +++ b/packages/nuxi/src/commands/dev.ts @@ -76,6 +76,8 @@ export default defineNuxtCommand({ await currentNuxt.close() } currentNuxt = await loadNuxt({ rootDir, dev: true, ready: false }) + currentNuxt.hook('restart', () => load(true)) + if (!isRestart) { showURL() } diff --git a/packages/schema/src/types/hooks.ts b/packages/schema/src/types/hooks.ts index 6b882387c22f..2b080868befd 100644 --- a/packages/schema/src/types/hooks.ts +++ b/packages/schema/src/types/hooks.ts @@ -61,7 +61,7 @@ export interface NuxtHooks { 'kit:compatibility': (compatibility: NuxtCompatibility, issues: NuxtCompatibilityIssues) => HookResult // Nuxt - /** + /** * Called after Nuxt initialization, when the Nuxt instance is ready to work. * @param nuxt The configured Nuxt object * @returns Promise @@ -73,6 +73,11 @@ export interface NuxtHooks { * @returns Promise */ 'close': (nuxt: Nuxt) => HookResult + /** + * Called when Nuxt instance is restarting. + * @returns Promise + */ + 'restart': () => HookResult /** * Called during Nuxt initialization, before installing user modules. From ca8f244a424232353b4bd1c94ae51cf2c7fdd366 Mon Sep 17 00:00:00 2001 From: Baroshem Date: Thu, 16 Feb 2023 14:19:09 +0100 Subject: [PATCH 2/6] feat-#18678: restart hook docs --- docs/3.api/4.advanced/1.hooks.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/3.api/4.advanced/1.hooks.md b/docs/3.api/4.advanced/1.hooks.md index 2a727cb6eb96..514df9a08e8e 100644 --- a/docs/3.api/4.advanced/1.hooks.md +++ b/docs/3.api/4.advanced/1.hooks.md @@ -38,6 +38,7 @@ Hook | Arguments | Description `kit:compatibility` | `compatibility, issues` | Allows extending compatibility checks. `ready` | `nuxt` | Called after Nuxt initialization, when the Nuxt instance is ready to work. `close` | `nuxt` | Called when Nuxt instance is gracefully closing. +`restart` | - | Called when Nuxt instance is restarting. `modules:before` | - | Called during Nuxt initialization, before installing user modules. `modules:done` | - | Called during Nuxt initialization, after installing user modules. `app:resolve` | `app` | Called after resolving the `app` instance. From 240615a427656fa7cc20078dbc7f77b146787bfc Mon Sep 17 00:00:00 2001 From: Jakub Andrzejewski <37120330+Baroshem@users.noreply.github.com> Date: Thu, 16 Feb 2023 14:35:26 +0100 Subject: [PATCH 3/6] Update packages/nuxi/src/commands/dev.ts Co-authored-by: pooya parsa --- packages/nuxi/src/commands/dev.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/commands/dev.ts b/packages/nuxi/src/commands/dev.ts index faeb699977d2..b91f0ccb870d 100644 --- a/packages/nuxi/src/commands/dev.ts +++ b/packages/nuxi/src/commands/dev.ts @@ -76,7 +76,7 @@ export default defineNuxtCommand({ await currentNuxt.close() } currentNuxt = await loadNuxt({ rootDir, dev: true, ready: false }) - currentNuxt.hook('restart', () => load(true)) + currentNuxt.hookOnce('restart', () => load(true)) if (!isRestart) { showURL() From 9fedcaa04fc829cafda6a79bbb41327279f28c57 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 16 Feb 2023 05:51:08 -0800 Subject: [PATCH 4/6] fix: access `hookOnce` from `nuxtApp.hooks` --- packages/nuxi/src/commands/dev.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/commands/dev.ts b/packages/nuxi/src/commands/dev.ts index b91f0ccb870d..ee246c6f6021 100644 --- a/packages/nuxi/src/commands/dev.ts +++ b/packages/nuxi/src/commands/dev.ts @@ -76,7 +76,7 @@ export default defineNuxtCommand({ await currentNuxt.close() } currentNuxt = await loadNuxt({ rootDir, dev: true, ready: false }) - currentNuxt.hookOnce('restart', () => load(true)) + currentNuxt.hooks.hookOnce('restart', () => load(true)) if (!isRestart) { showURL() From 00757faa98711c9c67f2642645e244ed91599a1e Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 16 Feb 2023 05:51:53 -0800 Subject: [PATCH 5/6] docs: slight wording tweak --- docs/3.api/4.advanced/1.hooks.md | 2 +- packages/schema/src/types/hooks.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/3.api/4.advanced/1.hooks.md b/docs/3.api/4.advanced/1.hooks.md index 514df9a08e8e..c2a35810e340 100644 --- a/docs/3.api/4.advanced/1.hooks.md +++ b/docs/3.api/4.advanced/1.hooks.md @@ -38,7 +38,7 @@ Hook | Arguments | Description `kit:compatibility` | `compatibility, issues` | Allows extending compatibility checks. `ready` | `nuxt` | Called after Nuxt initialization, when the Nuxt instance is ready to work. `close` | `nuxt` | Called when Nuxt instance is gracefully closing. -`restart` | - | Called when Nuxt instance is restarting. +`restart` | - | Called to restart the current Nuxt instance. `modules:before` | - | Called during Nuxt initialization, before installing user modules. `modules:done` | - | Called during Nuxt initialization, after installing user modules. `app:resolve` | `app` | Called after resolving the `app` instance. diff --git a/packages/schema/src/types/hooks.ts b/packages/schema/src/types/hooks.ts index 2b080868befd..566b89042b5a 100644 --- a/packages/schema/src/types/hooks.ts +++ b/packages/schema/src/types/hooks.ts @@ -74,7 +74,7 @@ export interface NuxtHooks { */ 'close': (nuxt: Nuxt) => HookResult /** - * Called when Nuxt instance is restarting. + * Called to restart the current Nuxt instance. * @returns Promise */ 'restart': () => HookResult From 951c3210b4870cbd94d1d52c7570deea5676e60f Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 1 Mar 2023 04:06:07 -0800 Subject: [PATCH 6/6] docs: add note that this feature is not yet released --- docs/3.api/4.advanced/1.hooks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/3.api/4.advanced/1.hooks.md b/docs/3.api/4.advanced/1.hooks.md index c2a35810e340..af93555a065a 100644 --- a/docs/3.api/4.advanced/1.hooks.md +++ b/docs/3.api/4.advanced/1.hooks.md @@ -38,7 +38,7 @@ Hook | Arguments | Description `kit:compatibility` | `compatibility, issues` | Allows extending compatibility checks. `ready` | `nuxt` | Called after Nuxt initialization, when the Nuxt instance is ready to work. `close` | `nuxt` | Called when Nuxt instance is gracefully closing. -`restart` | - | Called to restart the current Nuxt instance. +`restart` | - | Called to restart the current Nuxt instance. **This hook is currently only available on the [Edge Channel](/docs/guide/going-further/edge-channel/).** `modules:before` | - | Called during Nuxt initialization, before installing user modules. `modules:done` | - | Called during Nuxt initialization, after installing user modules. `app:resolve` | `app` | Called after resolving the `app` instance.