From 92f81e01e716b7e3ce75c325db1ac63de2dcac43 Mon Sep 17 00:00:00 2001 From: Kevin Marrec Date: Mon, 4 Mar 2019 07:48:40 +0100 Subject: [PATCH] feat(ts): nuxt configuration typedefs (#4854) --- examples/typescript-vuex/nuxt.config.ts | 4 +- examples/typescript/nuxt.config.ts | 6 +- packages/config/package.json | 4 +- packages/config/types/build.d.ts | 63 +++++++ packages/config/types/env.d.ts | 6 + packages/config/types/fetch.d.ts | 9 + packages/config/types/generate.d.ts | 19 ++ packages/config/types/globals.d.ts | 7 + packages/config/types/head.d.ts | 9 + packages/config/types/hooks.d.ts | 50 ++++++ packages/config/types/index.d.ts | 92 ++++++++++ packages/config/types/loading.d.ts | 27 +++ packages/config/types/module.d.ts | 9 + packages/config/types/plugin.d.ts | 7 + packages/config/types/render.d.ts | 27 +++ packages/config/types/router.d.ts | 16 ++ packages/config/types/server-middleware.d.ts | 8 + packages/config/types/server.d.ts | 15 ++ packages/config/types/vue-configuration.d.ts | 9 + packages/config/types/watchers.d.ts | 14 ++ packages/typescript/package.json | 12 ++ packages/vue-app/types/index.d.ts | 109 ++++++------ packages/vue-app/types/process.d.ts | 12 +- packages/vue-app/types/vue.d.ts | 36 ++-- test/fixtures/typescript/nuxt.config.ts | 4 +- test/types/tsconfig.json | 10 +- yarn.lock | 178 +++++++++++++++++++ 27 files changed, 674 insertions(+), 88 deletions(-) create mode 100644 packages/config/types/build.d.ts create mode 100644 packages/config/types/env.d.ts create mode 100644 packages/config/types/fetch.d.ts create mode 100644 packages/config/types/generate.d.ts create mode 100644 packages/config/types/globals.d.ts create mode 100644 packages/config/types/head.d.ts create mode 100644 packages/config/types/hooks.d.ts create mode 100644 packages/config/types/index.d.ts create mode 100644 packages/config/types/loading.d.ts create mode 100644 packages/config/types/module.d.ts create mode 100644 packages/config/types/plugin.d.ts create mode 100644 packages/config/types/render.d.ts create mode 100644 packages/config/types/router.d.ts create mode 100644 packages/config/types/server-middleware.d.ts create mode 100644 packages/config/types/server.d.ts create mode 100644 packages/config/types/vue-configuration.d.ts create mode 100644 packages/config/types/watchers.d.ts diff --git a/examples/typescript-vuex/nuxt.config.ts b/examples/typescript-vuex/nuxt.config.ts index 985fb1eece..0f720db64f 100644 --- a/examples/typescript-vuex/nuxt.config.ts +++ b/examples/typescript-vuex/nuxt.config.ts @@ -1,4 +1,6 @@ -const config = { +import NuxtConfiguration from '@nuxt/config-edge' + +const config: NuxtConfiguration = { head: { title: 'starter', meta: [ diff --git a/examples/typescript/nuxt.config.ts b/examples/typescript/nuxt.config.ts index f33d7c4e6e..5e5b1ae490 100644 --- a/examples/typescript/nuxt.config.ts +++ b/examples/typescript/nuxt.config.ts @@ -1,3 +1,7 @@ -export default { +import NuxtConfiguration from '@nuxt/config-edge' + +const config: NuxtConfiguration = { plugins: ['~/plugins/hello'] } + +export default config diff --git a/packages/config/package.json b/packages/config/package.json index 83d471ca7a..4d52820519 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -4,9 +4,11 @@ "repository": "nuxt/nuxt.js", "license": "MIT", "files": [ - "dist" + "dist", + "types/*.d.ts" ], "main": "dist/config.js", + "typings": "types/index.d.ts", "dependencies": { "@nuxt/utils": "2.4.5", "consola": "^2.5.6", diff --git a/packages/config/types/build.d.ts b/packages/config/types/build.d.ts new file mode 100644 index 0000000000..3325cf1bea --- /dev/null +++ b/packages/config/types/build.d.ts @@ -0,0 +1,63 @@ +/** + * NuxtConfigurationBuild + * Documentation: https://nuxtjs.org/api/configuration-build + */ + +import { + Configuration as WebpackConfiguration, + Options as WebpackOptions, + Plugin as WebpackPlugin +} from 'webpack' +import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' +import { Options as WebpackDevMiddlewareOptions } from 'webpack-dev-middleware' +import { Options as WebpackHotMiddlewareOptions } from 'webpack-hot-middleware' +import { Options as HtmlMinifierOptions } from 'html-minifier' +import { Options as OptimizeCssAssetsWebpackPluginOptions } from 'optimize-css-assets-webpack-plugin' +import { TerserPluginOptions } from 'terser-webpack-plugin' + +type NuxtConfigurationLoaders = any // TBD + +export interface NuxtConfigurationBuild { + analyze?: BundleAnalyzerPlugin.Options | boolean + babel?: any // TBD + cache?: boolean + crossorigin?: string + cssSourceMap?: boolean + devMiddleware?: WebpackDevMiddlewareOptions + devtools?: boolean + extend?( + config: WebpackConfiguration, + ctx: { + isDev: boolean, + isClient: boolean, + isServer: boolean, + loaders: NuxtConfigurationLoaders + } + ): void + extractCSS?: boolean + filenames?: { [key in 'app' | 'chunk' | 'css' | 'img' | 'font' | 'video']?: (ctx: { isDev: boolean }) => string } + friendlyErrors?: boolean + hardSource?: boolean + hotMiddleware?: WebpackHotMiddlewareOptions + html?: { minify: HtmlMinifierOptions } + loaders?: NuxtConfigurationLoaders + optimization?: WebpackOptions.Optimization + optimizeCSS?: OptimizeCssAssetsWebpackPluginOptions | boolean + parallel?: boolean + plugins?: WebpackPlugin[] + postcss?: any // TBD + profile?: boolean + publicPath?: string + quiet?: boolean + splitChunks?: { + commons?: boolean + layouts?: boolean + pages?: boolean + } + ssr?: boolean + templates?: any + terser?: TerserPluginOptions | boolean + transpile?: (string | RegExp)[] + useForkTsChecker?: { [key: string]: string } | boolean // TBD - Couldn't find typedefs for the forkTsCheckerWebpackPlugin options + watch?: string[] +} diff --git a/packages/config/types/env.d.ts b/packages/config/types/env.d.ts new file mode 100644 index 0000000000..42d83c86e2 --- /dev/null +++ b/packages/config/types/env.d.ts @@ -0,0 +1,6 @@ +/** + * NuxtConfigurationEnv + * Documentation: https://nuxtjs.org/api/configuration-env + */ + +export type NuxtConfigurationEnv = { [key: string]: string } diff --git a/packages/config/types/fetch.d.ts b/packages/config/types/fetch.d.ts new file mode 100644 index 0000000000..0860e01ebb --- /dev/null +++ b/packages/config/types/fetch.d.ts @@ -0,0 +1,9 @@ +/** + * NuxtConfigurationFetch + * Documentation: ? + */ + +export interface NuxtConfigurationFetch { + client?: boolean + server?: boolean +} diff --git a/packages/config/types/generate.d.ts b/packages/config/types/generate.d.ts new file mode 100644 index 0000000000..2adf9eb0e1 --- /dev/null +++ b/packages/config/types/generate.d.ts @@ -0,0 +1,19 @@ +/** + * NuxtConfigurationGenerate + * Documentation: https://nuxtjs.org/api/configuration-generate + */ + +type NuxtConfigurationGenerateRoute = string | { route: string, payload: any } + +type NuxtConfigurationGenerateRoutesFunction = () => (Promise | NuxtConfigurationGenerateRoute[]) +type NuxtConfigurationGenerateRoutesFunctionWithCallback = (callback: (err: Error, routes: NuxtConfigurationGenerateRoute[]) => void) => void + +export interface NuxtConfigurationGenerate { + concurrency?: number + devtools?: boolean + dir?: string + fallback?: string | boolean + interval?: number + routes?: NuxtConfigurationGenerateRoute[] | NuxtConfigurationGenerateRoutesFunction | NuxtConfigurationGenerateRoutesFunctionWithCallback + subFolders?: boolean +} diff --git a/packages/config/types/globals.d.ts b/packages/config/types/globals.d.ts new file mode 100644 index 0000000000..624be78c1e --- /dev/null +++ b/packages/config/types/globals.d.ts @@ -0,0 +1,7 @@ +/** + * NuxtConfigurationGlobals + * Documentation: https://nuxtjs.org/api/configuration-globals + */ + +type NuxtConfigurationCustomizableGlobalName = 'id' | 'nuxt' | 'context' | 'pluginPrefix' | 'readyCallback' | 'loadedCallback' +export type NuxtConfigurationGlobals = { [key in NuxtConfigurationCustomizableGlobalName]?: (globalName: string) => string } diff --git a/packages/config/types/head.d.ts b/packages/config/types/head.d.ts new file mode 100644 index 0000000000..57d5658e5e --- /dev/null +++ b/packages/config/types/head.d.ts @@ -0,0 +1,9 @@ +/** + * NuxtConfigurationHead + * Documentation: https://nuxtjs.org/api/configuration-head + * https://github.com/declandewet/vue-meta#recognized-metainfo-properties + */ + +import { MetaInfo } from 'vue-meta' + +export type NuxtConfigurationHead = MetaInfo diff --git a/packages/config/types/hooks.d.ts b/packages/config/types/hooks.d.ts new file mode 100644 index 0000000000..0593007758 --- /dev/null +++ b/packages/config/types/hooks.d.ts @@ -0,0 +1,50 @@ +/** + * NuxtConfigurationHooks + * Documentation: https://nuxtjs.org/api/configuration-hooks + * https://nuxtjs.org/api/internals-nuxt#hooks + * https://nuxtjs.org/api/internals-renderer#hooks + * https://nuxtjs.org/api/internals-module-container#hooks + * https://nuxtjs.org/api/internals-builder#hooks + * https://nuxtjs.org/api/internals-generator#hooks + */ + +export interface NuxtConfigurationHooks { + build?: { + before?(builder: any, buildOptions: any): void + compile?(params: { name: 'client' | 'server', compiler: any }): void + compiled?(params: { name: 'client' | 'server', compiler: any, stats: any }): void + done?(builder: any): void + extendRoutes?(routes: any, resolve: any): void + templates?(params: { templateFiles: any, templateVars: any, resolve: any }): void + } + close?(nuxt: any): void + error?(error: Error): void + generate?: { + before?(generator: any, generateOptions: any): void + distCopied?(generator: any): void + distRemoved?(generator: any): void + done?(generator: any): void + extendRoutes?(routes: any): void + page?(params: { route: any, path: any, html: any }): void + routeCreated?(route: any, path: any, errors: any): void + routeFailed?(route: any, errors: any): void + } + listen?(server: any, params: { host: string, port: number | string }): void + modules?: { + before?(moduleContainer: any, options: any): void + done?(moduleContainer: any): void + } + ready?(nuxt: any): void + render?: { + before?(renderer: any, options: any): void + done?(renderer: any): void + errorMiddleware?(app: any): void + resourcesLoaded?(resources: any): void + route?(url: string, result: any, context: any): void + routeContext?(context: any): void + routeDone?(url: string, result: any, context: any): void + setupMiddleware?(app: any): void + } +} + +// Hooks need too many core typedefs to be 100% defined diff --git a/packages/config/types/index.d.ts b/packages/config/types/index.d.ts new file mode 100644 index 0000000000..4649988ff9 --- /dev/null +++ b/packages/config/types/index.d.ts @@ -0,0 +1,92 @@ +import { NuxtConfigurationBuild } from './build' +import { NuxtConfigurationEnv } from './env' +import { NuxtConfigurationFetch } from './fetch' +import { NuxtConfigurationGenerate } from './generate' +import { NuxtConfigurationHead } from './head' +import { NuxtConfigurationHooks } from './hooks' +import { NuxtConfigurationGlobals } from './globals' +import { NuxtConfigurationLoading, NuxtConfigurationLoadingIndicator } from './loading' +import { NuxtConfigurationModule } from './module' +import { NuxtConfigurationPlugin } from './plugin' +import { NuxtConfigurationRender } from './render' +import { NuxtConfigurationRouter } from './router' +import { NuxtConfigurationServer } from './server' +import { NuxtConfigurationServerMiddleware } from './server-middleware' +import { NuxtConfigurationVueConfiguration } from './vue-configuration' +import { NuxtConfigurationWatchers } from './watchers' + +type ExtendableConfiguration = { [key: string]: any } + +export default interface NuxtConfiguration extends ExtendableConfiguration { + build?: NuxtConfigurationBuild + buildDir?: string + css?: string[] + dev?: boolean + env?: NuxtConfigurationEnv + fetch?: NuxtConfigurationFetch + generate?: NuxtConfigurationGenerate + globalName?: string + globals?: NuxtConfigurationGlobals + head?: NuxtConfigurationHead + hooks?: NuxtConfigurationHooks + ignorePrefix?: string + ignore?: string[] + layoutTransition?: any // TBD - should be of type `Transition` already defined in @nuxt/vue-app + loading?: NuxtConfigurationLoading | false | string + loadingIndicator?: NuxtConfigurationLoadingIndicator | false | string + mode?: 'spa' | 'universal' // TBR (To Be Reviewed) - should be a `NuxtMode` interface which should be used in @nuxt/vue-app/types/process.d.ts as well + modern?: 'client' | 'server' | boolean + modules?: NuxtConfigurationModule[] + modulesDir?: string[] + plugins?: NuxtConfigurationPlugin[] + render?: NuxtConfigurationRender + rootDir?: string + router?: NuxtConfigurationRouter + server?: NuxtConfigurationServer + serverMiddleware?: NuxtConfigurationServerMiddleware[] + srcDir?: string + transition?: any // TBD - should be of type `Transition` already defined in @nuxt/vue-app + 'vue.config'?: NuxtConfigurationVueConfiguration + watch?: string[] + watchers?: NuxtConfigurationWatchers +} + +export { + NuxtConfigurationBuild as Build, + NuxtConfigurationEnv as Env, + NuxtConfigurationFetch as Fetch, + NuxtConfigurationGenerate as Generate, + NuxtConfigurationHead as Head, + NuxtConfigurationHooks as Hooks, + NuxtConfigurationGlobals as Globals, + NuxtConfigurationLoading as Loading, + NuxtConfigurationLoadingIndicator as LoadingIndicator, + NuxtConfigurationModule as Module, + NuxtConfigurationPlugin as Plugin, + NuxtConfigurationRender as Render, + NuxtConfigurationRouter as Router, + NuxtConfigurationServer as Server, + NuxtConfigurationServerMiddleware as ServerMiddleware, + NuxtConfigurationVueConfiguration as VueConfiguration, + NuxtConfigurationWatchers as Watchers +} + +export namespace NuxtConfiguration { + export type Build = NuxtConfigurationBuild + export type Env = NuxtConfigurationEnv + export type Fetch = NuxtConfigurationFetch + export type Generate = NuxtConfigurationGenerate + export type Head = NuxtConfigurationHead + export type Hooks = NuxtConfigurationHooks + export type Globals = NuxtConfigurationGlobals + export type Loading = NuxtConfigurationLoading + export type LoadingIndicator = NuxtConfigurationLoadingIndicator + export type Module = NuxtConfigurationModule + export type Plugin = NuxtConfigurationPlugin + export type Render = NuxtConfigurationRender + export type Router = NuxtConfigurationRouter + export type Server = NuxtConfigurationServer + export type ServerMiddleware = NuxtConfigurationServerMiddleware + export type VueConfiguration = NuxtConfigurationVueConfiguration + export type Watchers = NuxtConfigurationWatchers +} diff --git a/packages/config/types/loading.d.ts b/packages/config/types/loading.d.ts new file mode 100644 index 0000000000..b3d70615c2 --- /dev/null +++ b/packages/config/types/loading.d.ts @@ -0,0 +1,27 @@ +/** + * NuxtConfigurationLoading + * Documentation: https://nuxtjs.org/api/configuration-loading + */ + +export interface NuxtConfigurationLoading { + color?: string + continuous?: boolean + css?: boolean + duration?: number + failedColor?: string + height?: string + rtl?: boolean + throttle?: number +} + +/** + * NuxtConfigurationLoadingIndicator + * Documentation: https://nuxtjs.org/api/configuration-loading-indicator + */ + +export interface NuxtConfigurationLoadingIndicator { + background?: string + color?: string + color2?: string + name?: string +} diff --git a/packages/config/types/module.d.ts b/packages/config/types/module.d.ts new file mode 100644 index 0000000000..28416a59eb --- /dev/null +++ b/packages/config/types/module.d.ts @@ -0,0 +1,9 @@ +/** + * NuxtConfigurationModule + * Documentation: https://nuxtjs.org/api/configuration-modules + * https://nuxtjs.org/guide/modules + */ + +type NuxtConfigurationModuleFunction = (this: any, moduleOptions?: { [key: string]: any }) => Promise | void // this, this.options & this.nuxt TBD + +export type NuxtConfigurationModule = string | [string, { [key: string]: any }] | NuxtConfigurationModuleFunction diff --git a/packages/config/types/plugin.d.ts b/packages/config/types/plugin.d.ts new file mode 100644 index 0000000000..9db8ff2423 --- /dev/null +++ b/packages/config/types/plugin.d.ts @@ -0,0 +1,7 @@ +/** + * NuxtConfigurationPlugin + * Documentation: https://nuxtjs.org/api/configuration-plugins + * https://nuxtjs.org/guide/plugins + */ + +export type NuxtConfigurationPlugin = { mode?: 'all' | 'client' | 'server', src: string, ssr?: boolean } | string diff --git a/packages/config/types/render.d.ts b/packages/config/types/render.d.ts new file mode 100644 index 0000000000..4a067614f5 --- /dev/null +++ b/packages/config/types/render.d.ts @@ -0,0 +1,27 @@ +/** + * NuxtConfigurationRender + * Documentation: https://nuxtjs.org/api/configuration-render + * https://ssr.vuejs.org/api/#renderer-options + * https://github.com/expressjs/compression#readme + * https://github.com/expressjs/serve-static#readme + * https://github.com/jshttp/etag#readme + */ + +import { CompressionOptions } from 'compression' +import { Options as EtagOptions } from 'etag' +import { ServeStaticOptions } from 'serve-static' +import { BundleRendererOptions } from 'vue-server-renderer' +import { NuxtConfigurationServerMiddleware } from './index' + +export interface NuxtConfigurationRender { + bundleRenderer?: BundleRendererOptions + compressor?: CompressionOptions | NuxtConfigurationServerMiddleware + csp?: any // TBD + dist?: ServeStaticOptions + etag?: EtagOptions | false + fallback?: any // https://github.com/nuxt/serve-placeholder types TBD + http2?: any // TBD + resourceHints?: boolean + ssr?: boolean + static?: ServeStaticOptions +} diff --git a/packages/config/types/router.d.ts b/packages/config/types/router.d.ts new file mode 100644 index 0000000000..e7f2e65d6f --- /dev/null +++ b/packages/config/types/router.d.ts @@ -0,0 +1,16 @@ + +/** + * NuxtConfigurationRouter + * Documentation: https://nuxtjs.org/api/configuration-router + * https://router.vuejs.org/api/#router-construction-options + */ + +import { RouterOptions, Route } from 'vue-router' + +export interface NuxtConfigurationRouter extends RouterOptions { + routeNameSplitter?: string + extendRoutes?: (routes: Route[], resolve: (...pathSegments: string[]) => string) => void + linkPrefetchedClass?: string + middleware?: string | string[] + prefetchLinks?: boolean +} diff --git a/packages/config/types/server-middleware.d.ts b/packages/config/types/server-middleware.d.ts new file mode 100644 index 0000000000..e4d0ac5f3f --- /dev/null +++ b/packages/config/types/server-middleware.d.ts @@ -0,0 +1,8 @@ +/** + * NuxtConfigurationServerMiddleware + * Documentation: https://nuxtjs.org/api/configuration-servermiddleware + */ + +import { RequestHandler } from 'express' + +export type NuxtConfigurationServerMiddleware = string | { path: string, handler: string | Function } | RequestHandler diff --git a/packages/config/types/server.d.ts b/packages/config/types/server.d.ts new file mode 100644 index 0000000000..c7057b4fec --- /dev/null +++ b/packages/config/types/server.d.ts @@ -0,0 +1,15 @@ +/** + * NuxtConfigurationServer + * Documentation: https://nuxtjs.org/api/configuration-server + */ + +export interface NuxtConfigurationServer { + host?: string + https?: { + cert?: string | Buffer + key?: string | Buffer + } + port?: number | string + socket?: string + timing?: boolean | { total?: boolean } +} diff --git a/packages/config/types/vue-configuration.d.ts b/packages/config/types/vue-configuration.d.ts new file mode 100644 index 0000000000..99a12a10d9 --- /dev/null +++ b/packages/config/types/vue-configuration.d.ts @@ -0,0 +1,9 @@ +/** + * NuxtConfigurationVueConfiguration + * Documentation: https://nuxtjs.org/api/configuration-vue-config + * https://vuejs.org/v2/api/#Global-Config + */ + +import { VueConstructor } from 'vue' + +export type NuxtConfigurationVueConfiguration = VueConstructor['config'] diff --git a/packages/config/types/watchers.d.ts b/packages/config/types/watchers.d.ts new file mode 100644 index 0000000000..999f1ac48f --- /dev/null +++ b/packages/config/types/watchers.d.ts @@ -0,0 +1,14 @@ +/** + * NuxtConfigurationWatchers + * Documentation: https://nuxtjs.org/api/configuration-watchers + * https://github.com/paulmillr/chokidar#api + * https://webpack.js.org/configuration/watch/#watchoptions + */ + +import { WatchOptions as ChokidarWatchOptions } from 'chokidar' +import { WatchOptions as WebpackWatchOptions } from 'webpack' + +export type NuxtConfigurationWatchers = { + chokidar?: ChokidarWatchOptions + webpack?: WebpackWatchOptions +} diff --git a/packages/typescript/package.json b/packages/typescript/package.json index 73d5582b04..63e2ffb475 100644 --- a/packages/typescript/package.json +++ b/packages/typescript/package.json @@ -9,7 +9,19 @@ ], "main": "dist/typescript.js", "dependencies": { + "@types/chokidar": "^1.7.5", + "@types/compression": "^0.0.36", + "@types/etag": "^1.8.0", + "@types/express": "^4.16.1", + "@types/html-minifier": "^3.5.3", "@types/node": "^11.10.4", + "@types/optimize-css-assets-webpack-plugin": "^1.3.4", + "@types/serve-static": "^1.13.2", + "@types/terser-webpack-plugin": "^1.2.1", + "@types/webpack": "^4.4.25", + "@types/webpack-bundle-analyzer": "^2.13.1", + "@types/webpack-dev-middleware": "^2.0.2", + "@types/webpack-hot-middleware": "^2.16.5", "chalk": "^2.4.2", "consola": "^2.5.6", "enquirer": "^2.3.0", diff --git a/packages/vue-app/types/index.d.ts b/packages/vue-app/types/index.d.ts index 046f28d745..a902e63d58 100644 --- a/packages/vue-app/types/index.d.ts +++ b/packages/vue-app/types/index.d.ts @@ -1,77 +1,78 @@ -import Vue from "vue"; -import VueRouter, { Route } from "vue-router"; -import { Store } from "vuex"; +import Vue from 'vue' +import VueRouter, { Route } from 'vue-router' +import { Store } from 'vuex' // augment typings of NodeJS.Process -import "./process"; +import './process' // augment typings of Vue.js -import "./vue"; +import './vue' -type Dictionary = { [key: string]: T }; +type Dictionary = { [key: string]: T } -type NuxtState = Dictionary; +type NuxtState = Dictionary export interface Context { - app: Vue; - isClient: boolean; - isServer: boolean; - isStatic: boolean; - isDev: boolean; - isHMR: boolean; - route: Route; - store: Store; - env: Dictionary; - params: Route['params']; - query: Route['query']; - req: Request; - res: Response; - redirect(status: number, path: string, query?: Route['query']): void; - redirect(path: string, query?: Route['query']): void; - error(params: ErrorParams): void; - nuxtState: NuxtState; - beforeNuxtRender(fn: (params: { Components: VueRouter['getMatchedComponents'], nuxtState: NuxtState }) => void): void + app: Vue + isClient: boolean + isServer: boolean + isStatic: boolean + isDev: boolean + isHMR: boolean + route: Route + store: Store + env: Dictionary + params: Route['params'] + payload: any + query: Route['query'] + req: Request + res: Response + redirect (status: number, path: string, query?: Route['query']): void + redirect (path: string, query?: Route['query']): void + error (params: ErrorParams): void + nuxtState: NuxtState + beforeNuxtRender (fn: (params: { Components: VueRouter['getMatchedComponents'], nuxtState: NuxtState }) => void): void } export type Middleware = string | ((ctx: Context, cb: Function) => Promise | void) export interface Transition { - name?: string; - mode?: string; - css?: boolean; - duration?: number; - type?: string; - enterClass?: string; - enterToClass?: string; - enterActiveClass?: string; - leaveClass?: string; - leaveToClass?: string; - leaveActiveClass?: string; - beforeEnter?(el: HTMLElement): void; - enter?(el: HTMLElement, done: Function): void; - afterEnter?(el: HTMLElement): void; - enterCancelled?(el: HTMLElement): void; - beforeLeave?(el: HTMLElement): void; - leave?(el: HTMLElement, done: Function): void; - afterLeave?(el: HTMLElement): void; - leaveCancelled?(el: HTMLElement): void; + name?: string + mode?: string + css?: boolean + duration?: number + type?: string + enterClass?: string + enterToClass?: string + enterActiveClass?: string + leaveClass?: string + leaveToClass?: string + leaveActiveClass?: string + beforeEnter?(el: HTMLElement): void + enter?(el: HTMLElement, done: Function): void + afterEnter?(el: HTMLElement): void + enterCancelled?(el: HTMLElement): void + beforeLeave?(el: HTMLElement): void + leave?(el: HTMLElement, done: Function): void + afterLeave?(el: HTMLElement): void + leaveCancelled?(el: HTMLElement): void } export interface ErrorParams { - statusCode?: number; - message?: string; + statusCode?: number + message?: string } export interface NuxtLoading extends Vue { - fail?(): NuxtLoading; - finish(): NuxtLoading; - increase?(num: number): NuxtLoading; - pause?(): NuxtLoading; - start(): NuxtLoading; + fail?(): NuxtLoading + finish(): NuxtLoading + increase?(num: number): NuxtLoading + pause?(): NuxtLoading + start(): NuxtLoading } export interface NuxtApp extends Vue { - $loading: NuxtLoading; - isOffline: boolean; - isOnline: boolean; + $loading: NuxtLoading + isOffline: boolean + isOnline: boolean } diff --git a/packages/vue-app/types/process.d.ts b/packages/vue-app/types/process.d.ts index 385924b0a2..abb0696f1a 100644 --- a/packages/vue-app/types/process.d.ts +++ b/packages/vue-app/types/process.d.ts @@ -4,11 +4,11 @@ declare namespace NodeJS { interface Process { - browser: boolean; - client: boolean; - mode: 'universal' | 'spa'; - modern: boolean; - server: boolean; - static: boolean; + browser: boolean + client: boolean + mode: 'spa' | 'universal' + modern: boolean + server: boolean + static: boolean } } diff --git a/packages/vue-app/types/vue.d.ts b/packages/vue-app/types/vue.d.ts index 222dd9521c..5bf203dda9 100644 --- a/packages/vue-app/types/vue.d.ts +++ b/packages/vue-app/types/vue.d.ts @@ -2,29 +2,29 @@ * Extends interfaces in Vue.js */ -import Vue, { ComponentOptions } from "vue"; -import { Route } from "vue-router"; -import { MetaInfo } from "vue-meta"; -import { Context, Middleware, Transition, NuxtApp } from "./index"; +import Vue, { ComponentOptions } from 'vue' +import { Route } from 'vue-router' +import { MetaInfo } from 'vue-meta' +import { Context, Middleware, Transition, NuxtApp } from './index' -declare module "vue/types/options" { +declare module 'vue/types/options' { interface ComponentOptions { - asyncData?(ctx: Context): object | undefined; - fetch?(ctx: Context): Promise | void; - head?: MetaInfo | (() => MetaInfo); - key?: string | ((to: Route) => string); - layout?: string | ((ctx: Context) => string); - loading?: boolean; - middleware?: Middleware | Middleware[]; - scrollToTop?: boolean; - transition?: string | Transition | ((to: Route, from: Route) => string); - validate?(ctx: Context): Promise | boolean; - watchQuery?: boolean | string[]; + asyncData?(ctx: Context): object | undefined + fetch?(ctx: Context): Promise | void + head?: MetaInfo | (() => MetaInfo) + key?: string | ((to: Route) => string) + layout?: string | ((ctx: Context) => string) + loading?: boolean + middleware?: Middleware | Middleware[] + scrollToTop?: boolean + transition?: string | Transition | ((to: Route, from: Route) => string) + validate?(ctx: Context): Promise | boolean + watchQuery?: boolean | string[] } } -declare module "vue/types/vue" { +declare module 'vue/types/vue' { interface Vue { - $nuxt: NuxtApp; + $nuxt: NuxtApp } } diff --git a/test/fixtures/typescript/nuxt.config.ts b/test/fixtures/typescript/nuxt.config.ts index ab6b0bc663..26dc21fd3b 100644 --- a/test/fixtures/typescript/nuxt.config.ts +++ b/test/fixtures/typescript/nuxt.config.ts @@ -1,4 +1,6 @@ -const config: any = { +import NuxtConfiguration from '@nuxt/config' + +const config: NuxtConfiguration = { modules: [ '~/modules/module' ], diff --git a/test/types/tsconfig.json b/test/types/tsconfig.json index f842055462..385c8552e3 100644 --- a/test/types/tsconfig.json +++ b/test/types/tsconfig.json @@ -1,15 +1,13 @@ { "compilerOptions": { - "target": "es5", - "module": "es2015", + "target": "esnext", "moduleResolution": "node", "strict": true, "noEmit": true, "lib": [ - "es5", - "dom", - "es2015.promise", - "es2015.core" + "esnext", + "esnext.asynciterable", + "dom" ] } } diff --git a/yarn.lock b/yarn.lock index 74dc2b6481..31dfd84cf3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1398,6 +1398,11 @@ universal-user-agent "^2.0.0" url-template "^2.0.8" +"@types/anymatch@*": + version "1.3.1" + resolved "https://registry.npmjs.org/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a" + integrity sha512-/+CRPXpBDpo2RK9C68N3b2cOvO0Cf5B9aPijHsoDQTHivnGSObdOF2BRQOYjojWTDy6nQvMjmqRXIxH55VjxxA== + "@types/babel-types@*", "@types/babel-types@^7.0.0": version "7.0.6" resolved "https://registry.npmjs.org/@types/babel-types/-/babel-types-7.0.6.tgz#a7cfaaeee96e90c4c54da0e580aaff3f4cffacac" @@ -1410,21 +1415,194 @@ dependencies: "@types/babel-types" "*" +"@types/body-parser@*": + version "1.17.0" + resolved "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.17.0.tgz#9f5c9d9bd04bb54be32d5eb9fc0d8c974e6cf58c" + integrity sha512-a2+YeUjPkztKJu5aIF2yArYFQQp8d51wZ7DavSHjFuY1mqVgidGyzEQ41JIVNy82fXj8yPgy2vJmfIywgESW6w== + dependencies: + "@types/connect" "*" + "@types/node" "*" + +"@types/chokidar@^1.7.5": + version "1.7.5" + resolved "https://registry.npmjs.org/@types/chokidar/-/chokidar-1.7.5.tgz#1fa78c8803e035bed6d98e6949e514b133b0c9b6" + integrity sha512-PDkSRY7KltW3M60hSBlerxI8SFPXsO3AL/aRVsO4Kh9IHRW74Ih75gUuTd/aE4LSSFqypb10UIX3QzOJwBQMGQ== + dependencies: + "@types/events" "*" + "@types/node" "*" + +"@types/clean-css@*": + version "4.2.0" + resolved "https://registry.npmjs.org/@types/clean-css/-/clean-css-4.2.0.tgz#785749d3ba799ae2cd3efcb3ce622781efd00340" + integrity sha512-P+gDCIBAXZ/Q5e9d/Z9Rtn16P5Pr1YIO3gZcY7ZvaQ9ErgmOYtFQlLHZ2P/xcrIyN8TEZrI03EZmdmv1154sjA== + dependencies: + "@types/node" "*" + +"@types/compression@^0.0.36": + version "0.0.36" + resolved "https://registry.npmjs.org/@types/compression/-/compression-0.0.36.tgz#7646602ffbfc43ea48a8bf0b2f1d5e5f9d75c0d0" + integrity sha512-B66iZCIcD2eB2F8e8YDIVtCUKgfiseOR5YOIbmMN2tM57Wu55j1xSdxdSw78aVzsPmbZ6G+hINc+1xe1tt4NBg== + dependencies: + "@types/express" "*" + +"@types/connect@*": + version "3.4.32" + resolved "https://registry.npmjs.org/@types/connect/-/connect-3.4.32.tgz#aa0e9616b9435ccad02bc52b5b454ffc2c70ba28" + integrity sha512-4r8qa0quOvh7lGD0pre62CAb1oni1OO6ecJLGCezTmhQ8Fz50Arx9RUszryR8KlgK6avuSXvviL6yWyViQABOg== + dependencies: + "@types/node" "*" + "@types/estree@0.0.39": version "0.0.39" resolved "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== +"@types/etag@^1.8.0": + version "1.8.0" + resolved "https://registry.npmjs.org/@types/etag/-/etag-1.8.0.tgz#37f0b1f3ea46da7ae319bbedb607e375b4c99f7e" + integrity sha512-EdSN0x+Y0/lBv7YAb8IU4Jgm6DWM+Bqtz7o5qozl96fzaqdqbdfHS5qjdpFeIv7xQ8jSLyjMMNShgYtMajEHyQ== + dependencies: + "@types/node" "*" + +"@types/events@*": + version "3.0.0" + resolved "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" + integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g== + +"@types/express-serve-static-core@*": + version "4.16.1" + resolved "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.16.1.tgz#35df7b302299a4ab138a643617bd44078e74d44e" + integrity sha512-QgbIMRU1EVRry5cIu1ORCQP4flSYqLM1lS5LYyGWfKnFT3E58f0gKto7BR13clBFVrVZ0G0rbLZ1hUpSkgQQOA== + dependencies: + "@types/node" "*" + "@types/range-parser" "*" + +"@types/express@*", "@types/express@^4.16.1": + version "4.16.1" + resolved "https://registry.npmjs.org/@types/express/-/express-4.16.1.tgz#d756bd1a85c34d87eaf44c888bad27ba8a4b7cf0" + integrity sha512-V0clmJow23WeyblmACoxbHBu2JKlE5TiIme6Lem14FnPW9gsttyHtk6wq7njcdIWH1njAaFgR8gW09lgY98gQg== + dependencies: + "@types/body-parser" "*" + "@types/express-serve-static-core" "*" + "@types/serve-static" "*" + +"@types/html-minifier@^3.5.3": + version "3.5.3" + resolved "https://registry.npmjs.org/@types/html-minifier/-/html-minifier-3.5.3.tgz#5276845138db2cebc54c789e0aaf87621a21e84f" + integrity sha512-j1P/4PcWVVCPEy5lofcHnQ6BtXz9tHGiFPWzqm7TtGuWZEfCHEP446HlkSNc9fQgNJaJZ6ewPtp2aaFla/Uerg== + dependencies: + "@types/clean-css" "*" + "@types/relateurl" "*" + "@types/uglify-js" "*" + +"@types/loglevel@*": + version "1.5.4" + resolved "https://registry.npmjs.org/@types/loglevel/-/loglevel-1.5.4.tgz#6e296bf20d9f6b0a3274cfb01a918f1d634e4c32" + integrity sha512-8dx4ckP0vndJeN+iKZwdGiapLqFjVQ3JLOt92uqK0C63acs5NcPLbUOpfXCJkKVRjZLBQjw8NIGNBSsnatFnFQ== + +"@types/memory-fs@*": + version "0.3.2" + resolved "https://registry.npmjs.org/@types/memory-fs/-/memory-fs-0.3.2.tgz#5d4753f9b390cb077c8c8af97bc96463399ceccd" + integrity sha512-j5AcZo7dbMxHoOimcHEIh0JZe5e1b8q8AqGSpZJrYc7xOgCIP79cIjTdx5jSDLtySnQDwkDTqwlC7Xw7uXw7qg== + dependencies: + "@types/node" "*" + +"@types/mime@*": + version "2.0.1" + resolved "https://registry.npmjs.org/@types/mime/-/mime-2.0.1.tgz#dc488842312a7f075149312905b5e3c0b054c79d" + integrity sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw== + "@types/node@*", "@types/node@^11.10.4", "@types/node@^11.9.5": version "11.10.4" resolved "https://registry.npmjs.org/@types/node/-/node-11.10.4.tgz#3f5fc4f0f322805f009e00ab35a2ff3d6b778e42" integrity sha512-wa09itaLE8L705aXd8F80jnFpxz3Y1/KRHfKsYL2bPc0XF+wEWu8sR9n5bmeu8Ba1N9z2GRNzm/YdHcghLkLKg== +"@types/optimize-css-assets-webpack-plugin@^1.3.4": + version "1.3.4" + resolved "https://registry.npmjs.org/@types/optimize-css-assets-webpack-plugin/-/optimize-css-assets-webpack-plugin-1.3.4.tgz#6838ab7a3a5ec1253ad98c348bdcd009e91b39cd" + integrity sha512-04LJJFAdZ7sW7V66htTeKz95WP/E+aTuKv3wikgM6bmmeO1alcqQ9eDoRSTrrkL/zeuoaoW4WR1FdjvqiWoSkQ== + dependencies: + "@types/webpack" "*" + "@types/q@^1.5.1": version "1.5.1" resolved "https://registry.npmjs.org/@types/q/-/q-1.5.1.tgz#48fd98c1561fe718b61733daed46ff115b496e18" integrity sha512-eqz8c/0kwNi/OEHQfvIuJVLTst3in0e7uTKeuY+WL/zfKn0xVujOTp42bS/vUUokhK5P2BppLd9JXMOMHcgbjA== +"@types/range-parser@*": + version "1.2.3" + resolved "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c" + integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA== + +"@types/relateurl@*": + version "0.2.28" + resolved "https://registry.npmjs.org/@types/relateurl/-/relateurl-0.2.28.tgz#6bda7db8653fa62643f5ee69e9f69c11a392e3a6" + integrity sha1-a9p9uGU/piZD9e5p6facEaOS46Y= + +"@types/serve-static@*", "@types/serve-static@^1.13.2": + version "1.13.2" + resolved "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.2.tgz#f5ac4d7a6420a99a6a45af4719f4dcd8cd907a48" + integrity sha512-/BZ4QRLpH/bNYgZgwhKEh+5AsboDBcUdlBYgzoLX0fpj3Y2gp6EApyOlM3bK53wQS/OE1SrdSYBAbux2D1528Q== + dependencies: + "@types/express-serve-static-core" "*" + "@types/mime" "*" + +"@types/tapable@*": + version "1.0.4" + resolved "https://registry.npmjs.org/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370" + integrity sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ== + +"@types/terser-webpack-plugin@^1.2.1": + version "1.2.1" + resolved "https://registry.npmjs.org/@types/terser-webpack-plugin/-/terser-webpack-plugin-1.2.1.tgz#02c2cacd7769c533cbdac28dd7610c24e46b5c95" + integrity sha512-5mzQulZabFsqiLh0PhJdccIKqpd5535UYpZ+Skugz8kPzZdajMMYBRKQSzM1KOkZ42NwLxbZSzQp6xKtaq46Gg== + dependencies: + "@types/webpack" "*" + terser "^3.16.1" + +"@types/uglify-js@*": + version "3.0.4" + resolved "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-3.0.4.tgz#96beae23df6f561862a830b4288a49e86baac082" + integrity sha512-SudIN9TRJ+v8g5pTG8RRCqfqTMNqgWCKKd3vtynhGzkIIjxaicNAMuY5TRadJ6tzDu3Dotf3ngaMILtmOdmWEQ== + dependencies: + source-map "^0.6.1" + +"@types/webpack-bundle-analyzer@^2.13.1": + version "2.13.1" + resolved "https://registry.npmjs.org/@types/webpack-bundle-analyzer/-/webpack-bundle-analyzer-2.13.1.tgz#25154f36585c0abc90f7e58fd3197c83fced789a" + integrity sha512-9M9jingj0izx1VfglYYJ+dvd0YCMlFgtrSCeb+C3VIQP8hmTXGJ5qqVeqiBnv0ffMyeKWqyij4K2F4VBcazQNw== + dependencies: + "@types/webpack" "*" + +"@types/webpack-dev-middleware@^2.0.2": + version "2.0.2" + resolved "https://registry.npmjs.org/@types/webpack-dev-middleware/-/webpack-dev-middleware-2.0.2.tgz#33934f15de582f1a6c21ea21c42f69282e328c76" + integrity sha512-uZ1avIbAcnspcDKKm0WfgIdvBYRqUapPmwb0MYGzzB74q2F3T4Xi+qPSoS0Oq5iQvIMVxOm7KMqHQJii4VDCsw== + dependencies: + "@types/connect" "*" + "@types/loglevel" "*" + "@types/memory-fs" "*" + "@types/webpack" "*" + +"@types/webpack-hot-middleware@^2.16.5": + version "2.16.5" + resolved "https://registry.npmjs.org/@types/webpack-hot-middleware/-/webpack-hot-middleware-2.16.5.tgz#5271eada42f34670a7ae79ddb6f1c419a19c985f" + integrity sha512-41qSQeyRGZkWSi366jMQVsLo5fdLT8EgmvHNoBwcCtwZcHrQk6An6tD+ZfC0zMdNHzVEFlzQvT2mTte8zDxqNw== + dependencies: + "@types/connect" "*" + "@types/webpack" "*" + +"@types/webpack@*", "@types/webpack@^4.4.25": + version "4.4.25" + resolved "https://registry.npmjs.org/@types/webpack/-/webpack-4.4.25.tgz#c8a1eb968a33a3e6da641f529c5add0d44d34809" + integrity sha512-YaYVbSK1bC3xiAWFLSgDQyVHdCTNq5cLlcx633basmrwSoUxJiv4SZ0SoT1uoF15zWx98afOcCbqA1YHeCdRYA== + dependencies: + "@types/anymatch" "*" + "@types/node" "*" + "@types/tapable" "*" + "@types/uglify-js" "*" + source-map "^0.6.0" + "@vue/babel-helper-vue-jsx-merge-props@^1.0.0-beta.2": version "1.0.0-beta.2" resolved "https://registry.npmjs.org/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.0.0-beta.2.tgz#f3e20d77b89ddb7a4b9b7a75372f05cd3ac22d92"