fix(nuxt): disallow write: false for type templates (#22972)

This commit is contained in:
Andrey Yolkin 2023-09-04 14:23:03 +03:00 committed by GitHub
parent 7431e22588
commit 3e676a7fd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -1,7 +1,7 @@
import { existsSync, promises as fsp } from 'node:fs' import { existsSync, promises as fsp } from 'node:fs'
import { basename, isAbsolute, join, parse, relative, resolve } from 'pathe' import { basename, isAbsolute, join, parse, relative, resolve } from 'pathe'
import hash from 'hash-sum' import hash from 'hash-sum'
import type { Nuxt, NuxtTemplate, ResolvedNuxtTemplate, TSReference } from '@nuxt/schema' import type { Nuxt, NuxtTemplate, NuxtTypeTemplate, ResolvedNuxtTemplate, TSReference } from '@nuxt/schema'
import { withTrailingSlash } from 'ufo' import { withTrailingSlash } from 'ufo'
import { defu } from 'defu' import { defu } from 'defu'
import type { TSConfig } from 'pkg-types' import type { TSConfig } from 'pkg-types'
@ -34,7 +34,7 @@ export function addTemplate (_template: NuxtTemplate<any> | string) {
* Renders given types using lodash template during build into the project buildDir * Renders given types using lodash template during build into the project buildDir
* and register them as types. * and register them as types.
*/ */
export function addTypeTemplate (_template: NuxtTemplate<any>) { export function addTypeTemplate (_template: NuxtTypeTemplate<any>) {
const nuxt = useNuxt() const nuxt = useNuxt()
const template = addTemplate(_template) const template = addTemplate(_template)

View File

@ -18,7 +18,11 @@ export interface NuxtPlugin {
order?: number order?: number
} }
export interface NuxtTemplate<Options = Record<string, any>> { // Internal type for simpler NuxtTemplate interface extension
type TemplateDefaultOptions = Record<string, any>
export interface NuxtTemplate<Options = TemplateDefaultOptions> {
/** resolved output file path (generated) */ /** resolved output file path (generated) */
dst?: string dst?: string
/** The target filename once the template is copied into the Nuxt buildDir */ /** The target filename once the template is copied into the Nuxt buildDir */
@ -33,13 +37,17 @@ export interface NuxtTemplate<Options = Record<string, any>> {
write?: boolean write?: boolean
} }
export interface ResolvedNuxtTemplate<Options = Record<string, any>> extends NuxtTemplate<Options> { export interface ResolvedNuxtTemplate<Options = TemplateDefaultOptions> extends NuxtTemplate<Options> {
filename: string filename: string
dst: string dst: string
} }
export interface NuxtTypeTemplate<Options = TemplateDefaultOptions> extends Omit<NuxtTemplate<Options>, 'write'> {
write?: true
}
type _TemplatePlugin<Options> = Omit<NuxtPlugin, 'src'> & NuxtTemplate<Options> type _TemplatePlugin<Options> = Omit<NuxtPlugin, 'src'> & NuxtTemplate<Options>
export interface NuxtPluginTemplate<Options = Record<string, any>> extends _TemplatePlugin<Options> { } export interface NuxtPluginTemplate<Options = TemplateDefaultOptions> extends _TemplatePlugin<Options> { }
export interface NuxtApp { export interface NuxtApp {
mainComponent?: string | null mainComponent?: string | null