Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const userSources = computed(() => (data.value?.globalSources || []).filter(s =>
<h3 class="opacity-80 text-base mb-1">
{{ sitemap.sitemapName }}
<NIcon
v-if="(sitemap.sources || []).some(s => !!s.error)"
v-if="(sitemap.sources || []).some(s => !!(s as any).error)"
icon="carbon:warning"
class="text-red-500"
/>
Expand Down
2 changes: 1 addition & 1 deletion client/composables/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { onDevtoolsClientConnected } from '@nuxt/devtools-kit/iframe-client'
import type { $Fetch } from 'nitropack'
import type { $Fetch } from 'ofetch'
import { ref, watchEffect } from 'vue'
import type { NuxtDevtoolsClient } from '@nuxt/devtools-kit/types'
import { refreshSources } from './state'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"test": "vitest run && pnpm run test:attw",
"test:unit": "vitest --project=unit",
"test:attw": "attw --pack",
"typecheck": "vue-tsc --noEmit"
"typecheck": "nuxt typecheck"
},
"dependencies": {
"@nuxt/devtools-kit": "^3.1.1",
Expand Down Expand Up @@ -93,6 +93,7 @@
}
},
"devDependencies": {
"vue-i18n-routing": "^1.2.0",
"@arethetypeswrong/cli": "^0.18.2",
"@nuxt/content": "^3.9.0",
"@nuxt/eslint-config": "^1.11.0",
Expand Down
3 changes: 3 additions & 0 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nuxt/tsconfig.app.json"
}
83 changes: 83 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export function setupDevToolsUI(options: ModuleOptions, resolve: Resolver['resol
// In local development, start a separate Nuxt Server and proxy to serve the client
else {
nuxt.hook('vite:extendConfig', (config) => {
config.server = config.server || {}
config.server.proxy = config.server.proxy || {}
// @ts-expect-error vite config server is readonly but we need to mutate it
if (!config.server) config.server = {}
if (!config.server.proxy) config.server.proxy = {}
config.server.proxy[DEVTOOLS_UI_ROUTE] = {
target: `http://localhost:${DEVTOOLS_UI_LOCAL_PORT}${DEVTOOLS_UI_ROUTE}`,
changeOrigin: true,
Expand Down
8 changes: 6 additions & 2 deletions src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ async function prerenderRoute(nitro: Nitro, route: string) {
const _route: PrerenderRoute = { route, fileName: route }
// Fetch the route
const encodedRoute = encodeURI(route)
const fetchUrl = withBase(encodedRoute, nitro.options.baseURL)
const res = await globalThis.$fetch.raw(
withBase(encodedRoute, nitro.options.baseURL),
fetchUrl,
{
headers: { 'x-nitro-prerender': encodedRoute },
retry: nitro.options.prerender.retry,
Expand All @@ -171,10 +172,13 @@ async function prerenderRoute(nitro: Nitro, route: string) {
const filePath = join(nitro.options.output.publicDir, _route.fileName!)
await mkdir(dirname(filePath), { recursive: true })
const data = res._data
if (data === undefined) {
throw new Error(`No data returned from '${fetchUrl}'`)
}
if (filePath.endsWith('json') || typeof data === 'object')
await writeFile(filePath, JSON.stringify(data), 'utf8')
else
await writeFile(filePath, data, 'utf8')
await writeFile(filePath, data as string, 'utf8')
_route.generateTimeMS = Date.now() - start
nitro._prerenderedRoutes!.push(_route)
nitro.logger.log(formatPrerenderRoute(_route))
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/server/plugins/nuxt-content-v2.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck this is for v2, consider it was stable and the types will not match when running type tests
import { defu } from 'defu'
import type { ParsedContentv2 } from '@nuxt/content'
import type { NitroApp } from 'nitropack/types'
Expand Down
6 changes: 4 additions & 2 deletions src/runtime/server/routes/__sitemap__/debug.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defineEventHandler } from 'h3'
import type { SitemapDefinition } from '../../../types'
import { useSitemapRuntimeConfig } from '../../utils'
import {
childSitemapSources,
Expand All @@ -17,8 +16,11 @@ export default defineEventHandler(async (e) => {
delete runtimeConfig.sitemaps
const globalSources = await globalSitemapSources()
const nitroOrigin = getNitroOrigin(e)
const sitemaps: Record<string, SitemapDefinition> = {}
const sitemaps: Record<string, typeof _sitemaps[number] & { sources: Awaited<ReturnType<typeof resolveSitemapSources>> }> = {}
for (const s of Object.keys(_sitemaps)) {
if (!_sitemaps[s]) {
throw new Error('Could not resolve matching key in _sitemaps')
}
// resolve the sources
sitemaps[s] = {
..._sitemaps[s],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineEventHandler } from 'h3'
// @ts-expect-error for nuxt v2 - type checking for nuxt v3
import type { ParsedContent } from '@nuxt/content'

// @ts-expect-error alias module
Expand Down
8 changes: 5 additions & 3 deletions src/runtime/server/routes/__sitemap__/nuxt-content-urls-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { defineEventHandler } from 'h3'
import { queryCollection } from '@nuxt/content/server'
// @ts-expect-error alias
import manifest from '#content/manifest'
import type { Collections } from '@nuxt/content'

export default defineEventHandler(async (e) => {
const collections = []
const collections: (keyof Collections)[] = []
// each collection in the manifest has a key => with fields which has a `sitemap`, we want to get all those
for (const collection in manifest) {
if (manifest[collection].fields.sitemap) {
collections.push(collection)
if (manifest[collection]?.fields?.sitemap) {
collections.push(collection as keyof Collections)
}
}
// now we need to handle multiple queries here, we want to run the requests in parralel
Expand All @@ -31,6 +32,7 @@ export default defineEventHandler(async (e) => {
.filter(c => c.sitemap !== false && c.path)
.flatMap(c => ({
loc: c.path,
// @ts-expect-error cannot figure out how to make sure this is resolvable when no Collections are in manifest
...(c.sitemap || {}),
}))
})
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/server/routes/sitemap.xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ export default defineEventHandler(async (e) => {
return sendRedirect(e, withBase('/sitemap_index.xml', useRuntimeConfig().app.baseURL), import.meta.dev ? 302 : 301)
}

return createSitemap(e, Object.values(sitemaps)[0], runtimeConfig)
const sitemap = Object.values(sitemaps)
// if we had an index, we would have returned above. as we do not
// this is compatible with SitemapDefinition expected
const sm = sitemap[0] as typeof sitemaps['any_key_except_index']
return createSitemap(e, sm, runtimeConfig)
})
2 changes: 1 addition & 1 deletion src/runtime/server/routes/sitemap/[sitemap].xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default defineEventHandler(async (e) => {
}

// Get the appropriate sitemap configuration
const sitemapConfig = getSitemapConfig(sitemapName, sitemaps, runtimeConfig.defaultSitemapsChunkSize)
const sitemapConfig = getSitemapConfig(sitemapName, sitemaps, runtimeConfig.defaultSitemapsChunkSize || 1000)

return createSitemap(e, sitemapConfig, runtimeConfig)
})
Loading