diff --git a/packages/kit/src/components.ts b/packages/kit/src/components.ts index 007d19182a..82394e3811 100644 --- a/packages/kit/src/components.ts +++ b/packages/kit/src/components.ts @@ -3,6 +3,7 @@ import type { Component, ComponentsDir } from '@nuxt/schema' import { useNuxt } from './context' import { assertNuxtCompatibility } from './compatibility' import { logger } from './logger' +import { MODE_RE } from './utils' /** * Register a directory to be scanned for components and imported only when used. @@ -19,7 +20,6 @@ export type AddComponentOptions = { name: string, filePath: string } & Partial> -const COMPONENT_MODE_RE = /\.(server|client)(\.\w+)*$/ /** * Register a component by its name and filePath. */ @@ -29,7 +29,7 @@ export async function addComponent (opts: AddComponentOptions) { nuxt.options.components = nuxt.options.components || [] if (!opts.mode) { - const [, mode = 'all'] = opts.filePath.match(COMPONENT_MODE_RE) || [] + const [, mode = 'all'] = opts.filePath.match(MODE_RE) || [] opts.mode = mode as 'all' | 'client' | 'server' } diff --git a/packages/kit/src/plugin.ts b/packages/kit/src/plugin.ts index 40f308fa5c..116721214f 100644 --- a/packages/kit/src/plugin.ts +++ b/packages/kit/src/plugin.ts @@ -3,8 +3,8 @@ import type { NuxtPlugin, NuxtPluginTemplate } from '@nuxt/schema' import { useNuxt } from './context' import { addTemplate } from './template' import { resolveAlias } from './resolve' +import { MODE_RE } from './utils' -const PLUGIN_MODE_RE = /\.(server|client)(\.\w+)*$/ /** * Normalize a nuxt plugin object */ @@ -28,7 +28,7 @@ export function normalizePlugin (plugin: NuxtPlugin | string): NuxtPlugin { plugin.mode = 'server' } if (!plugin.mode) { - const [, mode = 'all'] = plugin.src.match(PLUGIN_MODE_RE) || [] + const [, mode = 'all'] = plugin.src.match(MODE_RE) || [] plugin.mode = mode as 'all' | 'client' | 'server' } diff --git a/packages/kit/src/utils.ts b/packages/kit/src/utils.ts index 72b096120b..89fa591c50 100644 --- a/packages/kit/src/utils.ts +++ b/packages/kit/src/utils.ts @@ -2,3 +2,5 @@ export function toArray (value: T | T[]): T[] { return Array.isArray(value) ? value : [value] } + +export const MODE_RE = /\.(server|client)(\.\w+)*$/