Skip to content

Commit

Permalink
fix: rename RuntimeModuleHooks to ModuleRuntimeHooks (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Dec 19, 2023
1 parent 3c0ef06 commit 6641d8d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The entrypoint for module definition.

A default export using `defineNuxtModule` and `ModuleOptions` type export is expected.

You could also optionally export `ModuleHooks` or `RuntimeModuleHooks` to annotate any custom hooks the module uses.
You could also optionally export `ModuleHooks` or `ModuleRuntimeHooks` to annotate any custom hooks the module uses.

```ts [src/module.ts]
import { defineNuxtModule } from '@nuxt/kit'
Expand All @@ -55,10 +55,14 @@ export interface ModuleHooks {
'my-module:init': any
}

export interface RuntimeModuleHooks {
export interface ModuleRuntimeHooks {
'my-module:runtime-hook': any
}

export interface ModuleRuntimeConfig {
PRIVATE_NAME: string
}

export interface ModulePublicRuntimeConfig {
NAME: string
}
Expand Down Expand Up @@ -141,7 +145,6 @@ Module builder generates dist files in `dist/` directory:

[MIT](./LICENSE) - Made with 💚


<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/@nuxt/module-builder/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-version-href]: https://npmjs.com/package/@nuxt/module-builder
Expand Down
7 changes: 7 additions & 0 deletions example/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export interface ModuleHooks {
'my-module:init': () => void
}

export interface ModuleRuntimeHooks {
'my-module:runtime-hook': any
}

/**
* @deprecated `RuntimeModuleHooks` is a deprecated naming and will be removed in the future. Please use `ModuleRuntimeHooks` instead.
*/
export interface RuntimeModuleHooks {
'my-module:runtime-hook': () => void
}
Expand Down
18 changes: 15 additions & 3 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,22 @@ async function writeTypes (distDir: string, meta: ModuleMeta) {
moduleImports.push('ModuleHooks')
schemaShims.push(' interface NuxtHooks extends ModuleHooks {}')
}
if (hasTypeExport('RuntimeModuleHooks')) {
moduleImports.push('RuntimeModuleHooks')
appShims.push(' interface RuntimeNuxtHooks extends RuntimeModuleHooks {}')

if (hasTypeExport('RuntimeModuleHooks') || hasTypeExport('ModuleRuntimeHooks')) {
const runtimeHooksInterfaces = []

if (hasTypeExport('RuntimeModuleHooks')) {
consola.warn('`RuntimeModuleHooks` is a deprecated naming and will be removed in the future. Please use `ModuleRuntimeHooks` instead.')
runtimeHooksInterfaces.push('RuntimeModuleHooks')
}
if (hasTypeExport('ModuleRuntimeHooks')) {
runtimeHooksInterfaces.push('ModuleRuntimeHooks')
}

moduleImports.push(...runtimeHooksInterfaces)
appShims.push(` interface RuntimeNuxtHooks extends ${runtimeHooksInterfaces.join(', ')} {}`)
}

if (hasTypeExport('ModuleRuntimeConfig')) {
moduleImports.push('ModuleRuntimeConfig')
schemaShims.push(' interface RuntimeConfig extends ModuleRuntimeConfig {}')
Expand Down
6 changes: 3 additions & 3 deletions test/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ describe('module builder', () => {
const types = await readFile(join(distDir, 'types.d.ts'), 'utf-8')
expect(types).toMatchInlineSnapshot(`
"
import type { ModuleOptions, ModuleHooks, RuntimeModuleHooks, ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module'
import type { ModuleOptions, ModuleHooks, RuntimeModuleHooks, ModuleRuntimeHooks, ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module'
declare module '#app' {
interface RuntimeNuxtHooks extends RuntimeModuleHooks {}
interface RuntimeNuxtHooks extends RuntimeModuleHooks, ModuleRuntimeHooks {}
}
declare module '@nuxt/schema' {
Expand All @@ -68,7 +68,7 @@ describe('module builder', () => {
}
export type { ModuleHooks, ModuleOptions, ModulePublicRuntimeConfig, ModuleRuntimeConfig, RuntimeModuleHooks, default } from './module'
export type { ModuleHooks, ModuleOptions, ModulePublicRuntimeConfig, ModuleRuntimeConfig, ModuleRuntimeHooks, RuntimeModuleHooks, default } from './module'
"
`)
})
Expand Down

0 comments on commit 6641d8d

Please sign in to comment.