diff --git a/.eslintignore b/.eslintignore index 125155c9ed..65939590c1 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,5 @@ dist node_modules -schema +packages/schema/schema **/*.tmpl.* sw.js diff --git a/.eslintrc b/.eslintrc index a6d2bd2130..cbeda1b409 100644 --- a/.eslintrc +++ b/.eslintrc @@ -100,6 +100,21 @@ "definedTags": ["__NO_SIDE_EFFECTS__"] }] }, + "overrides": [ + { + "files": ["packages/schema/**"], + "rules": { + "jsdoc/no-undefined-types": "off", + "jsdoc/valid-types": "off", + "jsdoc/check-tag-names": [ + "error", + { + "definedTags": ["experimental"] + } + ] + } + } + ], "settings": { "jsdoc": { "ignoreInternal": true, diff --git a/packages/schema/src/config/adhoc.ts b/packages/schema/src/config/adhoc.ts index b8449e8872..817363cbff 100644 --- a/packages/schema/src/config/adhoc.ts +++ b/packages/schema/src/config/adhoc.ts @@ -34,6 +34,7 @@ export default defineUntypedSchema({ /** * An array of custom directories that will be auto-imported. * Note that this option will not override the default directories (~/composables, ~/utils). + * * @example * ```js * imports: { @@ -57,9 +58,8 @@ export default defineUntypedSchema({ * Manually disable nuxt telemetry. * * @see [Nuxt Telemetry](https://github.com/nuxt/telemetry) for more information. - * * @type {boolean | Record} - */ + */ telemetry: undefined, /** diff --git a/packages/schema/src/config/app.ts b/packages/schema/src/config/app.ts index be9d0f2150..759a8184e6 100644 --- a/packages/schema/src/config/app.ts +++ b/packages/schema/src/config/app.ts @@ -10,6 +10,7 @@ export default defineUntypedSchema({ vue: { /** * Options for the Vue compiler that will be passed at build time. + * * @see [documentation](https://vuejs.org/api/application.html#app-config-compileroptions) * @type {typeof import('@vue/compiler-core').CompilerOptions} */ @@ -19,11 +20,12 @@ export default defineUntypedSchema({ * Include Vue compiler in runtime bundle. */ runtimeCompiler: { - $resolve: async (val, get) => val ?? await get('experimental.runtimeVueCompiler') ?? false, + $resolve: async (val, get) => val ?? await get('experimental.runtimeVueCompiler') ?? false }, /** * Vue Experimental: Enable reactive destructure for `defineProps` + * * @see [Vue RFC#502](https://github.com/vuejs/rfcs/discussions/502) * @type {boolean} */ @@ -31,6 +33,7 @@ export default defineUntypedSchema({ /** * Vue Experimental: Enable macro `defineModel` + * * @see [Vue RFC#503](https://github.com/vuejs/rfcs/discussions/503) * @type {boolean} */ @@ -45,24 +48,26 @@ export default defineUntypedSchema({ * The base path of your Nuxt application. * * This can be set at runtime by setting the NUXT_APP_BASE_URL environment variable. + * * @example * ```bash * NUXT_APP_BASE_URL=/prefix/ node .output/server/index.mjs * ``` */ baseURL: { - $resolve: async (val) => val || process.env.NUXT_APP_BASE_URL || '/', + $resolve: val => val || process.env.NUXT_APP_BASE_URL || '/' }, /** The folder name for the built site assets, relative to `baseURL` (or `cdnURL` if set). This is set at build time and should not be customized at runtime. */ buildAssetsDir: { - $resolve: async (val) => val || process.env.NUXT_APP_BUILD_ASSETS_DIR || '/_nuxt/', + $resolve: val => val || process.env.NUXT_APP_BUILD_ASSETS_DIR || '/_nuxt/' }, /** * An absolute URL to serve the public folder from (production-only). * * This can be set to a different value at runtime by setting the `NUXT_APP_CDN_URL` environment variable. + * * @example * ```bash * NUXT_APP_CDN_URL=https://mycdn.org/ node .output/server/index.mjs @@ -175,10 +180,11 @@ export default defineUntypedSchema({ * Customize Nuxt root element tag. * */ - rootTag: 'div', + rootTag: 'div' }, - /** A path to an HTML file, the contents of which will be inserted into any HTML page + /** + * A path to an HTML file, the contents of which will be inserted into any HTML page * rendered with `ssr: false`. * * By default Nuxt will look in `~/app/spa-loading-template.html` for this file. @@ -230,7 +236,6 @@ export default defineUntypedSchema({ * } * * ``` - * * @type {string | false} */ spaLoadingTemplate: { @@ -249,9 +254,7 @@ export default defineUntypedSchema({ * @note Plugins are also auto-registered from the `~/plugins` directory * and these plugins do not need to be listed in `nuxt.config` unless you * need to customize their order. All plugins are deduplicated by their src path. - * * @see https://nuxt.com/docs/guide/directory-structure/plugins - * * @example * ```js * plugins: [ diff --git a/packages/schema/src/config/build.ts b/packages/schema/src/config/build.ts index 0a9e61841b..16cfccc168 100644 --- a/packages/schema/src/config/build.ts +++ b/packages/schema/src/config/build.ts @@ -16,7 +16,7 @@ export default defineUntypedSchema({ } const map: Record = { vite: '@nuxt/vite-builder', - webpack: '@nuxt/webpack-builder', + webpack: '@nuxt/webpack-builder' } return map[val] || val || (await get('vite') === false ? map.webpack : map.vite) } @@ -36,7 +36,7 @@ export default defineUntypedSchema({ server: true, client: await get('dev') }) - }, + } }, /** @@ -96,7 +96,6 @@ export default defineUntypedSchema({ * } * ] * ``` - * * @type {typeof import('../src/types/nuxt').NuxtTemplate[]} */ templates: [], @@ -113,7 +112,6 @@ export default defineUntypedSchema({ * } * ``` * @type {boolean | typeof import('webpack-bundle-analyzer').BundleAnalyzerPlugin.Options | typeof import('rollup-plugin-visualizer').PluginVisualizerOptions} - * */ analyze: { $resolve: async (val, get) => { @@ -128,7 +126,7 @@ export default defineUntypedSchema({ filename: join(analyzeDir, '{name}.html') } } - }, + } }, /** @@ -147,13 +145,13 @@ export default defineUntypedSchema({ * @type {Array<{ name: string, source?: string | RegExp, argumentLength: number }>} */ keyedComposables: { - $resolve: (val) => [ + $resolve: val => [ { name: 'defineNuxtComponent', argumentLength: 2 }, { name: 'useState', argumentLength: 2 }, { name: 'useFetch', argumentLength: 3 }, { name: 'useAsyncData', argumentLength: 3 }, { name: 'useLazyAsyncData', argumentLength: 3 }, - { name: 'useLazyFetch', argumentLength: 3 }, + { name: 'useLazyFetch', argumentLength: 3 } ].concat(val).filter(Boolean) }, @@ -172,18 +170,22 @@ export default defineUntypedSchema({ composables: { server: { $resolve: async (val, get) => defu(val || {}, - await get('dev') ? {} : { - vue: ['onBeforeMount', 'onMounted', 'onBeforeUpdate', 'onRenderTracked', 'onRenderTriggered', 'onActivated', 'onDeactivated', 'onBeforeUnmount'], - '#app': ['definePayloadReviver', 'definePageMeta'] - } + await get('dev') + ? {} + : { + vue: ['onBeforeMount', 'onMounted', 'onBeforeUpdate', 'onRenderTracked', 'onRenderTriggered', 'onActivated', 'onDeactivated', 'onBeforeUnmount'], + '#app': ['definePayloadReviver', 'definePageMeta'] + } ) }, client: { $resolve: async (val, get) => defu(val || {}, - await get('dev') ? {} : { - vue: ['onServerPrefetch', 'onRenderTracked', 'onRenderTriggered'], - '#app': ['definePayloadReducer', 'definePageMeta'] - } + await get('dev') + ? {} + : { + vue: ['onServerPrefetch', 'onRenderTracked', 'onRenderTriggered'], + '#app': ['definePayloadReducer', 'definePageMeta'] + } ) } } diff --git a/packages/schema/src/config/common.ts b/packages/schema/src/config/common.ts index 80df36c583..4311b63880 100644 --- a/packages/schema/src/config/common.ts +++ b/packages/schema/src/config/common.ts @@ -14,7 +14,6 @@ export default defineUntypedSchema({ * You can use `github:`, `gitlab:`, `bitbucket:` or `https://` to extend from a remote git repository. * * @type {string|string[]} - * */ extends: null, @@ -26,7 +25,6 @@ export default defineUntypedSchema({ * You can use `github:`, `gitlab:`, `bitbucket:` or `https://` to extend from a remote git repository. * * @type {string} - * */ theme: null, @@ -170,7 +168,7 @@ export default defineUntypedSchema({ * */ debug: { - $resolve: async (val, get) => val ?? isDebug + $resolve: val => val ?? isDebug }, /** @@ -178,7 +176,7 @@ export default defineUntypedSchema({ * If set to `false` generated pages will have no content. */ ssr: { - $resolve: (val) => val ?? true, + $resolve: val => val ?? true }, /** @@ -191,7 +189,6 @@ export default defineUntypedSchema({ * (in `node_modules`) and then will be resolved from project `srcDir` if `~` alias is used. * * @note Modules are executed sequentially so the order is important. - * * @example * ```js * modules: [ @@ -252,12 +249,12 @@ export default defineUntypedSchema({ * and copied across into your `dist` folder when your app is generated. */ public: { - $resolve: async (val, get) => val || await get('dir.static') || 'public', + $resolve: async (val, get) => val || await get('dir.static') || 'public' }, static: { $schema: { deprecated: 'use `dir.public` option instead' }, - $resolve: async (val, get) => val || await get('dir.public') || 'public', + $resolve: async (val, get) => val || await get('dir.public') || 'public' } }, @@ -274,11 +271,9 @@ export default defineUntypedSchema({ * * @note Within a webpack context (image sources, CSS - but not JavaScript) you _must_ access * your alias by prefixing it with `~`. - * * @note These aliases will be automatically added to the generated `.nuxt/tsconfig.json` so you can get full * type support and path auto-complete. In case you need to extend options provided by `./.nuxt/tsconfig.json` * further, make sure to add them here or within the `typescript.tsConfig` property in `nuxt.config`. - * * @example * ```js * export default { @@ -309,7 +304,6 @@ export default defineUntypedSchema({ * } * * ``` - * * @type {Record} */ alias: { @@ -328,7 +322,6 @@ export default defineUntypedSchema({ * Pass options directly to `node-ignore` (which is used by Nuxt to ignore files). * * @see [node-ignore](https://github.com/kaelzhang/node-ignore) - * * @example * ```js * ignoreOptions: { @@ -343,7 +336,7 @@ export default defineUntypedSchema({ * building if its filename starts with the prefix specified by `ignorePrefix`. */ ignorePrefix: { - $resolve: (val) => val ?? '-', + $resolve: val => val ?? '-' }, /** @@ -372,7 +365,7 @@ export default defineUntypedSchema({ * @type {Array} */ watch: { - $resolve: val => [].concat(val).filter((b: unknown) => typeof b === 'string' || b instanceof RegExp), + $resolve: val => [].concat(val).filter((b: unknown) => typeof b === 'string' || b instanceof RegExp) }, /** @@ -385,7 +378,7 @@ export default defineUntypedSchema({ * `watchOptions` to pass directly to webpack. * * @see [webpack@4 watch options](https://v4.webpack.js.org/configuration/watch/#watchoptions). - * */ + */ webpack: { aggregateTimeout: 1000 }, @@ -464,7 +457,7 @@ export default defineUntypedSchema({ app: { baseURL: (await get('app')).baseURL, buildAssetsDir: (await get('app')).buildAssetsDir, - cdnURL: (await get('app')).cdnURL, + cdnURL: (await get('app')).cdnURL } }) } diff --git a/packages/schema/src/config/dev.ts b/packages/schema/src/config/dev.ts index 5f46df1949..a9bc37d718 100644 --- a/packages/schema/src/config/dev.ts +++ b/packages/schema/src/config/dev.ts @@ -17,10 +17,7 @@ export default defineUntypedSchema({ * } * }) * ``` - * - * * @type {boolean | { key: string; cert: string }} - * */ https: false, @@ -43,6 +40,6 @@ export default defineUntypedSchema({ * * @type {(data: { loading?: string }) => string} */ - loadingTemplate: loadingTemplate + loadingTemplate } }) diff --git a/packages/schema/src/config/experimental.ts b/packages/schema/src/config/experimental.ts index 7bfde625e6..77fade2e49 100644 --- a/packages/schema/src/config/experimental.ts +++ b/packages/schema/src/config/experimental.ts @@ -6,11 +6,12 @@ export default defineUntypedSchema({ * Set to true to generate an async entry point for the Vue bundle (for module federation support). */ asyncEntry: { - $resolve: (val) => val ?? false + $resolve: val => val ?? false }, /** * Enable Vue's reactivity transform + * * @see https://vuejs.org/guide/extras/reactivity-transform.html * * Warning: Reactivity transform feature has been marked as deprecated in Vue 3.3 and is planned to be @@ -23,12 +24,14 @@ export default defineUntypedSchema({ // https://github.com/unjs/nitro/issues/1118 /** * Externalize `vue`, `@vue/*` and `vue-router` when building. + * * @see https://github.com/nuxt/nuxt/issues/13632 */ externalVue: true, /** * Tree shakes contents of client-only components from server bundle. + * * @see https://github.com/nuxt/framework/pull/5750 */ treeshakeClientOnly: true, @@ -47,7 +50,7 @@ export default defineUntypedSchema({ * @type {false | 'manual' | 'automatic'} */ emitRouteChunkError: { - $resolve: val => { + $resolve: (val) => { if (val === true) { return 'manual' } @@ -55,7 +58,7 @@ export default defineUntypedSchema({ return 'automatic' } return val ?? 'automatic' - }, + } }, /** @@ -113,7 +116,7 @@ export default defineUntypedSchema({ /** * Disable vue server renderer endpoint within nitro. - */ + */ noVueServer: false, /** @@ -148,6 +151,7 @@ export default defineUntypedSchema({ /** * Experimental component islands support with and .island.vue files. + * * @type {true | 'local' | 'local+remote' | false} */ componentIslands: { diff --git a/packages/schema/src/config/generate.ts b/packages/schema/src/config/generate.ts index 2ad0b5ad83..9882e6bb9b 100644 --- a/packages/schema/src/config/generate.ts +++ b/packages/schema/src/config/generate.ts @@ -14,14 +14,13 @@ export default defineUntypedSchema({ * ```js * routes: ['/users/1', '/users/2', '/users/3'] * ``` - * * @type {string | string[]} */ routes: [], /** * This option is no longer used. Instead, use `nitro.prerender.ignore`. - * + * * @deprecated */ exclude: [] diff --git a/packages/schema/src/config/nitro.ts b/packages/schema/src/config/nitro.ts index 5e1a79cb76..359ce18461 100644 --- a/packages/schema/src/config/nitro.ts +++ b/packages/schema/src/config/nitro.ts @@ -5,7 +5,6 @@ export default defineUntypedSchema({ * Configuration for Nitro. * * @see https://nitro.unjs.io/config/ - * * @type {typeof import('nitropack')['NitroConfig']} */ nitro: { @@ -21,9 +20,7 @@ export default defineUntypedSchema({ * Global route options applied to matching server routes. * * @experimental This is an experimental feature and API may change in the future. - * * @see https://nitro.unjs.io/config/#routerules - * * @type {typeof import('nitropack')['NitroConfig']['routeRules']} */ routeRules: {}, @@ -39,16 +36,13 @@ export default defineUntypedSchema({ * - lazy: Specifies whether to use lazy loading to import the handler. * * @see https://nuxt.com/docs/guide/directory-structure/server - * * @note Files from `server/api`, `server/middleware` and `server/routes` will be automatically registered by Nuxt. - * * @example * ```js * serverHandlers: [ * { route: '/path/foo/**:name', handler: '~/server/foohandler.ts' } * ] * ``` - * * @type {typeof import('nitropack')['NitroEventHandler'][]} */ serverHandlers: [], @@ -57,7 +51,6 @@ export default defineUntypedSchema({ * Nitro development-only server handlers. * * @see https://nitro.unjs.io/guide/routing - * * @type {typeof import('nitropack')['NitroDevEventHandler'][]} */ devServerHandlers: [] diff --git a/packages/schema/src/config/postcss.ts b/packages/schema/src/config/postcss.ts index ee9439724e..29effcd4dd 100644 --- a/packages/schema/src/config/postcss.ts +++ b/packages/schema/src/config/postcss.ts @@ -8,6 +8,7 @@ export default defineUntypedSchema({ * Options for configuring PostCSS plugins. * * https://postcss.org/ + * * @type {Record} */ plugins: { @@ -15,16 +16,18 @@ export default defineUntypedSchema({ * https://github.com/postcss/postcss-import */ 'postcss-import': { - $resolve: async (val, get) => val !== false ? defu(val || {}, { - resolve: createResolver({ - alias: { ...(await get('alias')) }, - modules: [ - await get('srcDir'), - await get('rootDir'), - ...(await get('modulesDir')) - ] + $resolve: async (val, get) => val !== false + ? defu(val || {}, { + resolve: createResolver({ + alias: { ...(await get('alias')) }, + modules: [ + await get('srcDir'), + await get('rootDir'), + ...(await get('modulesDir')) + ] + }) }) - }) : val, + : val }, /** diff --git a/packages/schema/src/config/router.ts b/packages/schema/src/config/router.ts index 3f10c1ceb0..279a609c87 100644 --- a/packages/schema/src/config/router.ts +++ b/packages/schema/src/config/router.ts @@ -11,7 +11,6 @@ export default defineUntypedSchema({ * * @see [documentation](https://router.vuejs.org/api/interfaces/routeroptions.html). * @type {typeof import('../src/types/router').RouterConfigSerializable} - * */ options: {} } diff --git a/packages/schema/src/config/typescript.ts b/packages/schema/src/config/typescript.ts index 5bf18adc5e..29b7886eda 100644 --- a/packages/schema/src/config/typescript.ts +++ b/packages/schema/src/config/typescript.ts @@ -24,7 +24,7 @@ export default defineUntypedSchema({ * @type {'vite' | 'webpack' | 'shared' | false | undefined} */ builder: { - $resolve: async (val, get) => val ?? null + $resolve: val => val ?? null }, /** @@ -39,13 +39,13 @@ export default defineUntypedSchema({ * Requires to install `typescript` and `vue-tsc` as dev dependencies. * * @see https://nuxt.com/docs/guide/concepts/typescript - * * @type {boolean | 'build'} */ typeCheck: false, /** * You can extend generated `.nuxt/tsconfig.json` using this option. + * * @type {typeof import('pkg-types')['TSConfig']} */ tsConfig: {}, diff --git a/packages/schema/src/config/vite.ts b/packages/schema/src/config/vite.ts index a991a654a2..1d6defd7ac 100644 --- a/packages/schema/src/config/vite.ts +++ b/packages/schema/src/config/vite.ts @@ -48,11 +48,11 @@ export default defineUntypedSchema({ }, script: { propsDestructure: { - $resolve: async (val, get) => val ?? Boolean((await get('vue')).propsDestructure), + $resolve: async (val, get) => val ?? Boolean((await get('vue')).propsDestructure) }, defineModel: { - $resolve: async (val, get) => val ?? Boolean((await get('vue')).defineModel), - }, + $resolve: async (val, get) => val ?? Boolean((await get('vue')).defineModel) + } } }, vueJsx: { diff --git a/packages/schema/src/config/webpack.ts b/packages/schema/src/config/webpack.ts index 4621e5909d..f8938ddda6 100644 --- a/packages/schema/src/config/webpack.ts +++ b/packages/schema/src/config/webpack.ts @@ -65,7 +65,6 @@ export default defineUntypedSchema({ * Extracting into multiple CSS files is better for caching and preload isolation. It * can also improve page performance by downloading and resolving only those resources * that are needed. - * * @example * ```js * export default { @@ -113,14 +112,12 @@ export default defineUntypedSchema({ * as most browsers will cache the asset and not detect the changes on first load. * * This example changes fancy chunk names to numerical ids: - * * @example * ```js * filenames: { * chunk: ({ isDev }) => (isDev ? '[name].js' : '[id].[contenthash].js') * } * ``` - * * @type { * Record< * string, @@ -140,8 +137,8 @@ export default defineUntypedSchema({ * } */ filenames: { - app: ({ isDev }: { isDev: boolean }) => isDev ? `[name].js` : `[contenthash:7].js`, - chunk: ({ isDev }: { isDev: boolean }) => isDev ? `[name].js` : `[contenthash:7].js`, + app: ({ isDev }: { isDev: boolean }) => isDev ? '[name].js' : '[contenthash:7].js', + chunk: ({ isDev }: { isDev: boolean }) => isDev ? '[name].js' : '[contenthash:7].js', css: ({ isDev }: { isDev: boolean }) => isDev ? '[name].css' : 'css/[contenthash:7].css', img: ({ isDev }: { isDev: boolean }) => isDev ? '[path][name].[ext]' : 'img/[name].[contenthash:7].[ext]', font: ({ isDev }: { isDev: boolean }) => isDev ? '[path][name].[ext]' : 'fonts/[name].[contenthash:7].[ext]', @@ -168,14 +165,15 @@ export default defineUntypedSchema({ /** * See https://github.com/esbuild-kit/esbuild-loader + * * @type {Omit} - */ + */ esbuild: {}, /** * See: https://github.com/webpack-contrib/file-loader#options - * @type {Omit} * + * @type {Omit} * @default * ```ts * { esModule: false } @@ -185,8 +183,8 @@ export default defineUntypedSchema({ /** * See: https://github.com/webpack-contrib/file-loader#options - * @type {Omit} * + * @type {Omit} * @default * ```ts * { esModule: false, limit: 1000 } @@ -196,8 +194,8 @@ export default defineUntypedSchema({ /** * See: https://github.com/webpack-contrib/file-loader#options - * @type {Omit} * + * @type {Omit} * @default * ```ts * { esModule: false, limit: 1000 } @@ -207,12 +205,14 @@ export default defineUntypedSchema({ /** * See: https://pugjs.org/api/reference.html#options + * * @type {typeof import('pug')['Options']} */ pugPlain: {}, /** * See [vue-loader](https://github.com/vuejs/vue-loader) for available options. + * * @type {Partial} */ vue: { @@ -224,13 +224,13 @@ export default defineUntypedSchema({ }, compilerOptions: { $resolve: async (val, get) => val ?? (await get('vue.compilerOptions')) }, propsDestructure: { $resolve: async (val, get) => val ?? Boolean(await get('vue.propsDestructure')) }, - defineModel: { $resolve: async (val, get) => val ?? Boolean(await get('vue.defineModel')) }, + defineModel: { $resolve: async (val, get) => val ?? Boolean(await get('vue.defineModel')) } }, css: { importLoaders: 0, url: { - filter: (url: string, resourcePath: string) => !url.startsWith('/'), + filter: (url: string, _resourcePath: string) => !url.startsWith('/') }, esModule: false }, @@ -238,7 +238,7 @@ export default defineUntypedSchema({ cssModules: { importLoaders: 0, url: { - filter: (url: string, resourcePath: string) => !url.startsWith('/'), + filter: (url: string, _resourcePath: string) => !url.startsWith('/') }, esModule: false, modules: { @@ -253,8 +253,8 @@ export default defineUntypedSchema({ /** * See: https://github.com/webpack-contrib/sass-loader#options + * * @type {typeof import('sass-loader')['Options']} - * * @default * ```ts * { @@ -272,6 +272,7 @@ export default defineUntypedSchema({ /** * See: https://github.com/webpack-contrib/sass-loader#options + * * @type {typeof import('sass-loader')['Options']} */ scss: {}, @@ -312,7 +313,6 @@ export default defineUntypedSchema({ * Defaults to true when `extractCSS` is enabled. * * @see [css-minimizer-webpack-plugin documentation](https://github.com/webpack-contrib/css-minimizer-webpack-plugin). - * * @type {false | typeof import('css-minimizer-webpack-plugin').BasePluginOptions & typeof import('css-minimizer-webpack-plugin').DefinedDefaultMinimizerAndOptions} */ optimizeCSS: { @@ -321,6 +321,7 @@ export default defineUntypedSchema({ /** * Configure [webpack optimization](https://webpack.js.org/configuration/optimization/). + * * @type {false | typeof import('webpack').Configuration['optimization']} */ optimization: { @@ -350,11 +351,12 @@ export default defineUntypedSchema({ plugins: { $resolve: async (val, get) => val ?? (await get('postcss.plugins')) } - }, + } }, /** * See [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) for available options. + * * @type {typeof import('webpack-dev-middleware').Options} */ devMiddleware: { @@ -363,6 +365,7 @@ export default defineUntypedSchema({ /** * See [webpack-hot-middleware](https://github.com/webpack-contrib/webpack-hot-middleware) for available options. + * * @type {typeof import('webpack-hot-middleware').MiddlewareOptions & { client?: typeof import('webpack-hot-middleware').ClientOptions }} */ hotMiddleware: {}, @@ -374,12 +377,14 @@ export default defineUntypedSchema({ /** * Filters to hide build warnings. + * * @type {Array<(warn: typeof import('webpack').WebpackError) => boolean>} */ warningIgnoreFilters: [], /** * Configure [webpack experiments](https://webpack.js.org/configuration/experiments/) + * * @type {false | typeof import('webpack').Configuration['experiments']} */ experiments: {} diff --git a/packages/schema/src/index.ts b/packages/schema/src/index.ts index 8178924cfb..eebdb6e56b 100644 --- a/packages/schema/src/index.ts +++ b/packages/schema/src/index.ts @@ -1,4 +1,3 @@ - // Types export * from './types/compatibility' export * from './types/components' diff --git a/packages/schema/src/types/compatibility.ts b/packages/schema/src/types/compatibility.ts index dabc01b1f0..63fe1d7fd9 100644 --- a/packages/schema/src/types/compatibility.ts +++ b/packages/schema/src/types/compatibility.ts @@ -3,7 +3,6 @@ export interface NuxtCompatibility { * Required nuxt version in semver format. * * @example `^2.14.0` or `>=3.0.0-27219851.6e49637`. - * */ nuxt?: string @@ -12,7 +11,7 @@ export interface NuxtCompatibility { * * - `true`: When using Nuxt 2, using bridge module is required. * - `false`: When using Nuxt 2, using bridge module is not supported. - */ + */ bridge?: boolean } diff --git a/packages/schema/src/types/config.ts b/packages/schema/src/types/config.ts index a3ae4a3650..cdfd08a68b 100644 --- a/packages/schema/src/types/config.ts +++ b/packages/schema/src/types/config.ts @@ -1,12 +1,12 @@ import type { KeepAliveProps, TransitionProps } from 'vue' -import type { ConfigSchema } from '../../schema/config' import type { ServerOptions as ViteServerOptions, UserConfig as ViteUserConfig } from 'vite' import type { Options as VuePluginOptions } from '@vitejs/plugin-vue' import type { Options as VueJsxPluginOptions } from '@vitejs/plugin-vue-jsx' -import type { AppHeadMetaObject } from './head' -import type { Nuxt } from './nuxt' import type { SchemaDefinition } from 'untyped' import type { NitroRuntimeConfig, NitroRuntimeConfigApp } from 'nitropack' +import type { ConfigSchema } from '../../schema/config' +import type { Nuxt } from './nuxt' +import type { AppHeadMetaObject } from './head' export type { SchemaDefinition } from 'untyped' type DeepPartial = T extends Function ? T : T extends Record ? { [P in keyof T]?: DeepPartial } : T @@ -63,22 +63,35 @@ type Overrideable, Path extends string = ''> = { : never } -/** User configuration in `nuxt.config` file */ -export interface NuxtConfig extends DeepPartial> { - // Avoid DeepPartial for vite config interface (#4772) - vite?: ConfigSchema['vite'] - runtimeConfig?: Overrideable - webpack?: DeepPartial & { - $client?: DeepPartial - $server?: DeepPartial - } +// Runtime Config - /** - * Experimental custom config schema - * - * @see https://github.com/nuxt/nuxt/issues/15592 - */ - $schema?: SchemaDefinition +type RuntimeConfigNamespace = Record + +export interface PublicRuntimeConfig extends RuntimeConfigNamespace { } + +export interface RuntimeConfig extends RuntimeConfigNamespace { + app: NitroRuntimeConfigApp + /** Only available on the server. */ + nitro?: NitroRuntimeConfig['nitro'] + public: PublicRuntimeConfig +} + +// User configuration in `nuxt.config` file +export interface NuxtConfig extends DeepPartial> { + // Avoid DeepPartial for vite config interface (#4772) + vite?: ConfigSchema['vite'] + runtimeConfig?: Overrideable + webpack?: DeepPartial & { + $client?: DeepPartial + $server?: DeepPartial + } + + /** + * Experimental custom config schema + * + * @see https://github.com/nuxt/nuxt/issues/15592 + */ + $schema?: SchemaDefinition } // TODO: Expose ConfigLayer from c12 @@ -92,7 +105,11 @@ export type NuxtConfigLayer = ConfigLayer -/** Normalized Nuxt options available as `nuxt.options.*` */ +export interface NuxtBuilder { + bundle: (nuxt: Nuxt) => Promise +} + +// Normalized Nuxt options available as `nuxt.options.*` export interface NuxtOptions extends Omit { sourcemap: Required> builder: '@nuxt/vite-builder' | '@nuxt/webpack-builder' | NuxtBuilder @@ -104,27 +121,26 @@ export interface NuxtOptions extends Omit { $schema: SchemaDefinition } -export interface NuxtBuilder { - bundle: (nuxt: Nuxt) => Promise -} - export interface ViteConfig extends Omit { /** The path to the entrypoint for the Vite build. */ entry?: string /** * Options passed to @vitejs/plugin-vue. + * * @see https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue */ vue?: VuePluginOptions /** * Options passed to @vitejs/plugin-vue-jsx. + * * @see https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx */ vueJsx?: VueJsxPluginOptions /** * Bundler for dev time server-side rendering. + * * @default 'vite-node' */ devBundler?: 'vite-node' | 'legacy' @@ -148,22 +164,7 @@ export interface ViteConfig extends Omit { publicDir?: never } - -// -- Runtime Config -- - -type RuntimeConfigNamespace = Record - -export interface PublicRuntimeConfig extends RuntimeConfigNamespace { } - -export interface RuntimeConfig extends RuntimeConfigNamespace { - app: NitroRuntimeConfigApp - /** Only available on the server. */ - nitro?: NitroRuntimeConfig['nitro'] - public: PublicRuntimeConfig -} - -// -- App Config -- - +// App Config export interface CustomAppConfig { [key: string]: unknown } diff --git a/packages/schema/src/types/hooks.ts b/packages/schema/src/types/hooks.ts index 6bd5fc3a91..99d727939b 100644 --- a/packages/schema/src/types/hooks.ts +++ b/packages/schema/src/types/hooks.ts @@ -1,17 +1,17 @@ -import type { TSConfig } from 'pkg-types' import type { Server as HttpServer } from 'node:http' import type { Server as HttpsServer } from 'node:https' +import type { TSConfig } from 'pkg-types' import type { ViteDevServer } from 'vite' import type { Manifest } from 'vue-bundle-renderer' import type { EventHandler } from 'h3' import type { Import, InlinePreset, Unimport } from 'unimport' import type { Compiler, Configuration, Stats } from 'webpack' -import type { Nuxt, NuxtApp, ResolvedNuxtTemplate } from './nuxt' import type { Nitro, NitroConfig } from 'nitropack' -import type { Component, ComponentsOptions } from './components' -import type { NuxtCompatibility, NuxtCompatibilityIssues, ViteConfig } from '..' import type { Schema, SchemaDefinition } from 'untyped' import type { RouteLocationRaw } from 'vue-router' +import type { NuxtCompatibility, NuxtCompatibilityIssues, ViteConfig } from '..' +import type { Component, ComponentsOptions } from './components' +import type { Nuxt, NuxtApp, ResolvedNuxtTemplate } from './nuxt' export type HookResult = Promise | void @@ -65,6 +65,7 @@ export interface NuxtHooks { // Kit /** * Allows extending compatibility checks. + * * @param compatibility Compatibility object * @param issues Issues to be mapped * @returns Promise @@ -74,18 +75,21 @@ export interface NuxtHooks { // Nuxt /** * Called after Nuxt initialization, when the Nuxt instance is ready to work. + * * @param nuxt The configured Nuxt object * @returns Promise */ 'ready': (nuxt: Nuxt) => HookResult /** * Called when Nuxt instance is gracefully closing. + * * @param nuxt The configured Nuxt object * @returns Promise */ 'close': (nuxt: Nuxt) => HookResult /** * Called to restart the current Nuxt instance. + * * @returns Promise */ 'restart': (options?: { @@ -97,29 +101,34 @@ export interface NuxtHooks { /** * Called during Nuxt initialization, before installing user modules. + * * @returns Promise */ 'modules:before': () => HookResult /** * Called during Nuxt initialization, after installing user modules. + * * @returns Promise */ 'modules:done': () => HookResult /** * Called after resolving the `app` instance. + * * @param app The resolved `NuxtApp` object * @returns Promise */ 'app:resolve': (app: NuxtApp) => HookResult /** * Called during `NuxtApp` generation, to allow customizing, modifying or adding new files to the build directory (either virtually or to written to `.nuxt`). + * * @param app The configured `NuxtApp` object * @returns Promise */ 'app:templates': (app: NuxtApp) => HookResult /** * Called after templates are compiled into the [virtual file system](https://nuxt.com/docs/guide/directory-structure/nuxt#virtual-file-system) (vfs). + * * @param app The configured `NuxtApp` object * @returns Promise */ @@ -127,16 +136,19 @@ export interface NuxtHooks { /** * Called before Nuxt bundle builder. + * * @returns Promise */ 'build:before': () => HookResult /** * Called after Nuxt bundle builder is complete. + * * @returns Promise */ 'build:done': () => HookResult /** * Called during the manifest build by Vite and Webpack. This allows customizing the manifest that Nitro will use to render `