mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
feat(kit): add more specific typings for schema (#1988)
This commit is contained in:
parent
c184211681
commit
4fe1fc881c
@ -19,6 +19,12 @@ export default defineBuildConfig({
|
||||
'webpack',
|
||||
'vite',
|
||||
'nuxt',
|
||||
'nuxt3'
|
||||
'nuxt3',
|
||||
// type imports
|
||||
'@vue/compiler-core',
|
||||
'vue-meta',
|
||||
'rollup-plugin-visualizer',
|
||||
'webpack-bundle-analyzer',
|
||||
'vue'
|
||||
]
|
||||
})
|
||||
|
40
packages/kit/src/config/schema/_adhoc.ts
Normal file
40
packages/kit/src/config/schema/_adhoc.ts
Normal file
@ -0,0 +1,40 @@
|
||||
export default {
|
||||
/**
|
||||
* Configure Nuxt component auto-registration.
|
||||
*
|
||||
* Any components in the directories configured here can be used throughout your
|
||||
* pages, layouts (and other components) without needing to explicitly import them.
|
||||
*
|
||||
* @default {{ dirs: [`~/components`] }}
|
||||
* @see [Nuxt 3](https://v3.nuxtjs.org/docs/directory-structure/components) and
|
||||
* [Nuxt 2](https://nuxtjs.org/docs/directory-structure/components/) documentation
|
||||
* @type {boolean | typeof import('../src/types/components').ComponentsOptions | typeof import('../src/types/components').ComponentsOptions['dirs']}
|
||||
*/
|
||||
components: {
|
||||
$resolve: (val, get) => {
|
||||
if (!val) {
|
||||
// Nuxt 2 and Nuxt 3 have different default values when this option is not set,
|
||||
// so we defer to the module's own defaults here.
|
||||
return undefined
|
||||
}
|
||||
if (val === undefined || val === true) {
|
||||
return { dirs: ['~/components'] }
|
||||
}
|
||||
if (Array.isArray(val)) {
|
||||
return { dirs: val }
|
||||
}
|
||||
return val
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Configure how Nuxt auto-imports composables into your application.
|
||||
*
|
||||
* @see [Nuxt 3 documentation](https://v3.nuxtjs.org/docs/directory-structure/composables)
|
||||
* @type {typeof import('../src/types/imports').AutoImportsOptions}
|
||||
*/
|
||||
autoImports: {
|
||||
global: false,
|
||||
dirs: []
|
||||
},
|
||||
}
|
@ -10,7 +10,8 @@ export default {
|
||||
* Properties that will be set directly on `Vue.config` for vue@2.
|
||||
*
|
||||
* @see [vue@2 Documentation](https://vuejs.org/v2/api/#Global-Config)
|
||||
* @version 2
|
||||
* @type {import('vue/types/vue').VueConfiguration}
|
||||
* @version 2
|
||||
*/
|
||||
config: {
|
||||
silent: { $resolve: (val, get) => val ?? !get('dev') },
|
||||
@ -19,6 +20,7 @@ export default {
|
||||
/**
|
||||
* Options for the Vue compiler that will be passed at build time
|
||||
* @see [documentation](https://v3.vuejs.org/api/application-config.html)
|
||||
* @type {import('@vue/compiler-core').CompilerOptions}
|
||||
* @version 3
|
||||
*/
|
||||
compilerOptions: {}
|
||||
@ -87,6 +89,7 @@ export default {
|
||||
* Options to pass directly to `vue-meta`.
|
||||
*
|
||||
* @see [documentation](https://vue-meta.nuxtjs.org/api/#plugin-options).
|
||||
* @type {import('vue-meta').VueMetaOptions}
|
||||
* @version 2
|
||||
*/
|
||||
vueMeta: null,
|
||||
@ -95,6 +98,7 @@ export default {
|
||||
* Set default configuration for `<head>` on every page.
|
||||
*
|
||||
* @see [documentation](https://vue-meta.nuxtjs.org/api/#metainfo-properties) for specifics.
|
||||
* @type {import('vue-meta').MetaInfo}
|
||||
* @version 2
|
||||
*/
|
||||
head: {
|
||||
@ -133,16 +137,13 @@ export default {
|
||||
* ]
|
||||
* }
|
||||
* ```
|
||||
* @type {import('nuxt3/dist/meta/runtime/types').MetaObject}
|
||||
* @version 3
|
||||
*/
|
||||
meta: {
|
||||
/** Each item in the array maps to a newly-created `<meta>` element, where object properties map to attributes. */
|
||||
meta: [],
|
||||
/** Each item in the array maps to a newly-created `<link>` element, where object properties map to attributes. */
|
||||
link: [],
|
||||
/** Each item in the array maps to a newly-created `<style>` element, where object properties map to attributes. */
|
||||
style: [],
|
||||
/** Each item in the array maps to a newly-created `<script>` element, where object properties map to attributes. */
|
||||
script: []
|
||||
},
|
||||
|
||||
@ -177,6 +178,7 @@ export default {
|
||||
* { src: '~/plugins/server-only.js', mode: 'server' } // only on server side
|
||||
* ]
|
||||
* ```
|
||||
* @type {typeof import('../src/types/nuxt').NuxtPlugin[]}
|
||||
* @version 2
|
||||
*/
|
||||
plugins: [],
|
||||
@ -185,6 +187,7 @@ export default {
|
||||
* You may want to extend plugins or change their order. For this, you can pass
|
||||
* a function using `extendPlugins`. It accepts an array of plugin objects and
|
||||
* should return an array of plugin objects.
|
||||
* @type {(plugins: Array<{ src: string, mode?: 'client' | 'server' }>) => Array<{ src: string, mode?: 'client' | 'server' }>}
|
||||
* @version 2
|
||||
*/
|
||||
extendPlugins: null,
|
||||
@ -208,6 +211,7 @@ export default {
|
||||
* '@/assets/css/main.scss'
|
||||
* ]
|
||||
* ```
|
||||
* @type {string[]}
|
||||
* @version 2
|
||||
* @version 3
|
||||
*/
|
||||
@ -217,6 +221,7 @@ export default {
|
||||
* An object where each key name maps to a path to a layout .vue file.
|
||||
*
|
||||
* Normally there is no need to configure this directly.
|
||||
* @type {Record<string, string>}
|
||||
* @version 2
|
||||
*/
|
||||
layouts: {},
|
||||
@ -225,6 +230,7 @@ export default {
|
||||
* Set a custom error page layout.
|
||||
*
|
||||
* Normally there is no need to configure this directly.
|
||||
* @type {string}
|
||||
* @version 2
|
||||
*/
|
||||
ErrorPage: null,
|
||||
|
@ -132,6 +132,7 @@ export default {
|
||||
* middleware, and so on - defaulting to `jiti` (which has support for TypeScript and ESM syntax).
|
||||
*
|
||||
* @see [jiti](https://github.com/unjs/jiti)
|
||||
* @type {'jiti' | 'native' | ((p: string | { filename: string }) => NodeRequire)}
|
||||
* @version 2
|
||||
*/
|
||||
createRequire: {
|
||||
@ -153,6 +154,7 @@ export default {
|
||||
* or as static HTML files suitable for a CDN or other static file server (`static`).
|
||||
*
|
||||
* This is unrelated to `ssr`.
|
||||
* @type {'server' | 'static'}
|
||||
* @version 2
|
||||
*/
|
||||
target: {
|
||||
@ -194,6 +196,7 @@ export default {
|
||||
* If you have set `modern: true` and are serving your app, modern will be set to `'server'`.
|
||||
*
|
||||
* @see [concept of modern mode](https://philipwalton.com/articles/deploying-es2015-code-in-production-today/)
|
||||
* @type {'server' | 'client' | boolean}
|
||||
* @version 2
|
||||
*/
|
||||
modern: undefined,
|
||||
@ -222,6 +225,7 @@ export default {
|
||||
* function () {}
|
||||
* ]
|
||||
* ```
|
||||
* @type {typeof import('../src/types/module').ModuleInstallOptions[]}
|
||||
* @version 2
|
||||
* @version 3
|
||||
*/
|
||||
@ -258,6 +262,7 @@ export default {
|
||||
* decreases the size of `node_modules` in production deployments. Please refer to each
|
||||
* module's documentation to see if it is recommended to use `modules` or `buildModules`.
|
||||
*
|
||||
* @type {typeof import('../src/types/module').ModuleInstallOptions[]}
|
||||
* @version 2
|
||||
* @version 3
|
||||
*/
|
||||
@ -284,11 +289,17 @@ export default {
|
||||
* @version 2
|
||||
*/
|
||||
globals: {
|
||||
/** @type {(globalName: string) => string} */
|
||||
id: globalName => `__${globalName}`,
|
||||
/** @type {(globalName: string) => string} */
|
||||
nuxt: globalName => `$${globalName}`,
|
||||
/** @type {(globalName: string) => string} */
|
||||
context: globalName => `__${globalName.toUpperCase()}__`,
|
||||
/** @type {(globalName: string) => string} */
|
||||
pluginPrefix: globalName => globalName,
|
||||
/** @type {(globalName: string) => string} */
|
||||
readyCallback: globalName => `on${pascalCase(globalName)}Ready`,
|
||||
/** @type {(globalName: string) => string} */
|
||||
loadedCallback: globalName => `_on${pascalCase(globalName)}Loaded`
|
||||
},
|
||||
|
||||
@ -508,6 +519,7 @@ export default {
|
||||
* </style>
|
||||
* ```
|
||||
*
|
||||
* @type {Record<string, string>}
|
||||
* @version 2
|
||||
* @version 3
|
||||
*/
|
||||
@ -570,6 +582,7 @@ export default {
|
||||
* ```js
|
||||
* watch: ['~/custom/*.js']
|
||||
* ```
|
||||
* @type {string[]}
|
||||
* @version 2
|
||||
*/
|
||||
watch: {
|
||||
@ -611,6 +624,7 @@ export default {
|
||||
* Your preferred code editor to launch when debugging.
|
||||
*
|
||||
* @see [documentation](https://github.com/yyx990803/launch-editor#supported-editors)
|
||||
* @type {string}
|
||||
* @version 2
|
||||
*/
|
||||
editor: undefined,
|
||||
@ -644,6 +658,7 @@ export default {
|
||||
* ```
|
||||
* @version 2
|
||||
* @version 3
|
||||
* @type {typeof import('../src/types/hooks').NuxtHooks}
|
||||
*/
|
||||
hooks: null,
|
||||
|
||||
@ -669,6 +684,7 @@ export default {
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
* @type {typeof import('../src/types/runtime-config').PrivateRuntimeConfig}
|
||||
* @version 2
|
||||
* @version 3
|
||||
*/
|
||||
@ -693,10 +709,11 @@ export default {
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
* @type {typeof import('../src/types/runtime-config').PublicRuntimeConfig}
|
||||
* @version 2
|
||||
* @version 3
|
||||
*/
|
||||
publicRuntimeConfig: {
|
||||
$resolve: (val, get) => defu(val, { app: get('app') })
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ export default {
|
||||
* analyzerMode: 'static'
|
||||
* }
|
||||
* ```
|
||||
* @type {boolean | typeof import('webpack-bundle-analyzer').BundleAnalyzerPlugin.Options | typeof import('rollup-plugin-visualizer').PluginVisualizerOptions}
|
||||
*/
|
||||
analyze: false,
|
||||
|
||||
@ -446,7 +447,8 @@ export default {
|
||||
transpile: [({ isLegacy }) => isLegacy && 'ky']
|
||||
* ```
|
||||
* @version 2
|
||||
* @version 3 webpack only
|
||||
* @version 3
|
||||
* @type {Array<string | RegExp | Function>}
|
||||
*/
|
||||
transpile: {
|
||||
$resolve: val => [].concat(val).filter(Boolean)
|
||||
|
@ -1,6 +1,7 @@
|
||||
export default {
|
||||
/**
|
||||
* Add a message to the CLI banner by adding a string to this array.
|
||||
* @type {string[]}
|
||||
* @version 2
|
||||
*/
|
||||
badgeMessages: [],
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
import _adhoc from './_adhoc'
|
||||
import _app from './_app'
|
||||
import _common from './_common'
|
||||
import _internal from './_internal'
|
||||
@ -30,6 +31,7 @@ TODO for top level normalizations: (nuxt2)
|
||||
*/
|
||||
|
||||
export default {
|
||||
..._adhoc,
|
||||
..._app,
|
||||
..._common,
|
||||
..._internal,
|
||||
@ -40,5 +42,11 @@ export default {
|
||||
server,
|
||||
cli,
|
||||
generate,
|
||||
typescript
|
||||
typescript,
|
||||
// TODO: split out into separate file
|
||||
/**
|
||||
* Configuration that will be passed directly to Vite.
|
||||
* @type {boolean | typeof import('vite').InlineConfig}
|
||||
*/
|
||||
vite: undefined,
|
||||
}
|
||||
|
@ -90,5 +90,5 @@ export interface ComponentsDir extends ScanDir {
|
||||
|
||||
export interface ComponentsOptions {
|
||||
dirs: (string | ComponentsDir)[]
|
||||
loader: Boolean
|
||||
loader?: Boolean
|
||||
}
|
||||
|
@ -1,20 +1,4 @@
|
||||
import { ConfigSchema as _ConfigSchema } from '../../schema/config'
|
||||
import { ModuleInstallOptions } from './module'
|
||||
import { NuxtHooks } from './hooks'
|
||||
import { AutoImportsOptions } from './imports'
|
||||
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
|
||||
vite: boolean | import('vite').InlineConfig
|
||||
autoImports: AutoImportsOptions
|
||||
}
|
||||
import { ConfigSchema } from '../../schema/config'
|
||||
|
||||
export interface NuxtOptions extends ConfigSchema { }
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { statSync } from 'fs'
|
||||
import { resolve } from 'pathe'
|
||||
import { defineNuxtModule, resolveAlias, addVitePlugin, addWebpackPlugin } from '@nuxt/kit'
|
||||
import type { Component, ComponentsDir } from '@nuxt/kit'
|
||||
import type { Component, ComponentsDir, ComponentsOptions } from '@nuxt/kit'
|
||||
import { componentsTemplate, componentsTypeTemplate } from './templates'
|
||||
import { scanComponents } from './scan'
|
||||
import { loaderPlugin } from './loader'
|
||||
@ -9,8 +9,9 @@ import { loaderPlugin } from './loader'
|
||||
const isPureObjectOrString = (val: any) => (!Array.isArray(val) && typeof val === 'object') || typeof val === 'string'
|
||||
const isDirectory = (p: string) => { try { return statSync(p).isDirectory() } catch (_e) { return false } }
|
||||
|
||||
export default defineNuxtModule({
|
||||
export default defineNuxtModule<ComponentsOptions>({
|
||||
name: 'components',
|
||||
configKey: 'components',
|
||||
defaults: {
|
||||
dirs: ['~/components']
|
||||
},
|
||||
|
@ -12,10 +12,13 @@ export interface MetaObject extends Record<string, any> {
|
||||
* @default `'width=device-width, initial-scale=1'`
|
||||
*/
|
||||
viewport?: string
|
||||
}
|
||||
|
||||
declare module '@nuxt/kit' {
|
||||
interface ConfigSchema {
|
||||
meta: MetaObject,
|
||||
}
|
||||
/** Each item in the array maps to a newly-created `<meta>` element, where object properties map to attributes. */
|
||||
meta: Array<Record<string, any>>
|
||||
/** Each item in the array maps to a newly-created `<link>` element, where object properties map to attributes. */
|
||||
link: Array<Record<string, any>>
|
||||
/** Each item in the array maps to a newly-created `<style>` element, where object properties map to attributes. */
|
||||
style: Array<Record<string, any>>
|
||||
/** Each item in the array maps to a newly-created `<script>` element, where object properties map to attributes. */
|
||||
script: Array<Record<string, any>>
|
||||
}
|
||||
|
24
yarn.lock
24
yarn.lock
@ -20424,17 +20424,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typescript@npm:^4.3.4":
|
||||
version: 4.4.4
|
||||
resolution: "typescript@npm:4.4.4"
|
||||
bin:
|
||||
tsc: bin/tsc
|
||||
tsserver: bin/tsserver
|
||||
checksum: 89ecb8436bb48ef5594d49289f5f89103071716b6e4844278f4fb3362856e31203e187a9c76d205c3f0b674d221a058fd28310dbcbcf5d95e9a57229bb5203f1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typescript@npm:^4.5.2":
|
||||
"typescript@npm:^4.3.4, typescript@npm:^4.5.2":
|
||||
version: 4.5.2
|
||||
resolution: "typescript@npm:4.5.2"
|
||||
bin:
|
||||
@ -20444,17 +20434,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typescript@patch:typescript@^4.3.4#~builtin<compat/typescript>":
|
||||
version: 4.4.4
|
||||
resolution: "typescript@patch:typescript@npm%3A4.4.4#~builtin<compat/typescript>::version=4.4.4&hash=ddd1e8"
|
||||
bin:
|
||||
tsc: bin/tsc
|
||||
tsserver: bin/tsserver
|
||||
checksum: bd629ad0da4a15d79aaad56baf3ee7d96f6a181760d430ae77f8c5325df7bffd9edee57544a3970e3651e8b796fe03a5838a7eb39c6d46cc3866c0b23d36a0dd
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typescript@patch:typescript@^4.5.2#~builtin<compat/typescript>":
|
||||
"typescript@patch:typescript@^4.3.4#~builtin<compat/typescript>, typescript@patch:typescript@^4.5.2#~builtin<compat/typescript>":
|
||||
version: 4.5.2
|
||||
resolution: "typescript@patch:typescript@npm%3A4.5.2#~builtin<compat/typescript>::version=4.5.2&hash=ddd1e8"
|
||||
bin:
|
||||
|
Loading…
Reference in New Issue
Block a user