diff --git a/packages/kit/src/components.ts b/packages/kit/src/components.ts index 49bc6d91e2..1257a6a68d 100644 --- a/packages/kit/src/components.ts +++ b/packages/kit/src/components.ts @@ -55,7 +55,7 @@ export async function addComponent (opts: AddComponentOptions) { nuxt.hook('components:extend', (components: Component[]) => { const existingComponentIndex = components.findIndex(c => (c.pascalName === component.pascalName || c.kebabName === component.kebabName) && c.mode === component.mode) if (existingComponentIndex !== -1) { - const existingComponent = components[existingComponentIndex] + const existingComponent = components[existingComponentIndex]! const existingPriority = existingComponent.priority ?? 0 const newPriority = component.priority ?? 0 diff --git a/packages/kit/src/ignore.ts b/packages/kit/src/ignore.ts index 9dcdc32cf2..dc18508a06 100644 --- a/packages/kit/src/ignore.ts +++ b/packages/kit/src/ignore.ts @@ -50,7 +50,7 @@ export function resolveIgnorePatterns (relativePath?: string): string[] { // Map ignore patterns based on if they start with * or !* return ignorePatterns.map((p) => { const [_, negation = '', pattern] = p.match(NEGATION_RE) || [] - if (pattern[0] === '*') { + if (pattern && pattern[0] === '*') { return p } return negation + relative(relativePath, resolve(nuxt.options.rootDir, pattern || p)) @@ -73,7 +73,7 @@ export function resolveGroupSyntax (group: string): string[] { groups = groups.flatMap((group) => { const [head, ...tail] = group.split('{') if (tail.length) { - const [body, ...rest] = tail.join('{').split('}') + const [body = '', ...rest] = tail.join('{').split('}') return body.split(',').map(part => `${head}${part}${rest.join('')}`) } diff --git a/packages/kit/src/layout.ts b/packages/kit/src/layout.ts index bf86c443c9..c159cd4a63 100644 --- a/packages/kit/src/layout.ts +++ b/packages/kit/src/layout.ts @@ -29,7 +29,7 @@ export function addLayout (this: any, template: NuxtTemplate | string, name?: st // Nuxt 3 adds layouts on app nuxt.hook('app:templates', (app) => { if (layoutName in app.layouts) { - const relativePath = relative(nuxt.options.srcDir, app.layouts[layoutName].file) + const relativePath = relative(nuxt.options.srcDir, app.layouts[layoutName]!.file) return logger.warn( `Not overriding \`${layoutName}\` (provided by \`~/${relativePath}\`) with \`${src || filename}\`.`, ) diff --git a/packages/kit/src/pages.ts b/packages/kit/src/pages.ts index 04c7592a55..f3c9aa6b9c 100644 --- a/packages/kit/src/pages.ts +++ b/packages/kit/src/pages.ts @@ -51,7 +51,7 @@ export function addRouteMiddleware (input: NuxtMiddleware | NuxtMiddleware[], op for (const middleware of middlewares) { const find = app.middleware.findIndex(item => item.name === middleware.name) if (find >= 0) { - const foundPath = app.middleware[find].path + const foundPath = app.middleware[find]!.path if (foundPath === middleware.path) { continue } if (options.override === true) { app.middleware[find] = { ...middleware } diff --git a/packages/kit/src/resolve.ts b/packages/kit/src/resolve.ts index b170210efe..31ae08d2ed 100644 --- a/packages/kit/src/resolve.ts +++ b/packages/kit/src/resolve.ts @@ -174,7 +174,7 @@ export async function resolveNuxtModule (base: string, paths: string[]): Promise for (const path of paths) { if (path.startsWith(base)) { - resolved.push(path.split('/index.ts')[0]) + resolved.push(path.split('/index.ts')[0]!) } else { const resolvedPath = await resolver.resolvePath(path) resolved.push(resolvedPath.slice(0, resolvedPath.lastIndexOf(path) + path.length)) diff --git a/packages/kit/src/template.ts b/packages/kit/src/template.ts index 8e729c2f20..77dc044f9b 100644 --- a/packages/kit/src/template.ts +++ b/packages/kit/src/template.ts @@ -228,10 +228,10 @@ export async function _generateTypes (nuxt: Nuxt) { if (excludedAlias.some(re => re.test(alias))) { continue } - let absolutePath = resolve(basePath, aliases[alias]) + let absolutePath = resolve(basePath, aliases[alias]!) let stats = await fsp.stat(absolutePath).catch(() => null /* file does not exist */) if (!stats) { - const resolvedModule = await tryResolveModule(aliases[alias], nuxt.options.modulesDir) + const resolvedModule = await tryResolveModule(aliases[alias]!, nuxt.options.modulesDir) if (resolvedModule) { absolutePath = resolvedModule stats = await fsp.stat(resolvedModule).catch(() => null) @@ -251,7 +251,7 @@ export async function _generateTypes (nuxt: Nuxt) { // remove extension ? relativePath.replace(/\b\.\w+$/g, '') // non-existent file probably shouldn't be resolved - : aliases[alias] + : aliases[alias]! tsConfig.compilerOptions.paths[alias] = [path] @@ -334,7 +334,7 @@ function renderAttrs (obj: Record) { return attrs.join(' ') } -function renderAttr (key: string, value: string) { +function renderAttr (key: string, value?: string) { return value ? `${key}="${value}"` : '' } diff --git a/packages/ui-templates/lib/render.ts b/packages/ui-templates/lib/render.ts index c9d5986c4f..d81ffe873c 100644 --- a/packages/ui-templates/lib/render.ts +++ b/packages/ui-templates/lib/render.ts @@ -136,9 +136,14 @@ export const RenderPlugin = () => { } return lastChar || '' }).replace(/@media[^{]*\{\}/g, '') - const inlineScripts = Array.from(html.matchAll(/