diff --git a/docs/3.api/4.advanced/2.kit.md b/docs/3.api/4.advanced/2.kit.md index 7f92d40835..cb15e09192 100644 --- a/docs/3.api/4.advanced/2.kit.md +++ b/docs/3.api/4.advanced/2.kit.md @@ -183,12 +183,218 @@ Options to pass in [`c12`](https://github.com/unjs/c12#options) `loadConfig` cal [source code](https://github.com/nuxt/nuxt/blob/main/packages/kit/src/compatibility.ts) -- `checkNuxtCompatibility(constraints)` -- `assertNuxtCompatibility(constraints)` -- `hasNuxtCompatibility(constraints)` -- `isNuxt2()` -- `isNuxt3()` -- `getNuxtVersion()` +### `checkNuxtCompatibility` + +Checks if constraints are met for the current Nuxt version. If not, returns an array of messages. Nuxt 2 version also checks for `bridge` support. + +#### Type + +```ts +async function checkNuxtCompatibility( + constraints: NuxtCompatibility, + nuxt?: Nuxt +): Promise; + +interface NuxtCompatibility { + nuxt?: string; + bridge?: boolean; +} + +interface NuxtCompatibilityIssue { + name: string; + message: string; +} + +interface NuxtCompatibilityIssues extends Array { + toString(): string; +} +``` + +#### Parameters + +##### `constraints` + +**Type**: `NuxtCompatibility` + +**Default**: `{}` + +Constraints to check for. It accepts the following properties: + +- `nuxt` (optional) + + **Type**: `string`ч + + Nuxt version in semver format. Versions may be defined in Node.js way, for exmaple: `>=2.15.0 <3.0.0`. + +- `bridge` (optional) + + **Type**: `boolean` + + If set to `true`, it will check if the current Nuxt version supports `bridge`. + +##### `nuxt` + +**Type**: `Nuxt` + +**Default**: `useNuxt()` + +Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call. + +### `assertNuxtCompatibility` + +Asserts that constraints are met for the current Nuxt version. If not, throws an error with the list of issues as string. + +#### Type + +```ts +async function assertNuxtCompatibility( + constraints: NuxtCompatibility, + nuxt?: Nuxt +): Promise; + +interface NuxtCompatibility { + nuxt?: string; + bridge?: boolean; +} +``` + +#### Parameters + +##### `constraints` + +**Type**: `NuxtCompatibility` + +**Default**: `{}` + +Constraints to check for. It accepts the following properties: + +- `nuxt` (optional) + + **Type**: `string`ч + + Nuxt version in semver format. Versions may be defined in Node.js way, for exmaple: `>=2.15.0 <3.0.0`. + +- `bridge` (optional) + + **Type**: `boolean` + + If set to `true`, it will check if the current Nuxt version supports `bridge`. + +##### `nuxt` + +**Type**: `Nuxt` + +**Default**: `useNuxt()` + +Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call. + +### `hasNuxtCompatibility` + +Checks if constraints are met for the current Nuxt version. Return `true` if all constraints are met, otherwise returns `false`. Nuxt 2 version also checks for `bridge` support. + +#### Type + +```ts +async function hasNuxtCompatibility( + constraints: NuxtCompatibility, + nuxt?: Nuxt +): Promise; + +interface NuxtCompatibility { + nuxt?: string; + bridge?: boolean; +} +``` + +#### Parameters + +##### `constraints` + +**Type**: `NuxtCompatibility` + +**Default**: `{}` + +Constraints to check for. It accepts the following properties: + +- `nuxt` (optional) + + **Type**: `string`ч + + Nuxt version in semver format. Versions may be defined in Node.js way, for exmaple: `>=2.15.0 <3.0.0`. + +- `bridge` (optional) + + **Type**: `boolean` + + If set to `true`, it will check if the current Nuxt version supports `bridge`. + +##### `nuxt` + +**Type**: `Nuxt` + +**Default**: `useNuxt()` + +Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call. + +### `isNuxt2` + +Checks if the current Nuxt version is 2.x. + +#### Type + +```ts +function isNuxt2(nuxt?: Nuxt): boolean; +``` + +#### Parameters + +##### `nuxt` + +**Type**: `Nuxt` + +**Default**: `useNuxt()` + +Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call. + +### `isNuxt3` + +Checks if the current Nuxt version is 3.x. + +#### Type + +```ts +function isNuxt3(nuxt?: Nuxt): boolean; +``` + +#### Parameters + +##### `nuxt` + +**Type**: `Nuxt` + +**Default**: `useNuxt()` + +Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call. + +### `getNuxtVersion` + +Returns the current Nuxt version. + +#### Type + +```ts +function getNuxtVersion(nuxt?: Nuxt): string; +``` + +#### Parameters + +##### `nuxt` + +**Type**: `Nuxt` + +**Default**: `useNuxt()` + +Nuxt instance. If not provided, it will be retrieved from the context via `useNuxt()` call. ## Auto-imports