mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
feat(kit): add components types (#1164)
This commit is contained in:
parent
0c937339b9
commit
dbbce5fcfa
@ -20,3 +20,4 @@ export * from './types/config'
|
||||
export * from './types/hooks'
|
||||
export * from './types/module'
|
||||
export * from './types/nuxt'
|
||||
export * from './types/components'
|
||||
|
@ -39,24 +39,7 @@ export interface ComponentsDir extends ScanDir {
|
||||
transpile?: 'auto' | boolean
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
export interface ComponentsOptions {
|
||||
dirs: (string | ComponentsDir)[]
|
||||
loader: Boolean
|
||||
}
|
||||
|
||||
type componentsDirHook = (dirs: Options['dirs']) => void | Promise<void>
|
||||
type componentsExtendHook = (components: (Component | ComponentsDir | ScanDir)[]) => void | Promise<void>
|
||||
|
||||
declare module '@nuxt/kit' {
|
||||
interface NuxtOptions {
|
||||
components: boolean | Options | Options['dirs']
|
||||
}
|
||||
interface NuxtHooks {
|
||||
'components:dirs'?: componentsDirHook
|
||||
'components:extend'?: componentsExtendHook
|
||||
components?: {
|
||||
dirs?: componentsDirHook
|
||||
extend?: componentsExtendHook
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
import { ConfigSchema as _ConfigSchema } from '../../schema/config'
|
||||
import { ModuleInstallOptions } from './module'
|
||||
import { NuxtHooks } from './hooks'
|
||||
import { ComponentsOptions } from './components'
|
||||
|
||||
export interface ConfigSchema extends _ConfigSchema {
|
||||
hooks: NuxtHooks,
|
||||
modules: ModuleInstallOptions[]
|
||||
buildModules: ModuleInstallOptions[]
|
||||
components: boolean | ComponentsOptions | ComponentsOptions['dirs']
|
||||
[key: string]: any
|
||||
|
||||
// TODO: Move to schema when untyped supports type annotation
|
||||
|
@ -3,7 +3,8 @@ import type { Compiler, Configuration, Stats } from 'webpack'
|
||||
import type { TSConfig } from 'pkg-types'
|
||||
import type { NuxtConfig, NuxtOptions } from '..'
|
||||
import type { ModuleContainer } from '../module/container'
|
||||
import type { NuxtTemplate, Nuxt, NuxtApp } from '../types/nuxt'
|
||||
import type { NuxtTemplate, Nuxt, NuxtApp } from './nuxt'
|
||||
import type { Component, ComponentsDir, ScanDir, ComponentsOptions } from './components'
|
||||
|
||||
type HookResult = Promise<void> | void
|
||||
|
||||
@ -36,6 +37,10 @@ export interface NuxtHooks {
|
||||
'app:templatesGenerated': (app: NuxtApp) => HookResult
|
||||
'builder:generateApp': () => HookResult
|
||||
|
||||
// components
|
||||
'components:dirs': (dirs: ComponentsOptions['dirs']) => HookResult
|
||||
'components:extend': (components: (Component | ComponentsDir | ScanDir)[]) => HookResult
|
||||
|
||||
// @nuxt/builder
|
||||
'build:before':
|
||||
(builder: Builder, buildOptions: NuxtOptions['build']) => HookResult
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { createUnplugin } from 'unplugin'
|
||||
import { parseQuery, parseURL } from 'ufo'
|
||||
import { Component } from './types'
|
||||
import { Component } from '@nuxt/kit'
|
||||
|
||||
interface LoaderOptions {
|
||||
getComponents(): Component[]
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { statSync } from 'fs'
|
||||
import { resolve } from 'pathe'
|
||||
import { defineNuxtModule, resolveAlias, addVitePlugin, addWebpackPlugin } from '@nuxt/kit'
|
||||
import type { Component, ComponentsDir } from '@nuxt/kit'
|
||||
import { componentsTemplate, componentsTypeTemplate } from './templates'
|
||||
import { scanComponents } from './scan'
|
||||
import type { Component, ComponentsDir } from './types'
|
||||
import { loaderPlugin } from './loader'
|
||||
|
||||
const isPureObjectOrString = (val: any) => (!Array.isArray(val) && typeof val === 'object') || typeof val === 'string'
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { basename, extname, join, dirname, relative } from 'pathe'
|
||||
import globby from 'globby'
|
||||
import { pascalCase, splitByCase } from 'scule'
|
||||
import type { ScanDir, Component } from './types'
|
||||
import type { ScanDir, Component } from '@nuxt/kit'
|
||||
|
||||
export function sortDirsByPathLength ({ path: pathA }: ScanDir, { path: pathB }: ScanDir): number {
|
||||
return pathB.split(/[\\/]/).filter(Boolean).length - pathA.split(/[\\/]/).filter(Boolean).length
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
import { relative } from 'pathe'
|
||||
|
||||
import type { Component } from './types'
|
||||
import type { Component } from '@nuxt/kit'
|
||||
|
||||
export type ComponentsTemplateOptions = {
|
||||
buildDir?: string
|
||||
|
Loading…
Reference in New Issue
Block a user